C
C#7mo 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
Buddy7mo ago
NativeAOT prevents reflection from being used.
reflectronic
reflectronic7mo 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
CrosRoad957mo 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
More Posts
ADO YAML - output variables troubleshootHi, I have pipeline, which compiles my app and publishes artifacts to azure, then I want to drop the✅ I want to work on the ongoing ASP.NET project as free or minimum salary.Hi, Nice to meet you everyone. As a experienced Web and Blockchian developer, now I am trying to lea✅ embed images in outputhi, I'm looking for a way to embed an image in the output in such a way that it's data is readable. Making an interpreter read custom filename extensionsI made an interpreter in Visual Studio (C#) for my own language. My question is, how do I make it soASP.NET Core 8 Web API, can't use additional fields with Identity registrationHello, It's my first time using Identity, so I came across some issues. When I input json data neceusing serilog (c#) in a vb.netHello, I have an old application which is written in vb.net. I'm searching for a sollution to use s✅ Why is a variable false in project in WPF .Net application even after it should be true?Hi I'm currently building my first C# project and could really need some help, I'm supposed to take i need help because i dont why this is nullif u need smt (sql or smt ab my visual code lmk please)Is there a way to ensure a function can't modify a parameter?I often want to pass objects or values into a function, and make sure the function cannot change it.why is my handler not working, also the breakpoint doesn't even get hit for it[ValidateAntiForgeryToken] public IActionResult OnPostPlaceOrder() { try