Skip to content

.NET 8 Native AOT Compatibility #608

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

Open
conormcg94 opened this issue May 7, 2025 · 0 comments
Open

.NET 8 Native AOT Compatibility #608

conormcg94 opened this issue May 7, 2025 · 0 comments

Comments

@conormcg94
Copy link

I haven't been to get LightInject to run with .NET 8 native AOT. Previously there was AOT compatibility with PCL #81 #305 #318

The Reflection.Emit methods throw a System.PlatformNotSupportedException. Toggling USE_EXPRESSIONS in the source throws IndexOutOfRange in MapGenericArguments

Expression Trees Stacktrace:

   at LightInject.GenericArgumentMapper.MapGenericArguments(Type[] serviceTypeGenericArguments, Type[] baseTypeGenericArguments, IDictionary`2 map)
   at LightInject.GenericArgumentMapper.MapGenericArguments(Type[] serviceTypeGenericArguments, Type[] baseTypeGenericArguments, IDictionary`2 map) 
   at LightInject.GenericArgumentMapper.CreateMap(Type genericServiceType, Type openGenericImplementingType, String[] genericParameterNames)
   at LightInject.GenericArgumentMapper.Map(Type genericServiceType, Type openGenericImplementingType)
   at LightInject.ServiceContainer.EnsureConstructable(Type serviceType, Type implementingType)
   at LightInject.ServiceContainer.RegisterService(Type serviceType, Type implementingType, ILifetime lifetime, String serviceName)
   at LightInject.ServiceContainer.Register(Type serviceType, Type implementingType, String serviceName, ILifetime lifetime) 
   at LightInject.AssemblyScanner.RegisterInternal(Type serviceType, Type implementingType, IServiceRegistry serviceRegistry, ILifetime lifetime, Func`3 serviceNameProvider)
   at LightInject.AssemblyScanner.BuildImplementationMap(Type implementingType, IServiceRegistry serviceRegistry, Func`1 lifetimeFactory, Func`3 shouldRegister, Func`3 serviceNameProvider)
   at LightInject.AssemblyScanner.Scan(Assembly assembly, IServiceRegistry serviceRegistry, Func`1 lifetimeFactory, Func`3 shouldRegister, Func`3 serviceNameProvider)
   at LightInject.ServiceContainer.RegisterAssembly(Assembly assembly, Func`1 lifetimeFactory, Func`3 shouldRegister, Func`3 serviceNameProvider)
   at LightInject.ServiceContainer.RegisterAssembly(Assembly assembly, Func`1 lifetimeFactory, Func`3 shouldRegister) 
   at LightInject.ServiceContainer.RegisterAssembly(Assembly assembly, Func`3 shouldRegister)
   at LightInject.ServiceContainer.RegisterAssembly(Assembly assembly)

Reflection.Emit Stacktrace:

    at System.Reflection.Emit.AssemblyBuilder.ThrowDynamicCodeNotSupported()
   at System.Reflection.Emit.AssemblyBuilder.EnsureDynamicCodeSupported()
   at System.Reflection.Emit.DynamicMethod.Init(String name, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] signature, Type owner, Module m, Boolean skipVisibility, Boolean transparentMethod)
   at System.Reflection.Emit.DynamicMethod..ctor(String name, Type returnType, Type[] parameterTypes, Module m, Boolean skipVisibility)
   at LightInject.ServiceContainer.DynamicMethodSkeleton.CreateDynamicMethod(Type returnType, Type[] parameterTypes)
   at LightInject.ServiceContainer.DynamicMethodSkeleton..ctor(Type returnType, Type[] parameterTypes)
   at LightInject.ServiceContainer.<>c.<.ctor>b__29_1(Type returnType, Type[] parameterTypes)
   at LightInject.ServiceContainer.CreateDynamicMethodDelegate(Action`1 serviceEmitter)
   at LightInject.ServiceContainer.CreateDelegate(Type serviceType, String serviceName, Boolean throwError)
   at LightInject.ServiceContainer.CreateDefaultDelegate(Type serviceType, Boolean throwError)
   at LightInject.ServiceContainer.GetInstance(Type serviceType)
   at LightInject.ServiceFactoryExtensions.GetInstance[TService](IServiceFactory
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant