dotnet / corert

This repo contains CoreRT, an experimental .NET Core runtime optimized for AOT (ahead of time compilation) scenarios, with the accompanying compiler toolchain.
http://dot.net
MIT License
2.91k stars 511 forks source link

Internal.TypeSystem.TypeSystemException+TypeLoadException when using EntityFrameworkCore with Npgsql #7506

Open eyupkayadarcin opened 5 years ago

eyupkayadarcin commented 5 years ago

I've got a dotnet core 2.1 project . I'm getting a Internal.TypeSystem.TypeSystemException+TypeLoadException after compilation (using dotnet publish -r win-x64 -c release):

Internal.TypeSystem.TypeSystemException+TypeLoadException: [TEMPORARY EXCEPTION MESSAGE] ClassLoadGeneral: Microsoft.EntityFrameworkCore.Storage.Internal.NpgsqlArrayTypeMapping, Npgsql.EntityFrameworkCore.PostgreSQL, Version=2.1.2.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7 at Internal.TypeSystem.ThrowHelper.ThrowTypeLoadException(ExceptionStringID id, String typeName, String assemblyName) at Internal.TypeSystem.Ecma.EcmaModule.GetType(String nameSpace, String name, Boolean throwIfNotFound) at Internal.TypeSystem.Ecma.EcmaModule.ResolveTypeReference(TypeReferenceHandle handle) at Internal.TypeSystem.Ecma.EcmaModule.EcmaObjectLookupHashtable.CreateValueFromKey(EntityHandle handle) at Internal.TypeSystem.LockFreeReaderHashtable2.CreateValueAndEnsureValueIsInTable(TKey key) at Internal.TypeSystem.Ecma.EcmaModule.GetObject(EntityHandle handle) at Internal.TypeSystem.Ecma.EcmaModule.GetType(EntityHandle handle) at Internal.TypeSystem.Ecma.EcmaSignatureParser.ParseType(SignatureTypeCode typeCode) at Internal.TypeSystem.Ecma.EcmaSignatureParser.ParseMethodSignature() at Internal.TypeSystem.Ecma.EcmaMethod.InitializeSignature() at ILCompiler.DependencyAnalysis.MethodMetadataNode.GetStaticDependencies(NodeFactory factory) at ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer2.GetStaticDependenciesImpl(DependencyNodeCore1 node) at ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer2.ProcessMarkStack() at ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer`2.ComputeMarkedNodes() 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)

And there is any method that create automatically rd.xml file ?

MichalStrehovsky commented 5 years ago

It looks like you might have some mismatched references and it trips up the compiler in a spot where it cannot handle that.

Can you try adding <IlcGenerateCompleteTypeMetadata>false</IlcGenerateCompleteTypeMetadata> to a PropertyGroup in your csproj to see if this problem goes away?

eyupkayadarcin commented 5 years ago

I have added <IlcGenerateCompleteTypeMetadata>false</IlcGenerateCompleteTypeMetadata> and getting a Internal.TypeSystem.TypeSystemException+TypeLoadException: [TEMPORARY EXCEPTION MESSAGE] ClassLoadGeneral: Microsoft.EntityFrameworkCore.Metadata.RelationalSequenceBuilder, Microsoft.EntityFrameworkCore.Relational again. My rd.xml file looks like this :

`

