Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem after publishing as NativeAOT #4267

Closed
CodeFanaticX opened this issue Sep 9, 2023 · 6 comments · Fixed by #4291
Closed

Problem after publishing as NativeAOT #4267

CodeFanaticX opened this issue Sep 9, 2023 · 6 comments · Fixed by #4291
Assignees
Labels
area: AOT status: has-pr There is active PR for issue type: bug
Milestone

Comments

@CodeFanaticX
Copy link

CodeFanaticX commented Sep 9, 2023

Describe your issue

If you have a question, first try to check our documentation, especially FAQ and search in issues and discussions - maybe your question already answered there.

If you still have questions or want to start general discussion, please create new topic in discussions.

If you are seeing an exception, include the full exceptions details (message and stack trace).

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.TypeInitializationException: A type initializer threw an exception. To determine which type, inspect the InnerException's StackTrace property.
 ---> System.NotSupportedException: Specified method is not supported.
   at Internal.Reflection.Execution.ExecutionEnvironmentImplementation.GetInterfaceMap(Type instanceType, Type interfaceType, MethodInfo[]& interfaceMethods, MethodInfo[]& targetMethods) + 0x2df
   at System.Reflection.Runtime.TypeInfos.RuntimeTypeInfo.GetInterfaceMap(Type interfaceType) + 0xd3
   at LinqToDB.Reflection.TypeAccessor`1..cctor() + 0x389
   at System.Runtime.CompilerServices.ClassConstructorRunner.EnsureClassConstructorRun(StaticClassConstructionContext* pContext) + 0xc2
   --- End of inner exception stack trace ---
   at System.Runtime.CompilerServices.ClassConstructorRunner.EnsureClassConstructorRun(StaticClassConstructionContext* pContext) + 0x14a
   at System.Runtime.CompilerServices.ClassConstructorRunner.CheckStaticClassConstructionReturnNonGCStaticBase(StaticClassConstructionContext* context, IntPtr nonGcStaticBase) + 0xd
   at LinqToDB.Reflection.TypeAccessor`1..ctor() + 0x1e
   at KeyVaultTest!<BaseAddress>+0xda59e4
   at System.Reflection.DynamicInvokeInfo.Invoke(Object thisPtr, IntPtr methodToCall, Object[] parameters, BinderBundle binderBundle, Boolean wrapInTargetInvocationException) + 0xb3
   --- End of inner exception stack trace ---
   at System.Reflection.DynamicInvokeInfo.Invoke(Object thisPtr, IntPtr methodToCall, Object[] parameters, BinderBundle binderBundle, Boolean wrapInTargetInvocationException) + 0x1d6
   at Internal.Reflection.Execution.MethodInvokers.InstanceMethodInvoker.CreateInstance(Object[] arguments, BinderBundle binderBundle, Boolean wrapInTargetInvocationException) + 0x44
   at Internal.Reflection.Core.Execution.MethodBaseInvoker.CreateInstance(Object[] arguments, Binder binder, BindingFlags invokeAttr, CultureInfo cultureInfo) + 0x3b
   at System.Reflection.Runtime.MethodInfos.RuntimePlainConstructorInfo`1.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) + 0x55
   at System.ActivatorImplementation.CreateInstance(Type, Boolean) + 0xd3
   at LinqToDB.Reflection.TypeAccessor.GetAccessor(Type type) + 0xb1
   at LinqToDB.Mapping.EntityDescriptor..ctor(MappingSchema mappingSchema, Type type, Action`2 onEntityDescriptorCreated) + 0xc4
   at LinqToDB.Mapping.MappingSchema.<>c.<GetEntityDescriptor>b__98_0(ICacheEntry`2 o, ValueTuple`2 context) + 0x76
   at LinqToDB.Common.Internal.Cache.CacheExtensions.GetOrCreate[TItem, TKey, TContext](IMemoryCache`2 cache, TKey key, TContext context, Func`3 factory) + 0x6b
   at LinqToDB.Mapping.MappingSchema.GetEntityDescriptor(Type type, Action`2 onEntityDescriptorCreated) + 0xcc
   at LinqToDB.Linq.Table`1.InitTable(IDataContext dataContext, Expression expression, EntityDescriptor tableDescriptor) + 0x59
   at LinqToDB.DataExtensions.GetTable[T](IDataContext dataContext) + 0x29
   at DatabaseConnection.<GetDataAsync>d__5.MoveNext() + 0x57

Steps to reproduce

I'm trying to add it to rd.xml but I don't know how to fix it or am I missing something?

<Assembly Name="linq2db">
            <Type Name="LinqToDB.DataExtensions" Dynamic="Required All" >
            </Type>

            <Type Name="LinqToDB.Data.DataParameter" Dynamic="Required All" />
        </Assembly>
<code with error and mapping classes>

Environment details

Linq To DB version: ? latest

Database (with version): ? (e.g. SQL Server 2019)

ADO.NET Provider (with version): ? (e.g. Microsoft.Data.SqlClient 4.1.0)

Operating system: ?

.NET Version: ?

@MaceWindu
Copy link
Contributor

Looks like duplicate of #2680
I suspect Microsoft still didn't implemented this method so we should expand fix surface to .net runtimes...

@MaceWindu MaceWindu self-assigned this Oct 8, 2023
@MaceWindu MaceWindu added this to the 5.3.0 milestone Oct 8, 2023
@MaceWindu
Copy link
Contributor

I suspect it could be related to dotnet/runtime#89157

@MaceWindu MaceWindu modified the milestones: 5.3.0, 5.4.0, 6.0.0 Oct 8, 2023
@MaceWindu
Copy link
Contributor

We should look into adding nativeaot build testing.

@MaceWindu
Copy link
Contributor

We will release temporary workaround which hopefully help with this issue #4291
Note that because GetIterfaceMap method is not available you cannot use interfaces in your mappings (you can, but it could work incorrectly)

@MaceWindu
Copy link
Contributor

Actually I found that it fails only for interfaces with new features like default members/statics. That's runtime issue, but it is not critical if user don't use such features in mapped interfaces. I will implement fix, which will ignore such interfaces

@MaceWindu MaceWindu modified the milestones: 6.0.0, 5.3.0 Oct 9, 2023
@MaceWindu MaceWindu added the status: has-pr There is active PR for issue label Oct 9, 2023
@MaceWindu
Copy link
Contributor

Could you please check preview version from here https://dev.azure.com/linq2db/linq2db/_artifacts/feed/linq2db/NuGet/linq2db/overview for any other aot issues so we can include fixes for them into upcoming release on thursday?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: AOT status: has-pr There is active PR for issue type: bug
Development

Successfully merging a pull request may close this issue.

2 participants