Closed
Description
Describe the bug
When building a project that
- includes globalization resources (comes from referenced packages)
- uses native AOT
- with
DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=true
set - on Linux
- using .NET 8 Preview 6
the build fails.
To Reproduce
Build a project in container with the following files:
(purposefully including a reference to System.CommandLine
to include some globalization resources)
cstest.csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<PublishAot>true</PublishAot>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<InvariantGlobalization>true</InvariantGlobalization>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
</ItemGroup>
</Project>
Program.cs:
using System.CommandLine;
var rootCommand = new RootCommand("Sample app for System.CommandLine");
rootCommand.SetHandler(() => Console.WriteLine("Hello, World!"));
return await rootCommand.InvokeAsync(args);
Dockerfile:
FROM alpine:latest AS build
RUN apk update \
&& apk add clang build-base bash zlib-dev
RUN mkdir -p /usr/share/dotnet && ln -s /usr/share/dotnet/dotnet /usr/bin/dotnet
RUN wget https://dot.net/v1/dotnet-install.sh \
&& chmod +x ./dotnet-install.sh \
&& ./dotnet-install.sh \
--channel 8.0 \
--install-dir /usr/share/dotnet
WORKDIR /source
ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=true
COPY . .
RUN dotnet publish -r linux-musl-x64 -o /app
FROM scratch as export
COPY --from=build /app /
Exceptions (if any)
#0 137.7 cstest -> /source/bin/Release/net8.0/linux-musl-x64/cstest.dll
#0 137.9 Generating native code
#0 138.2 EXEC : error : Only the invariant culture is supported in globalization-invariant mode. See https://aka.ms/GlobalizationInvariantMode for more information. (Parameter 'name') [/source/cstest.csproj]
#0 138.2 zh-Hant is an invalid culture identifier.
#0 138.2 System.Globalization.CultureNotFoundException: Only the invariant culture is supported in globalization-invariant mode. See https://aka.ms/GlobalizationInvariantMode for more information. (Parameter 'name')
#0 138.2 zh-Hant is an invalid culture identifier.
#0 138.2 at System.Reflection.AssemblyName.set_CultureName(String) + 0xad
#0 138.2 at Internal.TypeSystem.Ecma.EcmaAssembly.GetName() + 0x32d
#0 138.2 at ILCompiler.UsageBasedMetadataManager.<GetSatelliteAssemblies>d__25.MoveNext() + 0x44
#0 138.2 at ILCompiler.DependencyAnalysis.ModuleMetadataNode.GetStaticDependencies(NodeFactory) + 0x1e8
#0 138.2 at ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer`2.GetStaticDependenciesImpl(DependencyNodeCore`1) + 0x35
#0 138.2 at ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer`2.GetStaticDependencies(DependencyNodeCore`1) + 0x33
#0 138.2 at ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer`2.ProcessMarkStack() + 0xb1
#0 138.2 at ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer`2.ComputeMarkedNodes() + 0x4f
#0 138.2 at ILCompiler.ILScanner.ILCompiler.IILScanner.Scan() + 0x19
#0 138.2 at ILCompiler.Program.<Run>g__RunScanner|4_0(Program.<>c__DisplayClass4_0&) + 0x1a9
#0 138.2 at ILCompiler.Program.Run() + 0x206e
#0 138.2 at ILCompiler.ILCompilerRootCommand.<>c__DisplayClass215_0.<.ctor>b__0(InvocationContext context) + 0x2f3
#0 138.2 /root/.nuget/packages/microsoft.dotnet.ilcompiler/8.0.0-preview.6.23329.7/build/Microsoft.NETCore.Native.targets(290,5): error MSB3073: The command ""/root/.nuget/packages/runtime.linux-musl-x64.microsoft.dotnet.ilcompiler/8.0.0-preview.6.23329.7/tools/ilc" @"obj/Release/net8.0/linux-musl-x64/native/cstest.ilc.rsp"" exited with code 1. [/source/cstest.csproj]
Further technical details
This happens on
- .NET 8 Preview 6 only, not on Preview 5 or lower.
Alpine Linux only, not on other distros like UbuntuLinux only, not on Windows or Mac- native AOT builds only, not on regular builds