`

MichalStrehovsky commented 5 years ago

getting a Internal.TypeSystem.TypeSystemException+TypeLoadException: [TEMPORARY EXCEPTION MESSAGE] ClassLoadGeneral: Microsoft.EntityFrameworkCore.Metadata.RelationalSequenceBuilder, Microsoft.EntityFrameworkCore.Relational again

Is the exception stack the same?

eyupkayadarcin commented 5 years ago

Internal.TypeSystem.TypeSystemException+TypeLoadException: [TEMPORARY EXCEPTION MESSAGE] ClassLoadGeneral: Microsoft.EntityFrameworkCore.Metadata.RelationalSequenceBuilder, Microsoft.EntityFrameworkCore.Relational, Version=2.1.4.0, Culture=neutral, PublicKeyToken=adb9793829ddae60 at Internal.TypeSystem.ThrowHelper.ThrowTypeLoadException(ExceptionStringID id, String typeName, String assemblyName) at Internal.TypeSystem.Ecma.EcmaModule.GetType(String nameSpace, String name, Boolean throwIfNotFound) at Internal.TypeSystem.Ecma.EcmaModule.ResolveTypeReference(TypeReferenceHandle handle) at Internal.TypeSystem.Ecma.EcmaModule.EcmaObjectLookupHashtable.CreateValueFromKey(EntityHandle handle) at Internal.TypeSystem.LockFreeReaderHashtable2.CreateValueAndEnsureValueIsInTable(TKey key) at Internal.TypeSystem.Ecma.EcmaModule.GetObject(EntityHandle handle) at Internal.TypeSystem.Ecma.EcmaModule.GetType(EntityHandle handle) at Internal.TypeSystem.Ecma.EcmaSignatureParser.ParseType(SignatureTypeCode typeCode) at Internal.TypeSystem.Ecma.EcmaSignatureParser.ParseMethodSignature() at Internal.TypeSystem.Ecma.EcmaMethod.InitializeSignature() at Internal.TypeSystem.MetadataVirtualMethodAlgorithm.FindMatchingVirtualMethodOnTypeByNameAndSig(MethodDesc targetMethod, DefType currentType, Boolean reverseMethodSearch, Func3 nameSigMatchMethodIsValidCandidate) at Internal.TypeSystem.MetadataVirtualMethodAlgorithm.FindBaseUnificationGroup(MetadataType currentType, UnificationGroup unificationGroup) at Internal.TypeSystem.MetadataVirtualMethodAlgorithm.FindVirtualFunctionTargetMethodOnObjectType(MethodDesc targetMethod, MetadataType objectType) at ILCompiler.DependencyAnalysis.EETypeNode.GetConditionalStaticDependencies(NodeFactory factory)+MoveNext() at ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer2.GetStaticDependenciesImpl(DependencyNodeCore1 node) at ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer2.ProcessMarkStack() at ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer2.ComputeMarkedNodes() at ILCompiler.ILScanner.ILCompiler.IILScanner.Scan() at ILCompiler.Program.Run(String[] args) at ILCompiler.Program.Main(String[] args) like this.

MichalStrehovsky commented 5 years ago

It's possible the RD.XML is adding things to the compilation graph that don't resolve.

This really looks like the input libraries have mismatched versions. The compiler shouldn't crash, but I don't expect the app to work right even if the compiler doesn't crash. I would try fixing the references in the first place. Not sure how NuGet gets into this situation (I assume this is from NuGet).

eyupkayadarcin commented 5 years ago

How can i create automatically rd.xml file ? and Are you suggesting I check the references first? Becasue there is a n-tier app

MichalStrehovsky commented 5 years ago

How can i create automatically rd.xml file

rd.xml cannot be created automatically. Rd.xml tells the compiler what parts of your program should be made available to reflection. It's a hard problem to solve automatically.

The error message is saying that the type Microsoft.EntityFrameworkCore.Metadata.RelationalSequenceBuilder doesn't exist in the Microsoft.EntityFrameworkCore.Relational assembly, even though some assembly is referencing it.

Microsoft.EntityFrameworkCore.Relational is out of sync with some other assembly that references the type.

eyupkayadarcin commented 5 years ago

hey @MichalStrehovsky .

C:\Users\HP\.nuget\packages\microsoft.dotnet.ilcompiler\1.0.0-alpha-27811-01\build\Microsoft.NETCore.Native.targets(248,5): error MSB3073: The command ""C:\Users\HP\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\1.0.0-alpha-27811-01\tools\ilc" @"obj\Release\netcoreapp2.1\win-x64\native\Comments.ServerlessWidgetApi.ilc.rsp"" exited with code -1073741571. What is mean of this ?

MichalStrehovsky commented 5 years ago

-1073741571 is 0xC00000FD. Stack overflow.

Npgsql has patterns that are unfriendly to AOT compilation and require a feature we don't have (tracked in #363).

Here is an explanation of what's likely happening: https://github.com/dotnet/corert/issues/6052#issuecomment-402530745

eyupkayadarcin commented 5 years ago

Hey Michal,

How can i handle "System.Exception" ? EXEC : error : Exception of type 'System.Exception' was thrown. [C:\Users\HP\Desktop\yedek\Comments.ServerlessWidgetApi\Comments.ServerlessWidgetApi.csproj] System.Exception: Exception of type 'System.Exception' was thrown. at ILCompiler.RdXmlRootProvider.ProcessMethodDirective(IRootingServiceProvider rootProvider, ModuleDesc containingModule, TypeDesc containingType, XElement methodElement) at ILCompiler.RdXmlRootProvider.ProcessTypeDirective(IRootingServiceProvider rootProvider, ModuleDesc containingModule, XElement typeElement) at ILCompiler.RdXmlRootProvider.ProcessAssemblyDirective(IRootingServiceProvider rootProvider, XElement assemblyElement) at ILCompiler.RdXmlRootProvider.AddCompilationRoots(IRootingServiceProvider rootProvider) at ILCompiler.Compilation..ctor(DependencyAnalyzerBase1 dependencyGraph, NodeFactory nodeFactory, IEnumerable1 compilationRoots, ILProvider ilProvider, DebugInformationProvider debugInformationProvider, DevirtualizationManager devirtualizationManager, PInvokeILEmitterConfiguration pInvokeConfiguration, Logger logger) at ILCompiler.ILScannerBuilder.ToILScanner() at ILCompiler.Program.Run(String[] args) at ILCompiler.Program.Main(String[] args) C:\Users\HP\.nuget\packages\microsoft.dotnet.ilcompiler\1.0.0-alpha-27811-02\build\Microsoft.NETCore.Native.targets(248,5): error MSB3073: The command ""C:\Users\HP\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\1.0.0-alpha-27811-02\tools\ilc" @"obj\Release\netcoreapp2.1\win-x64\native\Comments.ServerlessWidgetApi.ilc.rsp"" exited with code 1. [C:\Users\HP\Desktop\yedek\Comments.ServerlessWidgetApi\Comments.ServerlessWidgetApi.csproj]

MichalStrehovsky commented 5 years ago

This is getting thrown from RdXmlRootProvider.ProcessMethodDirective so something is wrong with your RD.XML. Looking at all the places where we throw should give you and idea:

https://github.com/dotnet/corert/blob/5af8c5664104f1fe098439e1488a0923c4f76a6d/src/ILCompiler/src/RdXmlRootProvider.cs#L122-L151

We didn't try to make RD.XML parser friendly because it's temporary (#5001).

eyupkayadarcin commented 5 years ago

Hey Michal,

I use Ubuntu 19.04. I get a error when i try to install "clang-3.9".

`Some packages could not be installed. This may mean that you have requested an impossible situation or if you are using the unstable distribution that some required packages have not yet been created or been moved out of Incoming. The following information may help to resolve the situation:

