WPF Type initialization Exception in C#

后端 未结 8 2207
长发绾君心
长发绾君心 2020-12-17 19:44

I have someone else\'s WPF-based .NET 3.5 app that I\'m attempting to update to .NET 4.5. The code ran fine under .NET 3.5, and I\'m running Visual Studio 2013 Express on Wi

相关标签:
8条回答
  • 2020-12-17 19:49

    Check the spellings of connectionStrings,connectionString="" if used! 'S' should be capital ..XML is case sensitive :)

    0 讨论(0)
  • 2020-12-17 19:57

    I solve this problem by moving startup section in app.config to the last part before </configuration>, startup section must be the last part in app.config, like this:

    <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> </startup> </configuration>

    0 讨论(0)
  • 2020-12-17 19:58

    Digging Deeper into the Exception Details down to the last InnerException, and I found this:

    "Only one <configSections> element allowed per config file and if present must be the first child of the root <configuration> element"
    

    Move configSections to the beginning

    0 讨论(0)
  • 2020-12-17 20:02

    Check app.config file make sure that you don't have configurations to lib(s) that you no longer use or you have removed from the project

    0 讨论(0)
  • 2020-12-17 20:04

    Late to the party, but found this reason in my case. I had added a key-value pair with appSettings in app.config as in

    <appSettings>
        <add key="EncryKey" value="MyKey"/>
    </appSettings>
    

    before <configSections>. Upon digging in the internet, I came to know that, <configSections> had to be at the top of the root, soon after <configuration> and rest of the orders are irrelevant. Moving appSettings below <configSections> helped me fix this issue.

    0 讨论(0)
  • 2020-12-17 20:07

    One (not very educational) workaround would be to start a new 4.5 project, and copy-paste the relevant pieces of code from the old one.

    0 讨论(0)
提交回复
热议问题