Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fatal error in IL Linker:Failed to resolve Microsoft.Extensions.Logging.Abstractions.Internal.NullScope #16063

Open
mkArtakMSFT opened this issue Aug 6, 2019 · 22 comments

Comments

@mkArtakMSFT
Copy link

From @ar0311 on Monday, August 5, 2019 9:47:44 PM

Describe the bug

Possibly related to #10651

When compiling a Blazor Client app in a Hosted Blazor solution with references to Identity in the Shared project, compilation fails. In my case, using RavenDB.Identity in the Shared project (referenced by the Client project) pulls in the Identity references.

Manually adding a PackageReference in the Client project csproj to Microsoft.Extensions.Logging results in successful compilation

To Reproduce

Steps to reproduce the behavior:

  1. Using preview 7
  2. Repro git repository here
  3. Run dotnet restore && dotnet run (server project)
  4. See error output

Example:

Fatal error in IL Linker
Unhandled exception. Mono.Linker.MarkException: Error processing method: 'System.IDisposable Microsoft.Extensions.Logging.Logger::BeginScope(TState)' in assembly: 'Microsoft.Extensions.Logging.dll'
---> Mono.Cecil.ResolutionException: Failed to resolve Microsoft.Extensions.Logging.Abstractions.Internal.NullScope Microsoft.Extensions.Logging.Abstractions.Internal.NullScope::get_Instance()
at Mono.Linker.Steps.MarkStep.HandleUnresolvedMethod(MethodReference reference)
at Mono.Linker.Steps.MarkStep.MarkMethod(MethodReference 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()

Expected behavior

Successful compilation.

Copied from original issue: dotnet/aspnetcore#12894

@ar0311
Copy link

ar0311 commented Aug 7, 2019

The 10651 referred to is the issue in the aspnet/AspNetCore repo, not mono's.

@ar0311
Copy link

ar0311 commented Aug 13, 2019

After some more playing around, adding the following to the Blazor Client project results in a successful compilation, although obviously a much larger publish size.

<BlazorLinkOnBuild>false</BlazorLinkOnBuild>

Also, might it be related to this?

@ar0311
Copy link

ar0311 commented Aug 14, 2019

Issue still exists in preview 8.

And interestingly, on preview 8 the <BlazorLinkOnBuild>false</BlazorLinkOnBuild> causes a wasm error in the browser and prevents the app even starting. (Something about JSInterop)

@ar0311
Copy link

ar0311 commented Aug 15, 2019

Wasm error output in Chrome console:

blazor.webassembly.js:1 Uncaught (in promise) Error: Could not find method "EndInvokeJS" on type "Mono.WebAssembly.Interop.MonoWebAssemblyJSRuntime" at g (blazor.webassembly.js:1) at blazor.webassembly.js:1 at callRuntimeCallbacks (mono.js:1) at postRun (mono.js:1) at doRun (mono.js:1) at run (mono.js:1) at runCaller (mono.js:1) at removeRunDependency (mono.js:1) at blazor.webassembly.js:1

@CalaxDev
Copy link

I am getting the same error. What can I do about it?

@ar0311
Copy link

ar0311 commented Sep 6, 2019

Still refuses to compile the Client project under preview 9 without referencing Microsoft.Extensions.Logging in the csproj file. Wasm error seems to be gone now.

@ar0311
Copy link

ar0311 commented Sep 17, 2019

Still exists on rc1... (Using updated preview9 blazor packages per rc1 release notes)

@kjpou1
Copy link
Contributor

kjpou1 commented Nov 29, 2019

Is this still a valid issue using the current Blazor preview?

@Cheesebaron
Copy link

Cheesebaron commented Dec 3, 2019

This is also valid when consumed in a Xamarin Android project.

Running latest VS for mac preview:

Mono Framework MDK
Runtime:
	Mono 6.6.0.155 (2019-08/296a9afdb24) (64-bit)
	Package version: 606000155

Stack trace of error:

/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2105,5): error MSB4018: The "LinkAssemblies" task failed unexpectedly.
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2105,5): error MSB4018: Mono.Linker.MarkException: Error processing method: 'System.IDisposable Microsoft.Extensions.Logging.Logger::BeginScope(TState)' in assembly: 'Microsoft.Extensions.Logging.dll' ---> Mono.Cecil.ResolutionException: Failed to resolve Microsoft.Extensions.Logging.Abstractions.Internal.NullScope Microsoft.Extensions.Logging.Abstractions.Internal.NullScope::get_Instance()
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2105,5): error MSB4018:   at Mono.Linker.Steps.MarkStep.HandleUnresolvedMethod (Mono.Cecil.MethodReference reference) [0x00013] in <610526b6785240868e600b8f8b229a30>:0 
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2105,5): error MSB4018:   at Mono.Linker.Steps.MarkStep.MarkMethod (Mono.Cecil.MethodReference reference) [0x0004a] in <610526b6785240868e600b8f8b229a30>:0 
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2105,5): error MSB4018:   at Mono.Linker.Steps.MarkStep.MarkInstruction (Mono.Cecil.Cil.Instruction instruction) [0x00040] in <610526b6785240868e600b8f8b229a30>:0 
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2105,5): error MSB4018:   at Mono.Linker.Steps.MarkStep.MarkMethodBody (Mono.Cecil.Cil.MethodBody body) [0x000c2] in <610526b6785240868e600b8f8b229a30>:0 
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2105,5): error MSB4018:   at Mono.Linker.Steps.MarkStep.ProcessMethod (Mono.Cecil.MethodDefinition method) [0x00186] in <610526b6785240868e600b8f8b229a30>:0 
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2105,5): error MSB4018:   at Mono.Linker.Steps.MarkStep.ProcessQueue () [0x0001b] in <610526b6785240868e600b8f8b229a30>:0 
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2105,5): error MSB4018:    --- End of inner exception stack trace ---
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2105,5): error MSB4018:   at Mono.Linker.Steps.MarkStep.ProcessQueue () [0x00047] in <610526b6785240868e600b8f8b229a30>:0 
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2105,5): error MSB4018:   at Mono.Linker.Steps.MarkStep.ProcessPrimaryQueue () [0x0000a] in <610526b6785240868e600b8f8b229a30>:0 
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2105,5): error MSB4018:   at Mono.Linker.Steps.MarkStep.Process () [0x00102] in <610526b6785240868e600b8f8b229a30>:0 
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2105,5): error MSB4018:   at Mono.Linker.Steps.MarkStep.Process (Mono.Linker.LinkContext context) [0x0000d] in <610526b6785240868e600b8f8b229a30>:0 
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2105,5): error MSB4018:   at MonoDroid.Tuner.MonoDroidMarkStep.Process (Mono.Linker.LinkContext context) [0x0000b] in <610526b6785240868e600b8f8b229a30>:0 
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2105,5): error MSB4018:   at Mono.Linker.Pipeline.ProcessStep (Mono.Linker.LinkContext context, Mono.Linker.Steps.IStep step) [0x0000d] in <610526b6785240868e600b8f8b229a30>:0 
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2105,5): error MSB4018:   at Mono.Linker.Pipeline.Process (Mono.Linker.LinkContext context) [0x0000f] in <610526b6785240868e600b8f8b229a30>:0 
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2105,5): error MSB4018:   at MonoDroid.Tuner.Linker.Run (Mono.Linker.Pipeline pipeline, Mono.Linker.LinkContext context) [0x00000] in <610526b6785240868e600b8f8b229a30>:0 
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2105,5): error MSB4018:   at MonoDroid.Tuner.Linker.Process (MonoDroid.Tuner.LinkerOptions options, Mono.Linker.ILogger logger, Mono.Linker.LinkContext& context) [0x00071] in <610526b6785240868e600b8f8b229a30>:0 
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2105,5): error MSB4018:   at Xamarin.Android.Tasks.LinkAssemblies.Execute (Java.Interop.Tools.Cecil.DirectoryAssemblyResolver res) [0x002d4] in <610526b6785240868e600b8f8b229a30>:0 
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2105,5): error MSB4018:   at Xamarin.Android.Tasks.LinkAssemblies.Execute () [0x0001b] in <610526b6785240868e600b8f8b229a30>:0 
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2105,5): error MSB4018:   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute () [0x00023] in /Users/builder/jenkins/workspace/build-package-osx-mono/2019-06/external/bockbuild/builds/msbuild-15/src/Build/BackEnd/TaskExecutionHost/TaskExecutionHost.cs:574 
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2105,5): error MSB4018:   at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask (Microsoft.Build.BackEnd.ITaskExecutionHost taskExecutionHost, Microsoft.Build.BackEnd.Logging.TaskLoggingContext taskLoggingContext, Microsoft.Build.BackEnd.TaskHost taskHost, Microsoft.Build.BackEnd.ItemBucket bucket, Microsoft.Build.BackEnd.TaskExecutionMode howToExecuteTask) [0x002a9] in /Users/builder/jenkins/workspace/build-package-osx-mono/2019-06/external/bockbuild/builds/msbuild-15/src/Build/BackEnd/Components/RequestBuilder/TaskBuilder.cs:805 
    56 Warning(s)
    1 Error(s)

