HttpClient inside PCL throws NotImplementedException when called from a Silverlight app

拜拜、爱过 提交于 2019-12-11 18:15:57

问题


I have a portable class library (profile 147 supporting .NET4.03, Silverlight 5, WinPhone 8 and WinStore) that uses HttpClient to make HTTP calls. The library works fine in all platforms except for Silverlight 5.

When the library is used from an SL5 application, an attempt to call SendAsync method with GET verb results in NotImplementedException:

{System.NotImplementedException: The method or operation is not implemented. at System.Net.Browser.ClientHttpWebRequest.set_AllowAutoRedirect(Boolean value)}

I don't call such method (it's exposed on HttpClientHandler class). I set a couple of HTTP headers but they seem to be unrelated to this problem.

What can wrong here?

UPDATE Here is the exception stack trace:

System.Windows.dll!System.Net.Browser.ClientHttpWebRequest.AllowAutoRedirect.set(bool value) + 0x3d bytes   
System.Net.Http!System.Lightup.TryCall<System.Net.HttpWebRequest,bool>(ref System.Delegate storage, System.Net.HttpWebRequest instance, string methodName, bool parameter) + 0xb9 bytes 
System.Net.Http!System.Lightup.TrySet<System.Net.HttpWebRequest,bool>(ref System.Delegate storage, System.Net.HttpWebRequest instance, string propertyName, bool value) + 0xa1 bytes    
System.Net.Http!System.Net.HttpWebRequestLightup.TrySetAllowAutoRedirect(System.Net.HttpWebRequest instance, bool value) + 0x47 bytes   
System.Net.Http!System.Net.Http.HttpWebRequest.AllowAutoRedirect.set(bool value) + 0x58 bytes   
System.Net.Http!System.Net.Http.HttpClientHandler.SetDefaultOptions(System.Net.Http.HttpWebRequest webRequest) + 0x3e bytes 
System.Net.Http!System.Net.Http.HttpClientHandler.CreateAndPrepareWebRequest(System.Net.Http.HttpRequestMessage request) + 0x109 bytes  
System.Net.Http!System.Net.Http.HttpClientHandler.SendAsync(System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) + 0x1af bytes 
System.Net.Http!System.Net.Http.HttpMessageInvoker.SendAsync(System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) + 0x10e bytes    
System.Net.Http!System.Net.Http.HttpClient.SendAsync(System.Net.Http.HttpRequestMessage request, System.Net.Http.HttpCompletionOption completionOption, System.Threading.CancellationToken cancellationToken) + 0x1f4 bytes 
System.Net.Http!System.Net.Http.HttpClient.SendAsync(System.Net.Http.HttpRequestMessage request) + 0x61 bytes   

Simple.OData.Client.Core!Simple.OData.Client.RequestRunnerBase.ExecuteRequestAsync(Simple.OData.Client.HttpRequest request) Line 49 + 0x1c bytes C# Simple.OData.Client.Core!Simple.OData.Client.ODataClient.GetSchemaAsStringAsync(string urlBase, System.Net.ICredentials credentials) Line 23 + 0x17 bytes C# Simple.OData.Client.Core!Simple.OData.Client.Schema.FromUrl() Line 233 + 0x1e bytes C# [Resuming Async Method] System.Threading.Tasks!System.Runtime.CompilerServices.AsyncMethodBuilderCore.Startb__10>(ref Simple.OData.Client.Schema..b_10 stateMachine) + 0xbd bytes
System.Threading.Tasks!System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Startb__10>(ref Simple.OData.Client.Schema..b
_10 stateMachine) + 0x46 bytes
Simple.OData.Client.Core!Simple.OData.Client.Schema.FromUrl.AnonymousMethod__10() + 0x96 bytes
Simple.OData.Client.Core!Simple.OData.Client.Schema.ResolveAsync() Line 52 + 0x1c bytes C# Simple.OData.Client.Core!Simple.OData.Client.ODataClient.FindEntriesAsync(string commandText) Line 60 + 0xe bytes C# Simple.OData.Client.Tests.SL5App!Simple.OData.Client.Tests.ClientTests.FindEntries() Line 24 + 0x19 bytes C# Simple.OData.Client.Tests.SL5App!Simple.OData.Client.Tests.SL5App.MainPage.FindEntries() Line 34 + 0x11 bytes C# Simple.OData.Client.Tests.SL5App!Simple.OData.Client.Tests.SL5App.MainPage.buttonFindEntries_Click(object sender, System.Windows.RoutedEventArgs e) Line 25 + 0x8 bytes C# System.Windows.dll!System.Windows.Controls.Primitives.ButtonBase.OnClick() + 0x3d bytes System.Windows.dll!System.Windows.Controls.Button.OnClick() + 0x44 bytes
System.Windows.dll!System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(System.Windows.Input.MouseButtonEventArgs e) + 0x89 bytes
System.Windows.dll!System.Windows.Controls.Control.OnMouseLeftButtonUp(System.Windows.Controls.Control ctrl, System.EventArgs e) + 0x2a bytes
System.Windows.dll!MS.Internal.JoltHelper.FireEvent(System.IntPtr unmanagedObj, System.IntPtr unmanagedObjArgs, int argsTypeIndex, int actualArgsTypeIndex, string eventName, uint flags) + 0x28f bytes [Appdomain Transition]

来源:https://stackoverflow.com/questions/22210983/httpclient-inside-pcl-throws-notimplementedexception-when-called-from-a-silverli

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!