dotnet / runtimelab

This repo is for experimentation and exploring new ideas that may or may not make it into the main dotnet/runtime repo.
MIT License
1.43k stars 200 forks source link

[NativeAOT] .NET 7.0 failed to compile : Failed to load type 'System.Text.Json.Serialization.Metadata.IJsonTypeInfoResolver' from assembly 'System.Text.Json, #2030

Closed lozn00 closed 2 years ago

lozn00 commented 2 years ago

rd.xml does not define JSON-related content, how to write content to ignore this problem? web core api


.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\7.0.0-alpha.1.21423.2\framework\System.ComponentModel.TypeConverter.dll(0,0): 警告 IL9702: Assembly 'System.ComponentModel.TypeConverter' produced AOT analysis warnings.
EXEC(0,0): 错误 : Failed to load type 'System.Text.Json.Serialization.Metadata.IJsonTypeInfoResolver' from assembly 'System.Text.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
Internal.TypeSystem.TypeSystemException+TypeLoadException: Failed to load type 'System.Text.Json.Serialization.Metadata.IJsonTypeInfoResolver' from assembly 'System.Text.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
   at Internal.TypeSystem.ThrowHelper.ThrowTypeLoadException(ExceptionStringID id, String typeName, String assemblyName)
   at Internal.TypeSystem.ResolutionFailure.Throw()
   at Internal.TypeSystem.Ecma.EcmaModule.GetType(EntityHandle handle)
   at Internal.TypeSystem.Ecma.EcmaType.InitializeImplementedInterfaces()
   at ILCompiler.Metadata.Transform`1.InitializeTypeDef(MetadataType entity, TypeDefinition record)
   at ILCompiler.Metadata.Transform`1.HandleType(TypeDesc type)
   at ILCompiler.Metadata.MetadataTransform.Run[TPolicy](TPolicy policy, IEnumerable`1 modules)
   at ILCompiler.GeneratingMetadataManager.ComputeMetadata[TPolicy](TPolicy policy, NodeFactory factory, Byte[]& metadataBlob, List`1& typeMappings, List`1& methodMappings, List`1& fieldMappings, List`1& stackTraceMapping)
   at ILCompiler.UsageBasedMetadataManager.ComputeMetadata(NodeFactory factory, Byte[]& metadataBlob, List`1& typeMappings, List`1& methodMappings, List`1& fieldMappings, List`1& stackTraceMapping)
   at ILCompiler.DependencyAnalysis.MetadataNode.GetData(NodeFactory factory, Boolean relocsOnly)
   at ILCompiler.DependencyAnalysis.ObjectWriter.EmitObject(String objectFilePath, IEnumerable`1 nodes, NodeFactory factory, ObjectWritingOptions options, IObjectDumper dumper)
   at ILCompiler.RyuJitCompilation.CompileInternal(String outputFile, ObjectDumper dumper)
   at ILCompiler.Compilation.ILCompiler.ICompilation.Compile(String outputFile, ObjectDumper dumper)
   at ILCompiler.Program.Run(String[] args)
   at ILCompiler.Program.Main(String[] args)
C:\Users\惠普\.nuget\packages\microsoft.dotnet.ilcompiler\7.0.0-alpha.1.21423.2\build\Microsoft.NETCore.Native.targets(283,5): 错误 MSB3073: 命令“"C:\Users\惠普\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\7.0.0-alpha.1.21423.2\tools\ilc" @"obj\x64\AL_DEBUG\net7.0\win-x64\native\webapi_mes.ilc.rsp"”已退出,代码为 1。
jkotas commented 2 years ago

This exception is caused by using new SDK with old builds of native aot.

The best way to solve this problem is to use .NET 7 SDK RC1 or newer, set PublishAot property in the project file to true, and let the SDK download the matching version of the aot package for you. It is no longer necessary to manually reference the aot package with .NET 7 SDKs.

lozn00 commented 2 years ago

thank you , May I ask whether the latest version of.NET will solve some problems better?

@jkotas I'm now back down to.net6 and use 7.0.0-alpha.1.21423.2 <PackageReference Include="Microsoft.DotNet.ILCompiler;" Version="7.0.0-alpha.1.21423.2" />

jkotas commented 2 years ago

Yes, .NET 7 solves this problem. Check out the documentation we have for .NET 7: https://learn.microsoft.com/en-us/dotnet/core/deploying/native-aot/ . It just tells you to set the PublishAot property and that's it. You do not need it worry about having the right package versions at all.