edjCase / JsonRpc

Json Rpc Router for Asp.Net Core
MIT License
141 stars 42 forks source link

RpcClient sometimes not working with latest Mono #28

Closed slothbag closed 8 years ago

slothbag commented 8 years ago

I had been using an older Mono 3.2.8 with EdjCase.JsonRpc.Client and it was working well, however I just had to update to the latest Mono 4.4.2 because of incompatibilities with another library, and now the JsonRpc.Client is throwing an exception.

System.AggregateException: One or more errors occurred. ---> EdjCase.JsonRpc.Client.RpcClientUnknownException: Error occurred when trying to send rpc requests(s) ---> System.MissingFieldException: Field 'System.Net.HttpWebRequest.ResendContentFactory' not found.
  at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[TResult].Start[TStateMachine] (System.Runtime.CompilerServices.TStateMachine& stateMachine) <0x303a6c8 + 0x00117> in <filename unknown>:0 
  at System.Net.Http.HttpClientHandler.SendAsync (System.Net.Http.HttpRequestMessage request, CancellationToken cancellationToken) <0x303a538 + 0x0016b> in <filename unknown>:0 
  at System.Net.Http.HttpMessageInvoker.SendAsync (System.Net.Http.HttpRequestMessage request, CancellationToken cancellationToken) <0x303a3a0 + 0x00021> in <filename unknown>:0 
  at System.Net.Http.HttpClient.<SendAsync>__BaseCallProxy0 (System.Net.Http.HttpRequestMessage request, CancellationToken cancellationToken) <0x303a370 + 0x0001f> in <filename unknown>:0 
  at System.Net.Http.HttpClient+<SendAsyncWorker>c__async0.MoveNext () <0x3039350 + 0x00237> in <filename unknown>:0 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () <0x18aa010 + 0x00035> in <filename unknown>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) <0x18a7830 + 0x000b7> in <filename unknown>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) <0x18a7790 + 0x00087> in <filename unknown>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) <0x18a7740 + 0x0003f> in <filename unknown>:0 
  at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[TResult].GetResult () <0x18a8040 + 0x00024> in <filename unknown>:0 
  at EdjCase.JsonRpc.Client.RpcClient+<SendAsync>c__async3`2[TRequest,TResponse].MoveNext () <0x2d8bb78 + 0x0042b> in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at EdjCase.JsonRpc.Client.RpcClient+<SendAsync>c__async3`2[TRequest,TResponse].MoveNext () <0x2d8bb78 + 0x008c7> in <filename unknown>:0 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () <0x18aa010 + 0x00035> in <filename unknown>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) <0x18a7830 + 0x000b7> in <filename unknown>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) <0x18a7790 + 0x00087> in <filename unknown>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) <0x18a7740 + 0x0003f> in <filename unknown>:0 
  at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[TResult].GetResult () <0x18a8040 + 0x00024> in <filename unknown>:0 
  at EdjCase.JsonRpc.Client.RpcClient+<SendRequestAsync>c__async0.MoveNext () <0x2d8b640 + 0x0017f> in <filename unknown>:0 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () <0x18aa010 + 0x00035> in <filename unknown>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) <0x18a7830 + 0x000b7> in <filename unknown>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) <0x18a7790 + 0x00087> in <filename unknown>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) <0x18a7740 + 0x0003f> in <filename unknown>:0 
  at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[TResult].GetResult () <0x18a8040 + 0x00024> in <filename unknown>:0 
  at Nethereum.JsonRpc.Client.RpcRequestResponseHandler`1+<SendRequestAsync>d__7[TResponse].MoveNext () <0x2d8ad30 + 0x001df> in <filename unknown>:0 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () <0x18aa010 + 0x00035> in <filename unknown>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) <0x18a7830 + 0x000b7> in <filename unknown>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) <0x18a7790 + 0x00087> in <filename unknown>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) <0x18a7740 + 0x0003f> in <filename unknown>:0 
  at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[TResult].GetResult () <0x18a8040 + 0x00024> in <filename unknown>:0 
  at Nethereum.Web3.FunctionBase+<CallAsync>d__27`1[TReturn].MoveNext () <0x2d8a478 + 0x00213> in <filename unknown>:0

