C# DLL config file

后端 未结 17 2387
梦毁少年i
梦毁少年i 2020-11-22 05:05

Im trying to add an app.config file to my DLL, but all attempts have failed.

According to MusicGenesis in \'Putting configuration information in a DLL\' this should

17条回答
  •  后悔当初
    2020-11-22 05:07

    you are correct, you can read the config file of a dll. I struggled with this for a day until i found out that the my config file was the issue. See my code below. it was able to run.

            ExeConfigurationFileMap map = new ExeConfigurationFileMap();
            map.ExeConfigFilename = Assembly.GetExecutingAssembly().Location + ".config";
            Configuration libConfig = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);
            AppSettingsSection section = (libConfig.GetSection("appSettings") as AppSettingsSection);
            Console.WriteLine(section.Settings["dnd_shortcodes"].Value);
    

    my Plugin1.dll.config looked as below;

    
    
     
      
      
     
    
    

    I found out that my config file lacked the tag, so look around, your issue could have been different but not so far from mine.

提交回复
热议问题