开发者

Specific version of System.Configuration.dll for my add-in DLL when the host application targets a different version via its app.config?

开发者 https://www.devze.com 2023-02-15 16:05 出处:网络
I\'m writing a .NET DLL (C#) that is an add-in for a 3rd party product. That product includes this in it\'s application.exe.config file:

I'm writing a .NET DLL (C#) that is an add-in for a 3rd party product. That product includes this in it's application.exe.config file:

<startup useLegacyV2RuntimeActivationPolicy="true">
  <supportedRuntime version="v4.0"/>
</startup>

My DLL targets .NET v3.5, and my app.config file includes this:

<configSections>
  <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
  <section name="myDLL.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
  </sectionGroup>
</configSections>

When I use the Settings object (derived from ApplicationsSettingsBase) to save a setting, the save works - and the data is saved to the user.config file of the host application. However, it is saved with this in it (note the Version=4.0.0.0):

<configSections>
  <sectionGroup name="userSettings" type开发者_StackOverflow社区="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
    <section name="myDLL.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
    <section name="anotherVendorsDLL.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
  </sectionGroup>
</configSections>

With these settings saved, my DLL will not load the settings on subsequent runs of the host application. The supportedRuntime of the application.exe.config has an impact on this - changing or deleting it will mean that the user.config file is saved with a different Version=X.X.X.X in it. With Version=2.0.0.0 my settings load just fine.

How can I get my settings to load/save without a problem without updating the host application.exe.config file? Or do I need to consider using an alternative storage location for my application settings, such as my own XML config file or registry?


There's something missing from this question. A DLL cannot have its own .config file, its configuration sections must be merged into the app.exe.config file. Sounds to me you don't control this file, how do you prevent the owner of the app from breaking you when he reinstalls or updates his .config file?

At any rate, the lack of control you have is very troublesome. Storing your own settings without using a .config file is strongly indicated. An .xml file will do just fine.

0

精彩评论

暂无评论...
验证码 换一张
取 消