Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net System.ExecutionEngineeException:尝试JIT编译方法System.Threading.Interlocated:Exchange_.net_Mono_Xamarin.ios - Fatal编程技术网

.net System.ExecutionEngineeException:尝试JIT编译方法System.Threading.Interlocated:Exchange

.net System.ExecutionEngineeException:尝试JIT编译方法System.Threading.Interlocated:Exchange,.net,mono,xamarin.ios,.net,Mono,Xamarin.ios,我知道,如果编译器认为没有任何东西使用方法,那么它有时可能会忽略这些方法,您可以通过在代码中直接引用该方法来解决这一问题,从而强制编译器包含它。然而,在这种情况下,它似乎不起作用 以下是异常和调用堆栈: System.ExecutionEngineException: Attempting to JIT compile method '(wrapper managed-to-native) System.Threading.Interlocked:Exchange (System.Threadi

我知道,如果编译器认为没有任何东西使用方法,那么它有时可能会忽略这些方法,您可以通过在代码中直接引用该方法来解决这一问题,从而强制编译器包含它。然而,在这种情况下,它似乎不起作用

以下是异常和调用堆栈:

System.ExecutionEngineException: Attempting to JIT compile method '(wrapper managed-to-native) System.Threading.Interlocked:Exchange (System.Threading.Tasks.IContinuation&,System.Threading.Tasks.IContinuation)' while running with --aot-only. See http://docs.xamarin.com/ios/about/limitations for more information.

