dotnet / runtimelab

This repo is for experimentation and exploring new ideas that may or may not make it into the main dotnet/runtime repo.
MIT License
1.39k stars 195 forks source link

aot 8.0 throw System.MissingMethodException #2278

Closed lozn00 closed 1 year ago

lozn00 commented 1 year ago
Unhandled Exception: System.MissingMethodException: No parameterless constructor defined for type 'System.Configuration.ClientConfigurationHost'.
   at System.ActivatorImplementation.CreateInstance(Type, Boolean) + 0xfe
   at System.Configuration.Configuration..ctor(String, Type, Object[]) + 0x5b
   at System.Configuration.ClientConfigurationHost.OpenExeConfiguration(ConfigurationFileMap, Boolean, ConfigurationUserLevel, String) + 0x104
   at System.Configuration.ConfigurationManager.OpenExeConfigurationImpl(ConfigurationFileMap, Boolean, ConfigurationUserLevel, String, Boolean) + 0x4d
   at webapi_test.utils.ConfigUtil.initServerURLConfig() + 0x19
   at Program.<Main>$(String[] args) + 0x2e
   at webapi_mes!<BaseAddress>+0x11d0039

code

   Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            RuntimeSaveConfig.updateServer = readConfigValue(configuration, "UpdateServer");
            RuntimeSaveConfig.mesServer = readConfigValue(configuration, "MesServer");
jkotas commented 1 year ago

The native AOT projects lives in http://github.com/dotnet/runtime now. Please open any issues http://github.com/dotnet/runtime.

System.Configuration.ConfigurationManager package is not compatible with trimming and AOT (tracked by https://github.com/dotnet/runtime/issues/49062). You should see a warning like Assembly 'System.Configuration.ConfigurationManager' produced trim warnings. during build. This warning says that there is a good chance that the app is not going to work.

Duplicate of https://github.com/dotnet/runtime/issues/49062 that tracks trimming compatibility for System.Configuration.ConfigurationManager package.

lozn00 commented 1 year ago

@jkotas Can you give some advice? What library should I use instead of ConfigurationManager? Used to read and write files

Can you give some advice? What other utility classes support reading and writing configuration, and if I can't use ConfigurationManager, then what should I use?

jkotas commented 1 year ago

Microsoft.Extensions.Configuration is going to be the trimming and AOT friendly in .NET 8 with the introduction of configuration source generators: https://devblogs.microsoft.com/dotnet/announcing-dotnet-8-preview-3/#introducing-the-configuration-binding-source-generator

lozn00 commented 1 year ago

thank you