alexrainman / ModernHttpClient

ModernHttpClient
MIT License
126 stars 28 forks source link

Exception on UWP with Xamarin Forms #3

Closed pfranklinExponent closed 6 years ago

pfranklinExponent commented 6 years ago

I receive the following exception when using the ModernHttpClient in the .NET Standard library when running a UWP app:

Could not load type 'ModernHttpClient.NativeMessageHandler' from assembly 'ModernHttpClient, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'

However, if I instantiate the client and run the code locally within the UWP project it works fine. I'd like to put all my services, etc. in the .NET Standard library, but this is preventing me from doing so.

All works fine in iOS. I have yet to test on Android

alexrainman commented 6 years ago

The plugin only support .Net Standard 2.0, is that your case?

pfranklinExponent commented 6 years ago

Yes, I'm using .Net Standard 2.0. Not sure if this helps or not, but I removed this plugin and replaced it with the original ModernHttpClient written by Paul Betts and everything works fine across all platforms (iOS, Android, and UWP). I was under the assumption that the original did not support .Net Standard, which was why I went with your plugin.

alexrainman commented 6 years ago

No idea how it is working and why mine is not working in your case because it is working for others. Mine supports .Net Standard but also it comes with a custom implementation for UWP.

alexrainman commented 6 years ago

As i said, theres a custom native handler for UWP that is not included in the original plugin. That custom handler implements lot of things: timeout, native cookie handler, support for self signed certificates and so on.

vincentcastagna commented 6 years ago

Hello, First of all, thank you @alexrainman for your work on updating this package this is a nice thing. I got the exact same problem for UWP. Same error.

Tested and working well on Android and iOS. I'm also targeting .net standard 2.0.

Pinox commented 6 years ago

@alexrainman As previous 2 users stated. I also get the same error by just installing modernHttp in clean XF template.

Error message : TypeLoadException: Could not load type 'ModernHttpClient.NativeMessageHandler' from assembly 'ModernHttpClient, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.

Please find attached a repo that reproduce the problem, Android works perfectly but UWP throws an exception on the same code.

Thanks in advance for looking at this.

modernHttp.zip

alexrainman commented 6 years ago

@pinox going to take a look.

Pinox commented 6 years ago

@alexrainman Thanks. As a side note, not sure if this can help you or if it's applicable to this problem at all, but I recently listened to an interesting podcast by james montemagno specifically for library creators. http://www.mergeconflict.fm/85 called multi-targeting and the complexity of nuget packages.

alexrainman commented 6 years ago

I really don't know what is going on here. It works on the Demo but not in Nuget package :(

alexrainman commented 6 years ago

Trying to solve this and release a new version.

alexrainman commented 6 years ago

Going to fix this in the next release.

alexrainman commented 6 years ago

Version 2.7.0 has been released. Please test.

Pinox commented 6 years ago

Hi @alexrainman ,

I still see an error on the sample project posted above after updating to version 2.7

modernhttperror

Pinox commented 6 years ago

Hi @alexrainman ,

I see with this lib using multi-targeting now , not sure if this is of use for you.

https://montemagno.com/converting-xamarin-libraries-to-sdk-style-multi-targeted-projects/?utm_campaign=Weekly%2BXamarin&utm_medium=email&utm_source=Weekly_Xamarin_156

alexrainman commented 6 years ago

Somehow the plugin is not working as expected in .netstandard with the original architecture from Paul. Going to migrate it to default Xamarin plugin Lazy load style.

alexrainman commented 6 years ago

Found a lot of issues in my custom HttpClientHandler for UWP that i didn't see before. Fixed now.

Pinox commented 6 years ago

Awesome @alexrainman with V2.71 It works now as expected , there was a problem in my previous sample app where it uses a static instance of modernhttpclient when I change that to "new instance" then all works well. you're a star.

alexrainman commented 6 years ago

Great!