C
C#13mo ago
CrosRoad95

ActivatorUtilities.CreateInstance replacment for native AOT

as in title, how can i replace ActivatorUtilities.CreateInstance function? right now it complain that:
Error in startup A suitable constructor for type '<type>' could not be located. Ensure the type is concrete and all parameters of a public constructor are either registered as services or passed as arguments. Also ensure no extraneous arguments are provided.
Error in startup A suitable constructor for type '<type>' could not be located. Ensure the type is concrete and all parameters of a public constructor are either registered as services or passed as arguments. Also ensure no extraneous arguments are provided.
3 Replies
Buddy
Buddy13mo ago
NativeAOT prevents reflection from being used.
reflectronic
reflectronic12mo ago
this is not true to be clear, ActivatorUtilities.CreateInstance, and most of dependency injection in general, should be fully functional in NativeAOT you need to be using .NET 8 (and 8.0 versions of MS.Extensions libraries) though and you need to ensure you don't have other AOT or trimming warnings at build time which could be contributing to this
CrosRoad95
CrosRoad95OP12mo ago
let me check
Error in startup A suitable constructor for type '<Type>' could not be located. Ensure the type is concrete and all parameters of a public constructor are either registered as services or passed as arguments. Also ensure no extraneous arguments are provided.
at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.CreateInstance(IServiceProvider, Type, Object[]) + 0x2a1
at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.CreateInstance[T](IServiceProvider, Object[]) + 0x2b
Error in startup A suitable constructor for type '<Type>' could not be located. Ensure the type is concrete and all parameters of a public constructor are either registered as services or passed as arguments. Also ensure no extraneous arguments are provided.
at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.CreateInstance(IServiceProvider, Type, Object[]) + 0x2a1
at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.CreateInstance[T](IServiceProvider, Object[]) + 0x2b
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" /> updated to 8.0.0, also project is .net8
Want results from more Discord servers?
Add your server