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

(Native AOT) No parameterless constructor defined for type #1146

Open
PaddiM8 opened this issue Nov 22, 2022 · 5 comments
Open

(Native AOT) No parameterless constructor defined for type #1146

PaddiM8 opened this issue Nov 22, 2022 · 5 comments

Comments

@PaddiM8
Copy link

PaddiM8 commented Nov 22, 2022

When compiling to native AOT, I get the following: Unhandled Exception: System.MissingMethodException: No parameterless constructor defined for type 'MyClass'.

   at System.ActivatorImplementation.CreateInstance(Type, Boolean) + 0x203
   at System.Reflection.Runtime.General.ReflectionCoreCallbacksImplementation.ActivatorCreateInstance(Type, Boolean) + 0x2b
   at System.Activator.CreateInstance(Type type, Boolean nonPublic) + 0x45
   at System.Activator.CreateInstance(Type type) + 0x1f
   at SQLite.SQLiteCommand.<ExecuteDeferredQuery>d__12`1.MoveNext() + 0x6e6
   at System.Collections.Generic.List`1..ctor(IEnumerable`1) + 0x1fb
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1) + 0x81
   at SQLite.SQLiteCommand.ExecuteQuery[T]() + 0xb0
   at SQLite.SQLiteConnection.Query[T](String, Object[]) + 0x59

I didn't do anything fancy, just created a table, so should be easy to reproduce.

@cricketthomas
Copy link

@PaddiM8 did you figure out a work around for this?

@PaddiM8
Copy link
Author

PaddiM8 commented Sep 18, 2023

Unfortunately not.

@cricketthomas
Copy link

I am going to be looking into Microsoft.Data.Sqlite as an alternative, maybe it can work for your situation: https://learn.microsoft.com/en-us/windows/apps/develop/data-access/sqlite-data-access

They've added AOT support:
https://devblogs.microsoft.com/dotnet/announcing-ef8-rc1/
dotnet/efcore#29725

@PaddiM8
Copy link
Author

PaddiM8 commented Sep 18, 2023

Ohh finally. That's what I've been using with Ready-to-Run. Thanks!

@jonasnordlund
Copy link

jonasnordlund commented Dec 14, 2023

This looks related to NativeAOT specifically with COM. I think there's part been work here for .NET 8 but I'm not sure if that will automatically solve this? Otherwise, maybe a developer might take a look at this: https://stackoverflow.com/questions/76507803/c-sharp-net-core-native-aot-with-reflection-activator-createinstance

As for the above suggestion to use Microsoft.Data.Sqlite, please note that EF Core 8 seems to have missed the target to introduce experimental NativeAOT support but that the underlying Microsoft.Data.Sqlite does support it. So, as long as it's good enough to have "only" the core library and not go full EF Core, you're good to go.

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

3 participants