at System.Threading.Tasks.TaskCompletionQueue`1[System.Threading.Tasks.IContinuation].TryGetNextCompletion (IContinuation& continuation) [0x00000] in <filename unknown>:0
at System.Threading.Tasks.Task.ProcessCompleteDelegates () [0x0001b] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Threading.Tasks/Task.cs:521
at System.Threading.Tasks.Task.HandleGenericException (System.AggregateException e) [0x0001a] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Threading.Tasks/Task.cs:563
at System.Threading.Tasks.Task.TrySetException (System.AggregateException aggregate) [0x0003e] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Threading.Tasks/Task.cs:440
at System.Threading.Tasks.TaskCompletionSource`1[System.Net.WebResponse].TrySetException (IEnumerable`1 exceptions) [0x00000] in <filename unknown>:0
at System.Threading.Tasks.TaskCompletionSource`1[System.Net.WebResponse].SetException (IEnumerable`1 exceptions) [0x00000] in <filename unknown>:0
at System.Threading.Tasks.TaskCompletionSource`1[System.Net.WebResponse].SetException (System.Exception exception) [0x00000] in <filename unknown>:0
at System.Threading.Tasks.TaskFactory`1[System.Net.WebResponse].InnerInvoke (System.Threading.Tasks.TaskCompletionSource`1 tcs, System.Func`2 endMethod, IAsyncResult l) [0x00000] in <filename unknown>:0
at System.Threading.Tasks.TaskFactory`1+<FromAsyncBeginEnd>c__AnonStorey21[System.Net.WebResponse].<>m__15 (IAsyncResult l) [0x00000] in <filename unknown>:0
at Vistian.Net.Http.HttpRequestProcessor+<BeginGetResponse>c__AnonStorey3.<>m__5 (IAsyncResult result) [0x00082] in /Users/martinstafford/Projects/Vistian/vistian/common/Vistian.Net/trunk/Vistian.Net.Portable/Http/HttpRequestProcessor.cs:441
at System.Net.WebAsyncResult.CB (System.Object unused) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/System/System.Net/WebAsyncResult.cs:148
下面是关于错误的代码。对不起,有这么多,但它是在上下文中理解的。调用“callback”(回调)时引发异常—任何回调。如您所见,我正在尝试为一个包含GetRequestStream和GetResponse两个异步操作的类实现异步编程模型:

                    public static IAsyncResult BeginGetResponse(AsyncCallback callback, object state)
    {
        var requestProcessor = state as HttpRequestProcessor;

        // create the Uri of the Host and Path in the request
        // and use it to create a HttpWebRequest
        Uri u = new Uri(new Uri(requestProcessor.Request.Host), requestProcessor.Request.Path);
        requestProcessor.HttpWebRequest = WebRequest.Create(u) as HttpWebRequest;

        // set up the header of the HttpWebRequest
        requestProcessor.SetupHeader(requestProcessor.HttpWebRequest, requestProcessor.Request);

        requestProcessor.WebResponse = null;
        requestProcessor.RaisedException = null;

        // set up an event to be used to 'timeout' the forthcoming async process
        var syncRef = new System.Threading.AutoResetEvent(false);

        System.Diagnostics.Debug.WriteLine(string.Format("HttpRequestProcessor.BeginGetResponse: started method={0}", requestProcessor.Request.Method));

        // perform the request using the Async method
        // GET and POST requests are processed differently
        if (requestProcessor.Request.Method == HttpMethod.POST)
        {
            // create the request content using the serialiser
            var bytes = requestProcessor.Encoder.Encode(requestProcessor.Request.Data, requestProcessor.Request.ContentType);

            System.Diagnostics.Debug.WriteLine("HttpRequestProcessor.BeginGetResponse: BeginGetRequestStream started");

            // start the async process by adding the content to the request
            requestProcessor.HttpWebRequest.BeginGetRequestStream((IAsyncResult result) =>
            {
                // the asyncronous Get RequestStream has finished in some way
                // complete the Get RequestStream process by calling EndGetRequestStream

                // get the HttpWebRequest provided in the 'state' parameter and
                // use it to call EndGetRequestStream
                var request = result.AsyncState as HttpWebRequest;
                try
                {
                    // fill the request stream with the content
                    using (Stream requestStream = request.EndGetRequestStream(result))
                    {
                        requestStream.Write(bytes, 0, bytes.Length);
                    }

                    System.Diagnostics.Debug.WriteLine("HttpRequestProcessor.BeginGetResponse: EndGetRequestStream");
                }
                catch (Exception e)
                {
                    // if the filling of the request stream fails, finish the Async process here
                    System.Diagnostics.Debug.WriteLine(string.Format("HttpRequestProcessor.BeginGetResponse: EndGetRequestSteam failed. Uri={0}", request.RequestUri));

                    // remember the exception, to be picked up by the subsequent call in to EndGetResponse
                    requestProcessor.RaisedException = e;

                    // clear the timeout event to indicate the async process has finished
                    syncRef.Set();

                    // call the callback as the async process is finished
                    callback(new AsyncResult(requestProcessor, true));

                    return;
                }

                System.Diagnostics.Debug.WriteLine("HttpRequestProcessor.BeginGetResponse: BeginGetResponse started");

                // the HttpWebRequest has the request content in it
                // send the request and get the response
                request.BeginGetResponse((IAsyncResult responseResult) =>
                {
                    // the Async process GetResponse has finished in some way
                    // get the HttpWebRequest provided as a parameter and use it
                    // to complete the GetRespone process

                    HttpWebRequest req = responseResult.AsyncState as HttpWebRequest;
                    try
                    {
                        requestProcessor.WebResponse = req.EndGetResponse(responseResult);
                        System.Diagnostics.Debug.WriteLine("HttpRequestProcessor.BeginGetResponse: EndGetResponse");
                    }
                    catch (Exception e)
                    {
                        // if getting the response fails, catch and remember the exception
                        // for the subsequent call in to EndGetResponse
                        System.Diagnostics.Debug.WriteLine(string.Format("HttpRequestProcessor.BeginGetResponse: EndGetResponse failed. Uri={0}", req.RequestUri));
                        requestProcessor.RaisedException = e;
                    }

                    // clear the timeout timer event
                    syncRef.Set();

                    // call the async callback 
                    callback(new AsyncResult(requestProcessor, true));

                    System.Diagnostics.Debug.WriteLine("HttpRequestProcessor.BeginGetResponse: POST callback complete");

                }, request);

            }, requestProcessor.HttpWebRequest);
        }
        else
        {
            requestProcessor.HttpWebRequest.BeginGetResponse((IAsyncResult responseResult) =>
            {
                HttpWebRequest req = responseResult.AsyncState as HttpWebRequest;

                try
                {
                    requestProcessor.WebResponse = req.EndGetResponse(responseResult);
                    System.Diagnostics.Debug.WriteLine("HttpRequestProcessor.BeginGetResponse: EndGetResponse");
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine(string.Format("HttpRequestProcessor.BeginGetResponse: EndGetResponse failed. Uri={0}", req.RequestUri));
                    requestProcessor.RaisedException = e;
                }

                syncRef.Set();

                callback(new AsyncResult(requestProcessor, true));

                System.Diagnostics.Debug.WriteLine("HttpRequestProcessor.BeginGetResponse: GET callback complete");

            }, requestProcessor.HttpWebRequest);
        }

        // wait for the async process to finish or timeout
        if (!syncRef.WaitOne(requestProcessor.Request.Timeout))
        {
            // async process has time out
            System.Diagnostics.Debug.WriteLine("HttpRequestProcessor.BeginGetResponse: BeginGetStreamRequest timed out");

            // abort the async process and create and remember an exception
            // to be picked up by the call in the EndGetResponse
            requestProcessor.HttpWebRequest.Abort();
            requestProcessor.RaisedException = new TimeoutException("loading request stream timed out");
        }

        return new AsyncResult(requestProcessor, false);
    }

    public static WebResponse EndGetResponse(IAsyncResult result)
    {
        System.Diagnostics.Debug.WriteLine("HttpRequestProcessor.EndGetResponse:");

        var requestProcessor = result.AsyncState as HttpRequestProcessor;

        if (requestProcessor.RaisedException != null)
        {
            throw requestProcessor.RaisedException;
        }
        return requestProcessor.WebResponse;
    }

将此项添加到构造函数可以:


var dummy=System.Threading.Interlocked.Exchange(参考dummyTask,System.Threading.Tasks.Task.Factory.StartNew(()=>{}))

顺便说一句,在iPhone模拟器上运行时不会引发异常,只会在iPhone设备上失败这是一个AOT限制,并且AOT编译器仅用于设备(因此在使用JIT编译器的模拟器构建中不会看到这一点)。请参阅:我知道,如果编译器认为没有使用方法,它有时可能会忽略这些方法->托管链接器(不是编译器)可以删除未使用的代码,并且有一些方法可以防止这种情况(例如
[Preserve]
属性)。o缺少的方法不会抛出executionEngineeException。要[保留]Exchange方法,将意味着对Tasks库进行更改,我认为这是两件事,首先缺少的方法不会抛出executionEngineeException(你最初的假设是错误的,它与链接器无关,链接器可以删除未使用的东西,但AOT编译器不会删除任何东西),其次(如果你是对的)有一些方法可以防止(方法-复数),例如,可以使用XML文件(当[
保留
]无法使用时),或者你可以在应用程序中简单地使用代码(链接器不会删除它)。
                    public static IAsyncResult BeginGetResponse(AsyncCallback callback, object state)
    {
        var requestProcessor = state as HttpRequestProcessor;

        // create the Uri of the Host and Path in the request
        // and use it to create a HttpWebRequest
        Uri u = new Uri(new Uri(requestProcessor.Request.Host), requestProcessor.Request.Path);
        requestProcessor.HttpWebRequest = WebRequest.Create(u) as HttpWebRequest;

        // set up the header of the HttpWebRequest
        requestProcessor.SetupHeader(requestProcessor.HttpWebRequest, requestProcessor.Request);

        requestProcessor.WebResponse = null;
        requestProcessor.RaisedException = null;

        // set up an event to be used to 'timeout' the forthcoming async process
        var syncRef = new System.Threading.AutoResetEvent(false);

        System.Diagnostics.Debug.WriteLine(string.Format("HttpRequestProcessor.BeginGetResponse: started method={0}", requestProcessor.Request.Method));

        // perform the request using the Async method
        // GET and POST requests are processed differently
        if (requestProcessor.Request.Method == HttpMethod.POST)
        {
            // create the request content using the serialiser
            var bytes = requestProcessor.Encoder.Encode(requestProcessor.Request.Data, requestProcessor.Request.ContentType);

            System.Diagnostics.Debug.WriteLine("HttpRequestProcessor.BeginGetResponse: BeginGetRequestStream started");

            // start the async process by adding the content to the request
            requestProcessor.HttpWebRequest.BeginGetRequestStream((IAsyncResult result) =>
            {
                // the asyncronous Get RequestStream has finished in some way
                // complete the Get RequestStream process by calling EndGetRequestStream

                // get the HttpWebRequest provided in the 'state' parameter and
                // use it to call EndGetRequestStream
                var request = result.AsyncState as HttpWebRequest;
                try
                {
                    // fill the request stream with the content
                    using (Stream requestStream = request.EndGetRequestStream(result))
                    {
                        requestStream.Write(bytes, 0, bytes.Length);
                    }

                    System.Diagnostics.Debug.WriteLine("HttpRequestProcessor.BeginGetResponse: EndGetRequestStream");
                }
                catch (Exception e)
                {
                    // if the filling of the request stream fails, finish the Async process here
                    System.Diagnostics.Debug.WriteLine(string.Format("HttpRequestProcessor.BeginGetResponse: EndGetRequestSteam failed. Uri={0}", request.RequestUri));

                    // remember the exception, to be picked up by the subsequent call in to EndGetResponse
                    requestProcessor.RaisedException = e;

                    // clear the timeout event to indicate the async process has finished
                    syncRef.Set();

                    // call the callback as the async process is finished
                    callback(new AsyncResult(requestProcessor, true));

                    return;
                }

                System.Diagnostics.Debug.WriteLine("HttpRequestProcessor.BeginGetResponse: BeginGetResponse started");

                // the HttpWebRequest has the request content in it
                // send the request and get the response
                request.BeginGetResponse((IAsyncResult responseResult) =>
                {
                    // the Async process GetResponse has finished in some way
                    // get the HttpWebRequest provided as a parameter and use it
                    // to complete the GetRespone process

                    HttpWebRequest req = responseResult.AsyncState as HttpWebRequest;
                    try
                    {
                        requestProcessor.WebResponse = req.EndGetResponse(responseResult);
                        System.Diagnostics.Debug.WriteLine("HttpRequestProcessor.BeginGetResponse: EndGetResponse");
                    }
                    catch (Exception e)
                    {
                        // if getting the response fails, catch and remember the exception
                        // for the subsequent call in to EndGetResponse
                        System.Diagnostics.Debug.WriteLine(string.Format("HttpRequestProcessor.BeginGetResponse: EndGetResponse failed. Uri={0}", req.RequestUri));
                        requestProcessor.RaisedException = e;
                    }

                    // clear the timeout timer event
                    syncRef.Set();

                    // call the async callback 
                    callback(new AsyncResult(requestProcessor, true));

                    System.Diagnostics.Debug.WriteLine("HttpRequestProcessor.BeginGetResponse: POST callback complete");

                }, request);

            }, requestProcessor.HttpWebRequest);
        }
        else
        {
            requestProcessor.HttpWebRequest.BeginGetResponse((IAsyncResult responseResult) =>
            {
                HttpWebRequest req = responseResult.AsyncState as HttpWebRequest;

                try
                {
                    requestProcessor.WebResponse = req.EndGetResponse(responseResult);
                    System.Diagnostics.Debug.WriteLine("HttpRequestProcessor.BeginGetResponse: EndGetResponse");
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine(string.Format("HttpRequestProcessor.BeginGetResponse: EndGetResponse failed. Uri={0}", req.RequestUri));
                    requestProcessor.RaisedException = e;
                }

                syncRef.Set();

                callback(new AsyncResult(requestProcessor, true));

                System.Diagnostics.Debug.WriteLine("HttpRequestProcessor.BeginGetResponse: GET callback complete");

            }, requestProcessor.HttpWebRequest);
        }

        // wait for the async process to finish or timeout
        if (!syncRef.WaitOne(requestProcessor.Request.Timeout))
        {
            // async process has time out
            System.Diagnostics.Debug.WriteLine("HttpRequestProcessor.BeginGetResponse: BeginGetStreamRequest timed out");

            // abort the async process and create and remember an exception
            // to be picked up by the call in the EndGetResponse
            requestProcessor.HttpWebRequest.Abort();
            requestProcessor.RaisedException = new TimeoutException("loading request stream timed out");
        }

        return new AsyncResult(requestProcessor, false);
    }

    public static WebResponse EndGetResponse(IAsyncResult result)
    {
        System.Diagnostics.Debug.WriteLine("HttpRequestProcessor.EndGetResponse:");

        var requestProcessor = result.AsyncState as HttpRequestProcessor;

        if (requestProcessor.RaisedException != null)
        {
            throw requestProcessor.RaisedException;
        }
        return requestProcessor.WebResponse;
    }