dotnet / linker

387 stars 127 forks source link

Error processing method: 'System.Void Microsoft.AspNetCore.SignalR.HubConnectionContext/<WriteHandshakeResponseAsync>d__47::MoveNext()' in assembly: 'Microsoft.AspNetCore.SignalR.Core.dll' ---> Mono.Cecil.ResolutionException: Failed to resolve System.ReadOnlyMemory`1<System.Byte> #3022

Open aproko234 opened 2 years ago

aproko234 commented 2 years ago

I am having this issue when trying to archive my android project in VS 17.3.1:

Severity Code Description Project File Line Suppression State Error Mono.Linker.MarkException: Error processing method: 'System.Void Microsoft.AspNetCore.SignalR.HubConnectionContext/d__47::MoveNext()' in assembly: 'Microsoft.AspNetCore.SignalR.Core.dll' ---> Mono.Cecil.ResolutionException: Failed to resolve System.ReadOnlyMemory`1 Microsoft.AspNetCore.SignalR.Protocol.HandshakeProtocol::SuccessHandshakeData at Mono.Linker.Steps.MarkStep.HandleUnresolvedField(FieldReference reference) at Mono.Linker.Steps.MarkStep.MarkInstruction(Instruction instruction) at Mono.Linker.Steps.MarkStep.MarkMethodBody(MethodBody body) at Mono.Linker.Steps.MarkStep.ProcessMethod(MethodDefinition method) at Mono.Linker.Steps.MarkStep.ProcessQueue() --- End of inner exception stack trace --- at Mono.Linker.Steps.MarkStep.ProcessQueue() at Mono.Linker.Steps.MarkStep.ProcessPrimaryQueue() at Mono.Linker.Steps.MarkStep.Process() at Mono.Linker.Steps.MarkStep.Process(LinkContext context) at MonoDroid.Tuner.MonoDroidMarkStep.Process(LinkContext context) at Mono.Linker.Pipeline.ProcessStep(LinkContext context, IStep step) at Mono.Linker.Pipeline.Process(LinkContext context) at MonoDroid.Tuner.Linker.Process(LinkerOptions options, ILogger logger, LinkContext& context) at Xamarin.Android.Tasks.LinkAssemblies.Execute(DirectoryAssemblyResolver res) at Xamarin.Android.Tasks.LinkAssemblies.RunTask() at Microsoft.Android.Build.Tasks.AndroidTask.Execute() in /Users/runner/work/1/s/xamarin-android/external/xamarin-android-tools/src/Microsoft.Android.Build.BaseTasks/AndroidTask.cs:line 17 Project.zip AbuseAlert.Android

This project compiles and runs successfully (in debug mode) before I attempted to archive it (in release mode). It gives the afore-mentioned error.

I am attaching the project. I am using Visual Studio for Windows (64-bit) 17.3.3

marek-safar commented 2 years ago

It looks like SDK is not passing the full list of dependencies

/cc @sbomer @vitek-karas

aproko234 commented 2 years ago

Ok. Is this an issue to be resolved by the Visual Studio Team? Is there a workaround to this?

vitek-karas commented 2 years ago

The problem is a large version mismatch in resolved dependencies. The project AbuseAlert references Microsoft.AspNetCore.SignalR.Client version 6.0.8 - which brings in Microsoft.AspNetCore.SignalR.Common.dll version 6.0.0. The project AbuseAlert also referenced Microsoft.Azure.WebJobs.Extensions.SignalRService version 1.8.0 which eventually references Microsoft.AspNetCore.SignalR.dll version 1.0.0 which in turn has a reference to Microsoft.AspNetCore.SignalR.Common.dll version 1.0.0. But due to the above, it's resolved as version 6.0.0. Apparently there have been public API breaking changes in that assembly between versions 1.0.0 and 6.0.0, one such example is that version 1.0.0 had a field HandshakeProtocol.SuccessHanshakeData but version 6.0.0 doesn't have it.

I don't know what would be the best way to resolve this honestly, it's a version mismatch between dependencies which are not backward compatible.

The main problem is with Microsoft.Azure.WebJobs.Extensions.SignalRService which has a dependency on Microsoft.AspNetCore.SignalR package which has been deprecated. But as far as I can tell, there's no higher version available. https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/signalr/Microsoft.Azure.WebJobs.Extensions.SignalRService/src/Microsoft.Azure.WebJobs.Extensions.SignalRService.csproj

I would suggest creating an issue in the https://github.com/Azure/azure-sdk-for-net repo asking about this problem.

Other things to consider:

marek-safar commented 2 years ago

@jonathanpeppers @jonpryor for the question about how XA handles unresolved/missing dependencies in general

@jsquire @weshaggard to help with Azure SDK routing

jsquire commented 2 years ago

//cc: @sffamily @chenkennt @Y-Sindo

jonathanpeppers commented 2 years ago

One thing to note is the problem above is from a Xamarin.Android project. It's hard to know if we'd hit the same issue with ILLink vs. MonoDroidMarkStep.

@aproko234 do you get different/better results if you move your app to .NET 6? Or maybe you could try to make a smaller example project that hits this issue?

Y-Sindo commented 2 years ago

The version mismatch problem might be resolved by adding .NET 6.0 to the target frameworks of Microsoft.Azure.WebJobs.Extensions.SignalRService, as the .NET 6.0 won't have indirect dependency on Microsoft.AspNetCore.SignalR. But I am not sure if the solution is compliant with the SDK repo policy (currently all extension packages target only .NET Standard 2.0. @jsquire And I meets two errors when I try to add .NET 6 to the tfm.

Severity    Code    Description Project File    Line    Suppression State
Error       ResolvedMatchingContract 'C:\Users\username\.nuget\packages\microsoft.azure.webjobs.extensions.signalrservice\1.8.0\lib\net6.0\Microsoft.Azure.WebJobs.Extensions.SignalRService.dll' did not exist.    Microsoft.Azure.WebJobs.Extensions.SignalRService   C:\Users\username\.nuget\packages\microsoft.dotnet.apicompat\5.0.0-beta.20467.1\build\Microsoft.DotNet.ApiCompat.targets    51  
Error   CS0006  Metadata file 'C:\Users\username\source\repos\azure-sdk-for-net\artifacts\obj\Microsoft.Azure.WebJobs.Extensions.SignalRService\Debug\net6.0\ref\Microsoft.Azure.WebJobs.Extensions.SignalRService.dll' could not be found  Microsoft.Azure.WebJobs.Extensions.SignalRService.Tests (net461)    C:\Users\username\source\repos\azure-sdk-for-net\sdk\signalr\Microsoft.Azure.WebJobs.Extensions.SignalRService\tests\CSC    1   Active