Home > Software design >  PublishReadyToRun issue with .Net6 WPF application
PublishReadyToRun issue with .Net6 WPF application

Time:05-03

I'm facing an issue with the use of PublishReadyToRun in a .Net6 WPF application.

I use this command to publish :

dotnet publish sources/xxx.csproj --configuration Release --framework net6.0-windows --runtime win-x64 --output output/release64/net6.0-windows/publish -p:PublishReadyToRun=true --self-contained

here are the error :

C:\Program Files\dotnet\sdk\6.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(463,5): error : Error: Read out of bounds. [C:\xxx.csproj]
C:\Program Files\dotnet\sdk\6.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(463,5): error : System.BadImageFormatException: Read out of bounds. [C:\xxx.csproj]
C:\Program Files\dotnet\sdk\6.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(463,5): error :    at System.Reflection.Throw.OutOfBounds() [C:\xxx.csproj]
C:\Program Files\dotnet\sdk\6.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(463,5): error :    at System.Reflection.Metadata.Ecma335.TypeRefTableReader.GetResolutionScope(TypeReferenceHandle handle) [C:\xxx.csproj]
C:\Program Files\dotnet\sdk\6.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(463,5): error :    at System.Reflection.Metadata.TypeReference.get_ResolutionScope() [C:\xxx.csproj]
C:\Program Files\dotnet\sdk\6.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(463,5): error :    at Internal.TypeSystem.Ecma.EcmaModule.ResolveTypeReference(TypeReferenceHandle handle) [C:\xxx.csproj]
C:\Program Files\dotnet\sdk\6.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(463,5): error :    at Internal.TypeSystem.Ecma.EcmaModule.EcmaObjectLookupHashtable.CreateValueFromKey(EntityHandle handle) [C:\xxx.csproj]
C:\Program Files\dotnet\sdk\6.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(463,5): error :    at Internal.TypeSystem.LockFreeReaderHashtable`2.CreateValueAndEnsureValueIsInTable(TKey key) [C:\xxx.csproj]
C:\Program Files\dotnet\sdk\6.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(463,5): error :    at Internal.TypeSystem.Ecma.EcmaModule.GetObject(EntityHandle handle, NotFoundBehavior notFoundBehavior) [C:\xxx.csproj]
C:\Program Files\dotnet\sdk\6.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(463,5): error :    at Internal.TypeSystem.Ecma.EcmaModule.ResolveTypeReference(TypeReferenceHandle handle) [C:\xxx.csproj]
C:\Program Files\dotnet\sdk\6.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(463,5): error :    at Internal.TypeSystem.Ecma.EcmaModule.EcmaObjectLookupHashtable.CreateValueFromKey(EntityHandle handle) [C:\xxx.csproj]
C:\Program Files\dotnet\sdk\6.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(463,5): error :    at Internal.TypeSystem.LockFreeReaderHashtable`2.CreateValueAndEnsureValueIsInTable(TKey key) [C:\xxx.csproj]
C:\Program Files\dotnet\sdk\6.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(463,5): error :    at Internal.TypeSystem.Ecma.EcmaModule.GetObject(EntityHandle handle, NotFoundBehavior notFoundBehavior) [C:\xxx.csproj]
C:\Program Files\dotnet\sdk\6.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(463,5): error :    at Internal.TypeSystem.Ecma.EcmaModule.GetType(EntityHandle handle) [C:\xxx.csproj]
C:\Program Files\dotnet\sdk\6.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(463,5): error :    at ILCompiler.ReadyToRunCompilationModuleGroupBase.TryGetModuleTokenForExternalType(TypeDesc type, ModuleToken& token) [C:\xxx.csproj]
C:\Program Files\dotnet\sdk\6.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(463,5): error :    at ILCompiler.DependencyAnalysis.ReadyToRun.ModuleTokenResolver.GetModuleTokenForType(EcmaType type, Boolean throwIfNotFound) [C:\xxx.csproj]
C:\Program Files\dotnet\sdk\6.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(463,5): error :    at ILCompiler.DependencyAnalysis.ReadyToRun.SignatureContext.GetTargetModule(TypeDesc type) [C:\xxx.csproj]
C:\Program Files\dotnet\sdk\6.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(463,5): error :    at ILCompiler.DependencyAnalysis.ReadyToRun.TypeFixupSignature.GetData(NodeFactory factory, Boolean relocsOnly) [C:\xxx.csproj]
C:\Program Files\dotnet\sdk\6.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(463,5): error :    at ILCompiler.DependencyAnalysis.ReadyToRun.ImportSectionNode.MaterializeSignature(NodeFactory r2rFactory) [C:\xxx.csproj]
C:\Program Files\dotnet\sdk\6.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(463,5): error :    at ILCompiler.DependencyAnalysis.ReadyToRun.ImportSectionsTableNode.MaterializeSignature() [C:\xxx.csproj]
C:\Program Files\dotnet\sdk\6.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(463,5): error :    at ILCompiler.DependencyAnalysis.ReadyToRun.ManifestMetadataTableNode.ComputeLastSetOfModuleIndices() [C:\xxx.csproj]
C:\Program Files\dotnet\sdk\6.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(463,5): error :    at ILCompiler.DependencyAnalysis.ReadyToRun.ManifestMetadataTableNode.GetManifestAssemblyMvidTableData() [C:\xxx.csproj]
C:\Program Files\dotnet\sdk\6.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(463,5): error :    at ILCompiler.DependencyAnalysis.ReadyToRun.ManifestAssemblyMvidHeaderNode.GetData(NodeFactory factory, Boolean relocsOnly) [C:\xxx.csproj]
C:\Program Files\dotnet\sdk\6.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(463,5): error :    at ILCompiler.DependencyAnalysis.ReadyToRunObjectWriter.EmitPortableExecutable() [C:\xxx.csproj]
C:\Program Files\dotnet\sdk\6.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(463,5): error :    at ILCompiler.ReadyToRunCodegenCompilation.Compile(String outputFile) [C:\xxx.csproj]
C:\Program Files\dotnet\sdk\6.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(463,5): error :    at ILCompiler.Program.RunSingleCompilation(Dictionary`2 inFilePaths, InstructionSetSupport instructionSetSupport, String compositeRootPath, Dictionary`2 unrootedInputFilePaths, HashSet`1 versionBubbleModulesHash, CompilerTypeSystemContext typeSystemContext) [C:\xxx.csproj]
C:\Program Files\dotnet\sdk\6.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(463,5): error :    at ILCompiler.Program.Run(String[] args) [C:\xxx.csproj]
C:\Program Files\dotnet\sdk\6.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(463,5): error :    at ILCompiler.Program.Main(String[] args) [C:\xxx.csproj]
C:\Program Files\dotnet\sdk\6.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(351,5): error NETSDK1096: Optimizing assemblies for performance failed. You can either exclude the failing assemblies from being optimized, or set the PublishReadyToRun property to false. [C:\xxx.csproj]

The Verbosity detailed don't give more details about the issue.

I tried to create a new net6 wpf project and using this one I have no issue.

My application has lots of assemblies and has native dependencies.

Is there a way to fix this ? Is there any known limitation about crossgen2 ?

CodePudding user response:

Finally, I found the solution in the detailed verbosity

It has an error in a crossgen2 launch in a dependency assembly.

I added an PublishReadyToRunExclude node in the csproj to resolve the issue :

<ItemGroup>
    <PublishReadyToRunExclude Include="xxx.dll;yyy.dll" />
</ItemGroup>
  • Related