1

I have an application that is running .Net 3.5 and want to upgrade all of the users to V4.0 using a setup kit. The upgrade works fine, except that I don't want to hand-edit all of their configuration files to add the required line:

<startup useLegacyV2RuntimeActivationPolicy="true"><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>

That is required to make Crystal Reports 2010 work correctly. I was hoping that the Configuration namespace had a section labelled startup, but no such luck. I am unable to add a new Section without having a section type defined. Does anyone have any experience with doing this using the Configuration class?

Thanks, Neil

1 Answer 1

2

The most 'elegant' way I've found doing that is using some raw xml, which includes the entire startup section. So while it might not be the most 'correct' way, it is still better than manual edit of the config file IMO.

Here is a working code example for editing the config file from within the same executable (you might need to provide the path in OpenExeConfiguration to do so from your installer):

Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
var sec = config.Sections["startup"];
sec.SectionInformation.SetRawXml("<startup useLegacyV2RuntimeActivationPolicy=\"true\"><supportedRuntime version=\"v4.0\" sku=\".NETFramework,Version=v4.0\" /></startup>");
config.Save(ConfigurationSaveMode.Modified);
2
  • Hi Omer, thanks for the reply. I probably did not make myself clear enough - what I really need is a chunk of code that I can run in my Installer that adds the above line to the config file, to upgrade existing 3.5 installations to .net framework 4. I can see how to add existing sections to a config file, but what I don't understand is how to add a startup tag to the config file using the Configuration class.
    – Arkitec
    Mar 3, 2014 at 21:50
  • Omer - your solution worked beautifully. Just got a chance to try it out today. Thanks, this solved the problem, simply and elegantly.
    – Arkitec
    Mar 4, 2014 at 20:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.