SignalR icon indicating copy to clipboard operation
SignalR copied to clipboard

AspNetCore.SignalR.Client on Xamarin

Open brettclutch opened this issue 9 years ago • 13 comments

Goals:

  • Chasing the .net standard cross platform dream...
  • Get AspNetCore.SignalR.Client working in .Net Core runtime: Working.
  • Get AspNetCore.SignalR.Client working in .net 4.6.1 winforms runtime: Working.
  • Get AspNetCore.SignalR.Client working in Xamarin.Forms runtime on Android / iOS: Pending and the focus of this issue.

Reproduce repo I uploaded here: https://github.com/brettclutch/sample

The problem:

  • On launch of Xamarin.Forms application on Android emulator with AspNetCore.SignalR.Client results in crash. With the following error right before crash in Debug window:

08-06 15:03:33.540 D/Mono ( 3596): Assembly Loader probing location: 'System.Memory'. 08-06 15:03:33.540 F/monodroid-assembly( 3596): Could not load assembly 'System.Memory' during startup registration.

Additional Info:

  • I'm aware of the following .net standard documentation: https://docs.microsoft.com/en-us/dotnet/standard/net-standard -- Whereby: Xamarin/Mono clearly doesn't have .net standard 2.0 support yet.
  • I'm aware that AspNetCore.SignalR.Client takes a dependency on NetStandard 2.0
  • I'm aware of the .net standard specification API surface as documented here: https://github.com/dotnet/standard/blob/master/docs/versions/netstandard2.0_ref.md

Resulting Confusion / Questions:

  • Hence I understand its expected that it likely just wont work and the answer to this issue is 'wait for Xamarin/Mono to implement .net standard 2.0
  • Where my confusion comes in and why I felt compelled to post is I grew concerned about the below, feel I might be missing some core concept:
  1. The failure point is System.Memory assembly. Which I recall specifically having to update AspNetCore CI build to get AspNetCore.SignalR.Client working.
  2. Per .net standard API surface specs linked above:, System.Memory IS NOT part of .net standard 2.0 specification.

Is AspNetCore.SignalR.Client taking special dependencies on things outside of .net standard 2.0? If so I would provide my feedback to please not do that :) As its causing rough waters for those chasing the cross platform dream.

Thanks Guys.

brettclutch avatar Aug 06 '17 21:08 brettclutch

System.Memory should work across platforms, if it isn't then the portable version of System.Memory needs fixing.

Per .net standard API surface specs linked above:, System.Memory IS NOT part of .net standard 2.0 specification.

FWIW this is irrelevant. The portable version of System.Memory depends on netstandard 1.0. It doesn't need to be in netstandard 2.0 to function.

davidfowl avatar Aug 06 '17 23:08 davidfowl

Didn't mean to bother you on a Sunday sorry.

I see: My misunderstanding that System.Memory was portable. Thanks for mentioning, could you point me in the direction of who would 'own' System.Memory so I could run that up the right flag pole?

Also FWIW, I did more investigating with that in mind. It appears its happening because of these 'Debug' prints on build in a Xamarin Project:

08-06 19:47:50.701 D/Mono ( 4277): Image for assembly 'System.Memory' (/storage/emulated/0/Android/data/com.companyname.Rpf.Xamarin/files/.override/System.Memory.dll) has ReferenceAssemblyAttribute, skipping

Appears the portable has ReferenceAssemblyAttribute -> which I would guess is no good then if its supposed to be portable implementation.

P.S. System.Memory is the 'worst' to google search for :) Can only find a single implementation reference in AspNetCore :)

brettclutch avatar Aug 07 '17 01:08 brettclutch

/cc @akoeplinger any ideas?

davidfowl avatar Aug 07 '17 18:08 davidfowl

The System.Memory package from nuget.org does look good, it targets .NETStandard 1.x and 2.x.

What seems to be happening here is that the reference assembly (from ref/netstandard20 in the nuget package) ends up in your Android app instead of the implementation assembly (from lib/netstandard20). The Mono assembly loader then skips those reference assemblies.

I'm not yet sure why, digging in.

akoeplinger avatar Aug 07 '17 19:08 akoeplinger

Ah, it seems you're using <PackageReference/> to add nuget packages in the Xamarin.Android app. That is not yet supported afaik (and would explain why it adds the reference assembly).

Could you please try switching to packages.config for the Xamarin projects?

akoeplinger avatar Aug 07 '17 19:08 akoeplinger

Thanks for taking a look. Switching to packages.config seems to do the trick.

My Story:

  • I'm developing a .net standard 2.0 DLL I intend to be cross platform.
  • That DLL has references to SignalR including other things.
  • If I want to reference that DLL from other projects i.e. Winforms, Xamarin.Android, etc then I want to just reference that DLL and have that DLL's references resolve (Believe the term I've seen thrown around is: Transitive References).
  • I found that I could switch to PackageReference on the Winforms project file and achieve that.
  • I did the same on the now added Xamarin projects and now learned that PackageReference does not currently work for Xamarin apps as we have discovered.
  • Hence I need to be sure that I add the NUGET references in both my .net standard project and the projects for .Desktop, .Android, .iOS, .Linux, .Mac. Specifically: AspNetCore.SignalR.Client and AspNetCore.Sockets.Client.Http.

Thanks for the assist. Hate wasting your time on user error -> will try to do better for next one.

brettclutch avatar Aug 08 '17 19:08 brettclutch

@brettclutch please don't worry about "wasting" my time, that's what I get paid for :) I'll make sure getting PackageReference working in Xamarin projects is on the roadmap.

akoeplinger avatar Aug 09 '17 00:08 akoeplinger

Hello, I think we have to reopen this issue as it is important issue and not solved.

  • I referenced AspNetCore.SignalR.Client in the android project in a Xamarin forms shared project that fails with the same error: Could not load assembly 'System.Memory' during startup registration . same project works on UWP

  • @akoeplinger, you said "System.Memory package from nuget.org does look good" .. I can't find package called System.Memory on nuget, there is one in the preview channel though

  • @akoeplinger, Xamarin uses PackageReference now, the csproj files are what reference the Nuget libraries using , please correct me if I have wrong understanding here

  • @brettclutch, I have added both AspNetCore.SignalR.Client and AspNetCore.Sockets.Client.Http to my project, plus the preview System.Memory but I am still getting the same error. could you please explain steps you did further.

MhAllan avatar Dec 20 '17 04:12 MhAllan

Sorry, my brain short term memory ring buffer has elapsed and I don't remember many more details. My issue simply was Xamarin at the time did not support PackageReference and using it wouldn't work. If xamarin now support package reference and your trying to get that setup then perhaps you need a new issue ticket if its not working as expected.

brettclutch avatar Dec 20 '17 16:12 brettclutch

I have identical issue with System.Memor that cannot be loaded. Any news regarding the solution ?

ghost avatar Jan 21 '18 19:01 ghost

Same here. Getting error about System.memory in Xamarin.Forms

elusiven avatar Apr 22 '18 12:04 elusiven

The same here

HelloMyDevWorld avatar Apr 23 '18 05:04 HelloMyDevWorld

the same error

dasuma avatar May 11 '18 17:05 dasuma