Skip to content

Make it possible to use newer ILCompiler packages than what SDK comes with #26268

Closed
dotnet/runtime
#72346
@tomrus88

Description

@tomrus88

Describe the bug

Publishing app with NativeAOT results in broken binary.

To Reproduce

  • Create C# hello world console app and edit project file to be like this
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net7.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <PublishAot>true</PublishAot>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.DotNet.ILCompiler" Version="7.0.0-preview.6.22325.1" />
  </ItemGroup>

</Project>

Presence of both PublishAot and PackageReference to Microsoft.DotNet.ILCompiler is important.

  • Publish app (win-x64) and then run it
  • You will get exception like this
Unhandled Exception: System.InvalidOperationException: Operation is not valid due to the current state of the object.
   at Internal.Reflection.Core.Execution.ReflectionCoreExecution.InitializeExecutionDomain(ReflectionDomainSetup, ExecutionEnvironment) + 0x94
   at Internal.Reflection.Execution.ReflectionExecution.Initialize() + 0x35
   at ConsoleApp5!<BaseAddress>+0x1f0d6a

Further technical details

  • Tested with .NET 7 SDK Preview 5 and also .NET 7 SDK daily build
  • Here is why it doesn't work: build task that generates AppName.ilc.rsp file for ilc compiler adds duplicate --initassembly arguments
--initassembly:System.Private.CoreLib
--initassembly:System.Private.StackTraceMetadata
--initassembly:System.Private.TypeLoader
--initassembly:System.Private.Reflection.Execution
--initassembly:System.Private.CoreLib
--initassembly:System.Private.StackTraceMetadata
--initassembly:System.Private.TypeLoader
--initassembly:System.Private.Reflection.Execution

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

High Priority

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions