Unfortunately, right now, Config.NET can not be used with NativeAOT, because it relies on doing runtime code generation. This is a warning I'm getting during the NativeAOT build:
And sure enough, as soon as I do the typical new ConfigurationBuilder<IMySettings>().Build() thing, the app crashes:
Unhandled Exception: System.ArgumentException: Type System.Object is not valid base type for interface proxy, because it does not have accessible parameterless constructor. Only a non-sealed class with non-private default constructor can be used as base type for interface proxy. Please use some other valid type.
at Castle.DynamicProxy.Generators.BaseInterfaceProxyGenerator.ThrowInvalidBaseType(Type, String) + 0x5f
at Castle.DynamicProxy.Generators.BaseInterfaceProxyGenerator.EnsureValidBaseType(Type) + 0x114
at Castle.DynamicProxy.Generators.BaseInterfaceProxyGenerator..ctor(ModuleScope, Type, Type[], Type, ProxyGenerationOptions) + 0x77
at Castle.DynamicProxy.Generators.InterfaceProxyWithoutTargetGenerator..ctor(ModuleScope, Type, Type[], Type, ProxyGenerationOptions) + 0x42
at Castle.DynamicProxy.DefaultProxyBuilder.CreateInterfaceProxyTypeWithoutTarget(Type, Type[], ProxyGenerationOptions) + 0xc3
at Castle.DynamicProxy.ProxyGenerator.CreateInterfaceProxyTypeWithoutTarget(Type, Type[], ProxyGenerationOptions) + 0x48
at Castle.DynamicProxy.ProxyGenerator.CreateInterfaceProxyWithoutTarget(Type, Type[], ProxyGenerationOptions, IInterceptor[]) + 0x10d
at Castle.DynamicProxy.ProxyGenerator.CreateInterfaceProxyWithoutTarget(Type, IInterceptor) + 0xb8
at Castle.DynamicProxy.ProxyGenerator.CreateInterfaceProxyWithoutTarget[TInterface](IInterceptor) + 0x65
at Config.Net.ConfigurationBuilder`1.Build() + 0x101
at Sencae.Desktop.EmulatorRunner.Run(String[]) + 0x75
at Sencae.Program.Main(String[] args) + 0x3c
at Sencae.Desktop!<BaseAddress>+0x2bb067
at Sencae.Desktop!<BaseAddress>+0x2bb0e9
One possible workaroud would be to not have to rely on dynamically creating proxies, and instead use concrete classes defined in the source code (even if it means having to write extra boilerplate code), but it seems like Config.NET doesn't support that or provides an API for doing it manually.
Unfortunately, right now, Config.NET can not be used with NativeAOT, because it relies on doing runtime code generation. This is a warning I'm getting during the NativeAOT build:
And sure enough, as soon as I do the typical
new ConfigurationBuilder<IMySettings>().Build()
thing, the app crashes:One possible workaroud would be to not have to rely on dynamically creating proxies, and instead use concrete classes defined in the source code (even if it means having to write extra boilerplate code), but it seems like Config.NET doesn't support that or provides an API for doing it manually.