@Cheesebaron
Copy link

Is anyone looking into this?

@vargaz
Copy link
Contributor

vargaz commented Dec 10, 2019

This seems to be caused by mismatching assemblies, i.e. Microsoft.Extensions.Logging.dll
contains the following IL code:
IL_000a: call [Microsoft.Extensions.Logging.Abstractions]Microsoft.Extensions.Logging.Abstractions.Internal.NullScope [Microsoft.Extensions.Logging.Abstractions]Microsoft.Extensions.Logging.Abstractions.Internal.NullScope::get_Instance()

but the Microsoft.Extensions.Logging.Abstractions assembly doesn't have a type named
Microsoft.Extensions.Logging.Abstractions.Internal.NullScope, it has a type named simply
Microsoft.Extensions.Logging.NullScope.

So this doesn't seem to be a mono/linker issue, the linker fails because it tries to read all the assemblies and resolve all the references.

@Cheesebaron
Copy link

@vargaz thank you for your reply. I will investigate on my end, you are most likely right that some library is pulling in an older version or something. Although I would have never gathered that from this error.

@americanslon
Copy link

So this happened to me out of the blue...Anything I can do? Is this being looked at? Is this even a bug?

@vargaz
Copy link
Contributor

vargaz commented Jan 30, 2020

It happens because mismatching assemblies are being passed to the linker.