Edit: I tried using the netstarndard, net451, and portable dlls and it made no difference.

Just found this commit, the description says "Not support by Public HttpWebRequest, but HttpClient runs in this mode"

https://github.com/mono/mono/commit/ca2f879ce11ec034a17494316d64406c8a06a615

slothbag commented 8 years ago

So I created my own simple testbed app using RpcClient and it seems to work fine.. but when its called from the external library (https://github.com/Nethereum/Nethereum) it throws the error.

Not sure how Nethereum is calling it different to me and triggering the error?

slothbag commented 8 years ago

This is really bizarre. So the line HttpResponseMessage httpResponseMessage = httpClient.PostAsync(route, httpContent).Result; in RpcClient.SendAsync() is the failure point.

But if I create a really simple project with just the Nethereum specific call then the RpcClient works, but when its within a larger project it throws the error.

The only thing I can think of that is different is in the larger project it is running in a background thread, i'll test that now.

slothbag commented 8 years ago

Looks like the culprit was Mono.Security.dll

If its in the folder with the exe then it causes the error. If you remove the dll everything works fine.

Gekctek commented 7 years ago

Sorry I dont have any mono/linux experience so I would not be the person to ask

On Mon, Oct 17, 2016 at 12:44 PM rquackenbush notifications@github.com wrote:

Interesting. I experienced the same problem, and the Mono.Security.dll workaround worked fine for me. However, if I compile the same source in Visual Studio and copy it over to my linux / machine, I get the same exception, but there is no Mono.Security.dll present.

Here are all of the dlls (except for the ones I build):

Autofac.dll DotNetty.Buffers.dll DotNetty.Buffers.xml DotNetty.Codecs.Mqtt.dll DotNetty.Codecs.dll DotNetty.Codecs.xml DotNetty.Common.dll DotNetty.Handlers.dll DotNetty.Handlers.xml DotNetty.Transport.dll Microsoft.Azure.Amqp.dll Microsoft.Azure.Devices.Client.dll Microsoft.Azure.KeyVault.Core.dll Microsoft.Data.Edm.dll Microsoft.Data.OData.dll Microsoft.Data.Services.Client.dll Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.dll Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.xml Microsoft.WindowsAzure.Storage.dll Microsoft.WindowsAzure.Storage.pdb MiscUtil.dll MiscUtil.pdb Mono.Posix.dll Mono.Security.dll NModbus4.dll Newtonsoft.Json.dll PCLCrypto.dll PInvoke.BCrypt.dll PInvoke.Kernel32.dll PInvoke.Kernel32.xml PInvoke.NCrypt.dll PInvoke.Windows.Core.dll Serilog.Sinks.ColoredConsole.dll Serilog.Sinks.Console.dll Serilog.Sinks.File.dll Serilog.Sinks.PeriodicBatching.dll Serilog.Sinks.RollingFile.dll Serilog.dll System.Spatial.dll Validation.dll

Any ideas on how to determine which assembly is causing the issue?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/edjCase/JsonRpc/issues/28#issuecomment-254312201, or mute the thread https://github.com/notifications/unsubscribe-auth/AB2GadFYZCtwBvovCsVCPeaAnOHdhEB4ks5q09AWgaJpZM4JeoL0 .

jdluzen commented 7 years ago

I also had this issue (though not using this project), removing Mono.Security.dll was the solution as well. This issue is literally the only result when searching for this error. Hopefully the Googlebot will pick it up.

owlstack commented 7 years ago

@jdluzen Thank you! This helped me too! It's very strange. I had this issue when I upgraded to latest Xamarin/VS 2017 version.

kgalic commented 7 years ago

@owlstack please could you explain how did you remove Mono.Security.dll, only from references, or you did something else?

owlstack commented 7 years ago

@kgalic Are you also having this issue with latest Xamarin or another thing? Thanks!