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

Linker fails when adding a TrimmerRootAssembly #853

Closed
jeffschwMSFT opened this issue Dec 10, 2019 · 4 comments
Closed

Linker fails when adding a TrimmerRootAssembly #853

jeffschwMSFT opened this issue Dec 10, 2019 · 4 comments

Comments

@jeffschwMSFT
Copy link
Member

Transfer of dotnet/runtime#733 (comment)

When using PublishTrimmed=true for publishing single file applications in .net core, I get a runtime error when performing binary serialization/deserialization in System.Runtime.Serialization.Formatters library.

Exe netcoreapp3.0 true true true true win-x64 win-x64;linux-x64 The error during runtime received is:

System.TypeInitializationException: The type initializer for 'System.Runtime.Serialization.Formatters.Binary.Converter' threw an exception.
---> System.IO.FileNotFoundException: Could not load file or assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified.
File name: 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, RuntimeAssembly assemblyContext, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, AssemblyLoadContext assemblyLoadContext)
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, StackCrawlMark& stackMark, AssemblyLoadContext assemblyLoadContext)
at System.Reflection.Assembly.Load(String assemblyString)
at System.Runtime.Serialization.Formatters.Binary.Converter..cctor()

--- End of inner exception stack trace ---
at System.Runtime.Serialization.Formatters.Binary.BinaryParser.get_SystemAssemblyInfo()
at System.Runtime.Serialization.Formatters.Binary.BinaryParser.ReadObjectWithMapTyped(BinaryObjectWithMapTyped record)
at System.Runtime.Serialization.Formatters.Binary.BinaryParser.ReadObjectWithMapTyped(BinaryHeaderEnum binaryHeaderEnum)
at System.Runtime.Serialization.Formatters.Binary.BinaryParser.Run()
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(BinaryParser serParser, Boolean fCheck)
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, Boolean check)
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream)
I also tried adding the following to address this error:

but that prevents it from publishing as it returns an error: C:\Program Files\dotnet\sdk\3.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.ILLink.targets(87,5): error MSB6006: "dotnet.exe" exited with code -1073741819.

I can disable PublishTrimmed=true for now, but I would think there's a way to address this.

The application is a .Net Core 3 app, which references two multi-target libraries which are netstandard2.0;net462

@PeterPann23
Copy link

try and add the following to your csprj file


@sylvaingirardbe
Copy link

sylvaingirardbe commented Apr 15, 2020

Running into the same issue in a netcoreapp3.1 when publishing with

dotnet publish -c release -o /app -r linux-x64 --self-contained true --no-restore /p:PublishTrimmed=true /p:PublishReadyToRun=true 

Setting PublishTrimmed=false fixes it. Resulting docker image is 15MB bigger.

@aloksharma1
Copy link

aloksharma1 commented Mar 13, 2021

did this issue got solved? i'm having the same issue with blazor wasm publish, following is my blazor wasm project csproj file (its just a test using default template)
i am trying to use trim features of wasm assemblies but wants to keep some framework assemblies like runtime etc in the project for later uses, but its crashing on publish
here is the file input

<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<TrimmerRootAssembly Include="System.Security" />
</ItemGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<WarningLevel>4</WarningLevel>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="McMaster.NETCore.Plugins" Version="1.4.0-beta.41" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="5.0.4" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="5.0.4" PrivateAssets="all" />
<PackageReference Include="System.Net.Http.Json" Version="5.0.0" />
</ItemGroup>

</Project>

what am i doing wrong here?
build succeeds but publish failes with error
ILLink(0,0): Error IL1012: IL Linker has encountered an unexpected error. Please report the issue at https://github.com/mono/linker/issues
Fatal error in IL Linker
Unhandled exception. System.IO.FileNotFoundException: Could not find file 'D:\Projects\Web\test\BlazorWasm\BlazorWasm\System.Security'.
File name: 'D:\Projects\Web\test\BlazorWasm\BlazorWasm\System.Security'

@marek-safar
Copy link
Contributor

@aloksharma1 your problem is a duplicate of #1772 which will be addressed in .NET6 P3. The original issue will be addressed as part of dotnet/runtime#43078

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

No branches or pull requests

5 participants