@americanslon
Copy link

How would I troubleshoot that? It happened seemingly out of the blue.

@vargaz
Copy link
Contributor

vargaz commented Jan 30, 2020

Its a problem with the build system/IDE/nuget etc. Its not a mono bug.

@Cheesebaron
Copy link

I fixed it by ensuring that every library I consumed was on the same major version of the Microsoft.Extensions.Logging.Abstractions package. Had a dependency on Serilog.Extensions.Logging which pulled in an old version of Microsoft.Extensions.Logging in and in turn grabbed and old version of the Abstractions package.

Since we have no way of checking transitive packages easily with Xamarin projects it is a bit of a cumbersome task to do. But perhaps check your log from restoring packages and see if there are any downgrades there.

@shadow-cs
Copy link
Contributor

Possibly related to dotnet/linker#858

@EnglishDave
Copy link

EnglishDave commented Oct 2, 2020

This problem also occurs when using Microsft.Bot.Connector.DirectLine 3.0.3-Preview1 (references Microsoft.Extensions.Logging 2.1.1 via Microsoft.Bot.StreamingExtensions 4.5.0-preview1) (in one project) with Microsoft.Extensions.Caching.Memory 3.1.7 (references Microsoft.Extensions.Logging.Abstractions 3.1.7) (in a different project) , specifically for Android projects built using an AzureDevOps pipeline. We see the exception, presumably because of the same mismatch, however this builds and runs successfully when built on Visual Studio (Windows or Mac), so it can be surmised that the VS build system successfully handles the mismatch (or at least handles the exception gracefully), whereas the build system used by the AzDevOps pipeline does not, however maybe Microsoft.Extensions.Logging 3.1.7 is being cached by VS.

@amirvenus
Copy link

I am having the exact same issue using JetBrains Rider so I guess only Visual Studio knows how to [gracefully] handle this.

@gabriele-ricci-kyklos
Copy link

It is a problem related to different versions used of Microsoft.Extensions.Logging.
In my case, I was building a Xamarin.Forms app having a starter project in Android, and a .NET Standard project with all the logic. It worked fine in Debug, but presented the issue when building in release mode.
The error I was getting was:

Mono.Linker.MarkException: Error processing method: 'System.IDisposable Microsoft.Extensions.Logging.Logger::BeginScope(TState)' in assembly: 'Microsoft.Extensions.Logging.dll' ---> Mono.Cecil.ResolutionException: Failed to resolve Microsoft.Extensions.Logging.Abstractions.Internal.NullScope Microsoft.Extensions.Logging.Abstractions.Internal.NullScope::get_Instance()
   at Mono.Linker.Steps.MarkStep.HandleUnresolvedMethod(MethodReference reference)
   at Mono.Linker.Steps.MarkStep.MarkMethod(MethodReference 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/builder/azdo/_work/1/s/xamarin-android/external/xamarin-android-tools/src/Microsoft.Android.Build.BaseTasks/AndroidTask.cs:line 17	WMS.Mobile.Android			

To troubleshoot this, you need to look at the {project_name}.deps.json file of the .NET Standard project, checking for different versions of Microsoft.Extensions.Logging.
In my case I found that the NLog package was using a different version than all other packages, so I removed it and manually installed the latest version of Microsoft.Extensions.Logging and then reinstalled NLog, I was then able to build in release mode.

@ToolmakerSteve
Copy link

ToolmakerSteve commented Apr 22, 2022

I just had this happen on a Xamarin.Forms iOS iPhone Release build.
For me, did NOT happen on Android Release build. Nor on iPhoneSimulator Release build. Nor on iPhone Debug build.

Manage Nugets / Install / Microsoft.Extensions.Logging 6.0.0 did eliminate that exception. (I didn't uninstall/reinstall any other nugets).

NOTE: The build crashes when launched (ONLY on iPhone Release), so its possible adding that Logging Nuget version was not sufficient.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests