Custom task start method throws an ArgumentException

Due to the fact that CultureInfo is not copied from stream to stream, I made the following method to do this for me.

public static StartCustomTask(Action action, TaskCreationOptions tco = TaskCreationOptions.None)
{
    var currentCult = Thread.CurrentThread.CurrentCuture;
    var currentUiCult = Thread.CurrentThread.CurrentUICulture;

    return Task.Factory.StartNew(() =>
    {
        Thread.CurrentThread.CurrentCuture = currentCult;
        Thread.CurrentThread.CurrentUICulture = currentUiCult;
        action();
    }, tco);
}

basically this code copies culture information from the current thread to the thread that it should execute action. I don’t know why, but he quits System.ArgumentExceptionspeaking Value does not fall within the expected range. I tried to run the action on the main thread regularly and it works fine. By this, I mean that this method, which is an action, has no problem, a problem arises somewhere in the above code.

Here is the exception stack trace

at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
   at System.Web.Hosting.IIS7WorkerRequest.GetServerVariableInternal(String name)
   at System.Web.HttpRequest.BuildUrl(Func`1 pathAccessor)
   at System.Web.HttpRequest.get_Url()
   at SL.CoreLogic.Web.FrontEnd.Controllers.AccountController.<>c__DisplayClass37.<ResetPassword>b__31() in d:\CoreProjects\CoreLogic\CoreLogic-RusSlot\SL.CoreLogic\SL.CoreLogic.Web.FrontEnd\Controllers\AccountController.cs:line 447
   at SL.CoreLogic.Common.CustomTask.<>c__DisplayClass1.<StartWithCurrentCulture>b__0() in d:\CoreProjects\CoreLogic\CoreLogic-RusSlot\SL.CoreLogic\SL.CoreLogic.Common\CustomTask.cs:line 22
   at System.Threading.Tasks.Task.

one more thing. this code worked fine, but suddenly he started to do it.

+2
source share
1 answer

. , , Url = Request.Url, , .

+1

All Articles