dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.49k stars 10.04k forks source link

Blazor Preview 7 Linker error #12728

Closed dazinator closed 5 years ago

dazinator commented 5 years ago

Having updated my Blazor client solution from preview 6 to preview 7 followed this guidance doing a dotnet build results in the following linker error where it is unable to find System.Text.Json.Serialization.JsonSerializerOptions:

Hub.Platform.Client -> C:\Users\DarrellTunnell\source\repos\HubCore\src\Hub.Platform\Hub.Platform.Client\bin\Debug\netstandard2.0\Hub.Platform.Client.dll Processing embedded resource linker descriptor: mscorlib.xml Duplicate preserve in resource mscorlib.xml in mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e of System.Threading.WasmRuntime (All). Duplicate uses (All) Type System.Reflection.Assembly has no fields to preserve Fatal error in IL Linker

Unhandled Exception: Mono.Cecil.ResolutionException: Failed to resolve System.Text.Json.Serialization.JsonSerializerOptions at Mono.Linker.Steps.MarkStep.HandleUnresolvedType(TypeReference reference) at Mono.Linker.Steps.MarkStep.MarkType(TypeReference reference) at Mono.Linker.Steps.MarkStep.MarkField(FieldReference reference) at Mono.Linker.Steps.MarkStep.InitializeFields(TypeDefinition type) at Mono.Linker.Steps.MarkStep.InitializeType(TypeDefinition type) at Mono.Linker.Steps.MarkStep.InitializeAssembly(AssemblyDefinition assembly) at Mono.Linker.Steps.MarkStep.Initialize() at Mono.Linker.Steps.MarkStep.Process(LinkContext context) at Mono.Linker.Pipeline.ProcessStep(LinkContext context, IStep step) at Mono.Linker.Pipeline.Process(LinkContext context) at Mono.Linker.Driver.Run(ILogger customLogger) at Mono.Linker.Driver.Execute(String[] args, ILogger customLogger) at Mono.Linker.Driver.Main(String[] args) C:\Users\DarrellTunnell.nuget\packages\microsoft.aspnetcore.blazor.build\3.0.0-preview7.19365.7\targets\Blazor.MonoRuntime.targets(439,5): error MSB3073: The command "dotnet "C:\Users\DarrellTunnell.nuget\packages\microsoft.aspnetcore.blazor.mono\0.10.0-preview7.19351.1\build\netstandard1.0../../tools/illink/illink.dll" -l none --disable-opt unreachablebodies --verbose --strip-security true --exclude-feature com --exclude-feature sre -v false -c link -u link -b true -d "C:\Users\DarrellTunnell.nuget\packages\microsoft.aspnetcore.blazor.mono\0.10.0-preview7.19351.1\build\netstandard1.0../../tools/mono/bcl/" -d "C:\Users\DarrellTunnell.nuget\packages\microsoft.aspnetcore.blazor.mono\0.10.0-preview7.19351.1\build\netstandard1.0../../tools/mono/bcl/Facades/" -o "C:\Users\DarrellTunnell\source\repos\HubCore\src\Hub.Platform\Hub.Platform.Client\obj\Debug\netstandard2.0\blazor\linker/" -x "C:\Users\DarrellTunnell.nuget\packages\microsoft.aspnetcore.blazor.build\3.0.0-preview7.19365.7\targets\BuiltInBclLinkerDescriptor.xml" -x "C:\Users\DarrellTunnell\source\repos\HubCore\src\Hub.Platform\Hub.Platform.Client\obj\Debug\netstandard2.0\blazor\linker.descriptor.xml" -a "C:\Users\DarrellTunnell.nuget\packages\blazorsignalr\0.7.0-blazor-3.0.0-preview6.19307.2\lib\netstandard2.0\BlazorSignalR.JS.dll" -a "C:\Users\DarrellTunnell.nuget\packages\blazorsignalr\0.7.0-blazor-3.0.0-preview6.19307.2\lib\netstandard2.0\BlazorSignalR.dll" -a "C:\Users\DarrellTunnell.nuget\packages\lazycache\2.0.1\lib\netstandard2.0\LazyCache.dll" -a "C:\Users\DarrellTunnell.nuget\packages\lazycache.aspnetcore\2.0.1\lib\netstandard2.0\LazyCache.AspNetCore.dll" -a "C:\Users\DarrellTunnell.nuget\packages\microsoft.aspnetcore.authorization\3.0.0-preview7.19365.7\lib\netstandard2.0\Microsoft.AspNetCore.Authorization.dll" -a "C:\Users\DarrellTunnell.nuget\packages\microsoft.aspnetcore.blazor\3.0.0-preview7.19365.7\lib\netstandard2.0\Microsoft.AspNetCore.Blazor.dll" -a "C:\Users\DarrellTunnell.nuget\packages\microsoft.aspnetcore.components\3.0.0-preview7.19365.7\lib\netstandard2.0\Microsoft.AspNetCore.Components.dll" -a "C:\Users\DarrellTunnell.nuget\packages\microsoft.aspnetcore.components.browser\3.0.0-preview7.19365.7\lib\netstandard2.0\Microsoft.AspNetCore.Components.Browser.dll" -a "C:\Users\DarrellTunnell.nuget\packages\microsoft.aspnetcore.connections.abstractions\3.0.0-preview6.19307.2\lib\netstandard2.0\Microsoft.AspNetCore.Connections.Abstractions.dll" -a "C:\Users\DarrellTunnell.nuget\packages\microsoft.aspnetcore.http.connections.client\3.0.0-preview6.19307.2\lib\netstandard2.0\Microsoft.AspNetCore.Http.Connections.Client.dll" -a "C:\Users\DarrellTunnell.nuget\packages\microsoft.aspnetcore.http.connections.common\3.0.0-preview6.19307.2\lib\netstandard2.0\Microsoft.AspNetCore.Http.Connections.Common.dll" -a "C:\Users\DarrellTunnell.nuget\packages\microsoft.aspnetcore.http.features\3.0.0-preview6.19307.2\lib\netstandard2.0\Microsoft.AspNetCore.Http.Features.dll" -a "C:\Users\DarrellTunnell.nuget\packages\microsoft.aspnetcore.metadata\3.0.0-preview7.19365.7\lib\netstandard2.0\Microsoft.AspNetCore.Metadata.dll" -a "C:\Users\DarrellTunnell.nuget\packages\microsoft.aspnetcore.signalr.client\3.0.0-preview6.19307.2\lib\netstandard2.0\Microsoft.AspNetCore.SignalR.Client.dll" -a "C:\Users\DarrellTunnell.nuget\packages\microsoft.aspnetcore.signalr.client.core\3.0.0-preview6.19307.2\lib\netstandard2.0\Microsoft.AspNetCore.SignalR.Client.Core.dll" -a "C:\Users\DarrellTunnell.nuget\packages\microsoft.aspnetcore.signalr.common\3.0.0-preview6.19307.2\lib\netstandard2.0\Microsoft.AspNetCore.SignalR.Common.dll" -a "C:\Users\DarrellTunnell.nuget\packages\microsoft.aspnetcore.signalr.protocols.json\3.0.0-preview6.19307.2\lib\netstandard2.0\Microsoft.AspNetCore.SignalR.Protocols.Json.dll" -a "C:\Users\DarrellTunnell.nuget\packages\microsoft.bcl.asyncinterfaces\1.0.0-preview7.19362.9\lib\netstandard2.0\Microsoft.Bcl.AsyncInterfaces.dll" -a "C:\Users\DarrellTunnell.nuget\packages\microsoft.extensions.caching.abstractions\3.0.0-preview7.19362.4\lib\netstandard2.0\Microsoft.Extensions.Caching.Abstractions.dll" -a "C:\Users\DarrellTunnell.nuget\packages\microsoft.extensions.caching.memory\3.0.0-preview7.19362.4\lib\netstandard2.0\Microsoft.Extensions.Caching.Memory.dll" -a "C:\Users\DarrellTunnell.nuget\packages\microsoft.extensions.configuration\3.0.0-preview7.19362.4\lib\netstandard2.0\Microsoft.Extensions.Configuration.dll" -a "C:\Users\DarrellTunnell.nuget\packages\microsoft.extensions.configuration.abstractions\3.0.0-preview7.19362.4\lib\netstandard2.0\Microsoft.Extensions.Configuration.Abstractions.dll" -a "C:\Users\DarrellTunnell.nuget\packages\microsoft.extensions.configuration.binder\3.0.0-preview7.19362.4\lib\netstandard2.0\Microsoft.Extensions.Configuration.Binder.dll" -a "C:\Users\DarrellTunnell.nuget\packages\microsoft.extensions.dependencyinjection\3.0.0-preview7.19362.4\lib\netstandard2.0\Microsoft.Extensions.DependencyInjection.dll" -a "C:\Users\DarrellTunnell.nuget\packages\microsoft.extensions.dependencyinjection.abstractions\3.0.0-preview7.19362.4\lib\netstandard2.0\Microsoft.Extensions.DependencyInjection.Abstractions.dll" -a "C:\Users\DarrellTunnell.nuget\packages\microsoft.extensions.http\3.0.0-preview7.19362.4\lib\netstandard2.0\Microsoft.Extensions.Http.dll" -a "C:\Users\DarrellTunnell.nuget\packages\microsoft.extensions.logging\3.0.0-preview7.19362.4\lib\netstandard2.0\Microsoft.Extensions.Logging.dll" -a "C:\Users\DarrellTunnell.nuget\packages\microsoft.extensions.logging.abstractions\3.0.0-preview7.19362.4\lib\netstandard2.0\Microsoft.Extensions.Logging.Abstractions.dll" -a "C:\Users\DarrellTunnell.nuget\packages\microsoft.extensions.options\3.0.0-preview7.19362.4\lib\netstandard2.0\Microsoft.Extensions.Options.dll" -a "C:\Users\DarrellTunnell.nuget\packages\microsoft.extensions.primitives\3.0.0-preview7.19362.4\lib\netstandard2.0\Microsoft.Extensions.Primitives.dll" -a "C:\Users\DarrellTunnell.nuget\packages\microsoft.jsinterop\3.0.0-preview7.19362.4\lib\netstandard2.0\Microsoft.JSInterop.dll" -a "C:\Users\DarrellTunnell.nuget\packages\mono.webassembly.interop\3.0.0-preview7.19362.4\lib\netstandard2.0\Mono.WebAssembly.Interop.dll" -a "C:\Users\DarrellTunnell.nuget\packages\netpack.browserreload.blazorclient\0.3.0-alpha0108\lib\netstandard2.0\NetPack.BrowserReload.BlazorClient.dll" -a "C:\Program Files\dotnet\sdk\NuGetFallbackFolder\system.buffers\4.5.0\lib\netstandard2.0\System.Buffers.dll" -a "C:\Users\DarrellTunnell.nuget\packages\system.componentmodel.annotations\4.6.0-preview7.19362.9\lib\netstandard2.0\System.ComponentModel.Annotations.dll" -a "C:\Users\DarrellTunnell.nuget\packages\system.io.pipelines\4.6.0-preview6.19303.8\lib\netstandard2.0\System.IO.Pipelines.dll" -a "C:\Users\DarrellTunnell.nuget\packages\system.memory\4.5.3\lib\netstandard2.0\System.Memory.dll" -a "C:\Program Files\dotnet\sdk\NuGetFallbackFolder\system.numerics.vectors\4.5.0\lib\netstandard2.0\System.Numerics.Vectors.dll" -a "C:\Users\DarrellTunnell.nuget\packages\system.runtime.compilerservices.unsafe\4.6.0-preview7.19362.9\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll" -a "C:\Users\DarrellTunnell.nuget\packages\system.text.json\4.6.0-preview7.19362.9\lib\netstandard2.0\System.Text.Json.dll" -a "C:\Users\DarrellTunnell.nuget\packages\system.threading.channels\4.6.0-preview6.19303.8\lib\netstandard2.0\System.Threading.Channels.dll" -a "C:\Users\DarrellTunnell.nuget\packages\system.threading.tasks.extensions\4.5.2\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll" -a "C:\Users\DarrellTunnell\source\repos\HubCore\src\Hub.Platform\Hub.Platform.Shared\bin\Debug\netstandard2.0\Hub.Platform.Shared.dll" -a "C:\Users\DarrellTunnell\source\repos\HubCore\src\Hub.Platform\Hub.Platform.Client\obj\Debug\netstandard2.0\Hub.Platform.Client.dll"" exited with code -532462766. [C:\Users\DarrellTunnell\source\repos\HubCore\src\Hub.Platform\Hub.Platform.Client\Hub.Platform.Client.csproj]

