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

.NET 5 Linux Trimming Error #42582

Closed
jjxtra opened this issue Sep 22, 2020 · 13 comments
Closed

.NET 5 Linux Trimming Error #42582

jjxtra opened this issue Sep 22, 2020 · 13 comments
Labels
area-Host linkable-framework Issues associated with delivering a linker friendly framework
Milestone

Comments

@jjxtra
Copy link

jjxtra commented Sep 22, 2020

Publishing my app to Ubuntu with Linux-x64 platform using .NET 5 RC 1. Trimming is ON, single file is off.

Upon startup, I get this error:

Error Exception: System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.

File name: 'System.Runtime, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'
   at Microsoft.Extensions.Hosting.GenericHostWebHostBuilderExtensions.ConfigureWebHost(IHostBuilder builder, Action`1 configure)

This error does not happen with .net core 3.1 with trimming enabled.

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added area-Infrastructure-libraries untriaged New issue has not been triaged by the area owner labels Sep 22, 2020
@ghost
Copy link

ghost commented Sep 22, 2020

Tagging subscribers to this area: @safern, @ViktorHofer
See info in area-owners.md if you want to be subscribed.

@Fabi
Copy link

Fabi commented Sep 22, 2020

Publishing my app to Ubuntu with Linux-x64 platform using .NET 5 RC 1. Trimming is ON, single file is off.

Upon startup, I get this error:

Error Exception: System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.

File name: 'System.Runtime, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'
   at Microsoft.Extensions.Hosting.GenericHostWebHostBuilderExtensions.ConfigureWebHost(IHostBuilder builder, Action`1 configure)

This error does not happen with .net core 3.1 with trimming enabled.

Exclude that file from trimming

@jjxtra
Copy link
Author

jjxtra commented Sep 22, 2020

The file version is 0.0.0.0. It is not part of any of my nuget packages that I can tell. How would I go about excluding this? It feels like a phantom file given the version...

@Fabi
Copy link

Fabi commented Sep 22, 2020

The file version is 0.0.0.0. It is not part of any of my nuget packages that I can tell. How would I go about excluding this? It feels like a phantom file given the version...

Is this working? I got similar problems using that and stuff like that fixed many issues for me
Otherwise you might need to include some other things.
The same happens for default WPF apps etc. They just don't work without additional configuration for trimming (why?!?!!)

<ItemGroup>
      <TrimmerRootAssembly Include="mscorlib" />
      <TrimmerRootAssembly Include="netstandard" />
</ItemGroup>

@jjxtra
Copy link
Author

jjxtra commented Sep 22, 2020

I had to add the following:

<ItemGroup>
	<TrimmerRootAssembly Include="System.Core" />
	<TrimmerRootAssembly Include="System.Reflection" />
	<TrimmerRootAssembly Include="System.Runtime" />
	<TrimmerRootAssembly Include="mscorlib" />
	<TrimmerRootAssembly Include="netstandard" />
</ItemGroup>

It's odd that these core set of assemblies would even be analyzed by the trimmer at all... :|

@Fabi
Copy link

Fabi commented Sep 22, 2020

Yea that's pretty annoying that's true, but at least it works for now :D

@eerhardt
Copy link
Member

@jjxtra - is it possible to share your .csproj and the exact command you ran to publish the app? You are right, you should not be seeing an error like this by default. I think something is going wrong.

cc @sbomer

@eerhardt eerhardt added area-Host linkable-framework Issues associated with delivering a linker friendly framework and removed area-Infrastructure-libraries labels Sep 22, 2020
@ghost
Copy link

ghost commented Sep 22, 2020

Tagging subscribers to this area: @vitek-karas, @agocke
See info in area-owners.md if you want to be subscribed.

@eerhardt
Copy link
Member

I know area-Host isn't the greatest area for this issue - but there isn't an area for "linker" issues like there is for SingleFile, and it is better than "infrastructure". If there is a better one, please correct it.

@vitek-karas
Copy link
Member

I think for now it's fine - I expect the problem to be somewhere in FX, but before we figure out where... it can stay here 😉

@jjxtra
Copy link
Author

jjxtra commented Sep 22, 2020