The following packages have unmet dependencies: clang-3.9 : Depends: libstdc++-5-dev but it is not installable Depends: libgcc-5-dev but it is not installable Depends: libobjc-5-dev but it is not installable Recommends: llvm-3.9-dev but it is not going to be installed E: Unable to correct problems, you have held broken packages.`

What is mean of that ?

jkotas commented 5 years ago

You can set CppCompilerAndLinker either in your environment or in .csproj file to workaround this.

https://github.com/dotnet/corert/blob/master/Documentation/prerequisites-for-building.md#clang-39-not-found-on-linux

testusercomments commented 5 years ago

Hello guys,

Sorry for bothering EXEC : error : Exception of type 'System.Exception' was thrown. [C:\Users\HP\Desktop\yedek\Comments.ServerlessWidgetApi\Comments.ServerlessWidgetApi.csproj] System.Exception: Exception of type 'System.Exception' was thrown. at ILCompiler.RdXmlRootProvider.ProcessMethodDirective(IRootingServiceProvider rootProvider, ModuleDesc containingModule, TypeDesc containingType, XElement methodElement) at ILCompiler.RdXmlRootProvider.ProcessTypeDirective(IRootingServiceProvider rootProvider, ModuleDesc containingModule, XElement typeElement) at ILCompiler.RdXmlRootProvider.ProcessAssemblyDirective(IRootingServiceProvider rootProvider, XElement assemblyElement) at ILCompiler.RdXmlRootProvider.AddCompilationRoots(IRootingServiceProvider rootProvider) at ILCompiler.Compilation..ctor(DependencyAnalyzerBase1 dependencyGraph, NodeFactory nodeFactory, IEnumerable1 compilationRoots, ILProvider ilProvider, DebugInformationProvider debugInformationProvider, DevirtualizationManager devirtualizationManager, PInvokeILEmitterConfiguration pInvokeConfiguration, Logger logger) at ILCompiler.ILScannerBuilder.ToILScanner() at ILCompiler.Program.Run(String[] args) at ILCompiler.Program.Main(String[] args) C:\Users\HP\.nuget\packages\microsoft.dotnet.ilcompiler\1.0.0-alpha-27815-01\build\Microsoft.NETCore.Native.targets(248,5): error MSB3073: The command ""C:\Users\HP\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\1.0.0-alpha-27815-01\tools\ilc" @"obj\Release\netcoreapp2.1\win-x64\native\Comments.ServerlessWidgetApi.ilc.rsp"" exited with code 1. [C:\Users\HP\Desktop\yedek\Comments.ServerlessWidgetApi\Comments.ServerlessWidgetApi.csproj] I get exception. what is mean of that ? Thank you

MichalStrehovsky commented 5 years ago

@testusercomments Since this is the exact same stack trace (including user name) as above, the answer is the same: https://github.com/dotnet/corert/issues/7506#issuecomment-501154956