Build FAILED.

Notes:

dazinator commented 5 years ago

I did, but i noticed one of my dependencies still references a preview-6 blazor depedendency. Would this cause the linker to bomb out?

stavroskasidis commented 5 years ago

I think that also happened to me, because some references where preview-6. Try upgrading everything.

RemiBou commented 5 years ago

@dazinator yes it might because ILLinker will try to find what is useless in your project binaries so If it finds something referencing (in your project or in a dependency) "System.Text.Json.Serialization.JsonSerializerOptions" it'll try to find it. In this case this class moved a namespace upper in "System.Text.Json". It could also be because of an other dependency. If you still want to execute your project, you can disable the linker by following this doc https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/blazor/configure-linker?view=aspnetcore-3.0

But you might have this error at runtime anyway.

mkArtakMSFT commented 5 years ago

@dazinator please confirm this is an issue after you'll resolve all your references to point to Preview7.

dazinator commented 5 years ago

Ok. I'll have to wait until downstream dependencies are republished to nuget until I can retest this in my application.

artezhar commented 5 years ago

Ran into same issue, updated all dependencies (and sub-sub-... -dependencies) to Preview-7 and IL Linker worked again!

SeppPenner commented 5 years ago

I saw a similar issue today. This was caused by some custom nuget dependencies that were not compiled as the correct target framework, e.g. one .NetStandard project referencing NetFramework:

5>Processing embedded resource linker descriptor: mscorlib.xml
5>Duplicate preserve in resource mscorlib.xml in mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e of System.Threading.WasmRuntime (All).  Duplicate uses (All)
5>Type System.Reflection.Assembly has no fields to preserve
5>Fatal error in IL Linker
5>Unhandled exception. Mono.Cecil.ResolutionException: Failed to resolve System.IO.Ports.SerialPort
5>   at Mono.Linker.Steps.MarkStep.HandleUnresolvedType(TypeReference reference)
5>   at Mono.Linker.Steps.MarkStep.MarkType(TypeReference reference)
5>   at Mono.Linker.Steps.MarkStep.MarkField(FieldReference reference)
5>   at Mono.Linker.Steps.MarkStep.InitializeFields(TypeDefinition type)
5>   at Mono.Linker.Steps.MarkStep.InitializeType(TypeDefinition type)
5>   at Mono.Linker.Steps.MarkStep.InitializeAssembly(AssemblyDefinition assembly)
5>   at Mono.Linker.Steps.MarkStep.Initialize()
5>   at Mono.Linker.Steps.MarkStep.Process(LinkContext context)
5>   at Mono.Linker.Pipeline.ProcessStep(LinkContext context, IStep step)
5>   at Mono.Linker.Pipeline.Process(LinkContext context)
5>   at Mono.Linker.Driver.Run(ILogger customLogger)
5>   at Mono.Linker.Driver.Execute(String[] args, ILogger customLogger)
5>   at Mono.Linker.Driver.Main(String[] args)
mkArtakMSFT commented 5 years ago

Closing this as this doesn't seem to be an issue with Blazor.