I have 2 ubuntu servers. One of them oddly does not have this problem. The other, which I had previously installed the .NET 3.1.101 sdk on and then removed had the issue. Servers are identical otherwise.

<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFrameworks>net5.0</TargetFrameworks>
    <TrimUnusedDependencies>true</TrimUnusedDependencies>
    <TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
    <DebugType>portable</DebugType>
    <LangVersion>latest</LangVersion>
    <RootNamespace>***</RootNamespace>
    <AssemblyName>***</AssemblyName>
    <MvcRazorExcludeRefAssembliesFromPublish>false</MvcRazorExcludeRefAssembliesFromPublish>
    <CopyRefAssembliesToPublishDirectory>true</CopyRefAssembliesToPublishDirectory>
    <PreserveCompilationReferences>true</PreserveCompilationReferences>
    <PreserveCompilationContext>true</PreserveCompilationContext>
    <PublishTrimmed>true</PublishTrimmed>
    <GenerateSerializationAssemblies>false</GenerateSerializationAssemblies>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
    <PackageReference Include="SharpCompress" Version="0.26.0" />
  </ItemGroup>
</Project>

This project references another shared library project which looks like this:

<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFrameworks>net5.0</TargetFrameworks>
    <PlatformTarget>AnyCPU</PlatformTarget>
    <TrimUnusedDependencies>true</TrimUnusedDependencies>
    <TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
    <DebugType>portable</DebugType>
    <LangVersion>latest</LangVersion>
    <RootNamespace>***</RootNamespace>
    <AssemblyName>***</AssemblyName>
    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
    <MvcRazorExcludeRefAssembliesFromPublish>false</MvcRazorExcludeRefAssembliesFromPublish>
    <CopyRefAssembliesToPublishDirectory>true</CopyRefAssembliesToPublishDirectory>
    <PreserveCompilationContext>true</PreserveCompilationContext>
    <DefineConstants>$(DefineConstants);EFCORE3</DefineConstants>
    <EFCoreVersion>3.0.0</EFCoreVersion>
    <GenerateSerializationAssemblies>false</GenerateSerializationAssemblies>
  </PropertyGroup>

  <ItemGroup>
    <FrameworkReference Include="Microsoft.AspNetCore.App" />
    <PackageReference Include="FlexLabs.EntityFrameworkCore.Upsert" Version="3.1.0" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="3.1.8" />
    <PackageReference Include="Humanizer" Version="2.8.26" />
    <PackageReference Include="MailKit" Version="2.9.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="3.1.8" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="3.1.8" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="3.1.8" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.8" />
    <PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="3.1.8" />
    <PackageReference Include="Microsoft.Extensions.Hosting" Version="3.1.8" />
    <PackageReference Include="Microsoft.Extensions.Http.Polly" Version="3.1.8" />
    <PackageReference Include="Microsoft.Web.Administration" Version="11.1.0" />
    <PackageReference Include="NLog" Version="4.7.4" />
    <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="3.1.4" />
    <PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="3.2.0" />
    <PackageReference Include="protobuf-net.Grpc.AspNetCore" Version="1.0.123" />
    <PackageReference Include="SharpCompress" Version="0.26.0" />
    <PackageReference Include="StackExchange.Redis" Version="2.1.58" />
    <PackageReference Include="System.Net.WebSockets" Version="4.3.0" />
    <PackageReference Include="System.Net.WebSockets.WebSocketProtocol" Version="4.7.1" />
  </ItemGroup>
</Project>

@agocke agocke removed the untriaged New issue has not been triaged by the area owner label Sep 28, 2020
@agocke agocke added this to the 6.0.0 milestone Sep 28, 2020
@eerhardt
Copy link
Member

Is this fixed now that we are copying facade assemblies? See dotnet/linker#1837

@sbomer
Copy link
Member

sbomer commented May 18, 2021

Yes, I believe this is fixed. (We're not copying facades - we're consistently keeping the pieces that are required by other assemblies that are copied or by string references to facade assemblies).

@sbomer sbomer closed this as completed May 18, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Jun 18, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-Host linkable-framework Issues associated with delivering a linker friendly framework
Projects
None yet
Development

No branches or pull requests

7 participants