WPF Application fails on startup with TypeInitializationException

前端 未结 10 816
Happy的楠姐
Happy的楠姐 2020-12-17 09:05

I have a simple WPF application which I am trying to start. I am following the Microsoft Patterns and Practices \"Composite Application Guidance for WPF\". I\'ve followed

相关标签:
10条回答
  • 2020-12-17 09:40

    I ran into a similar situation. After searching for a week time, I found the resolution and it really worked for me. It solved 2-3 problems arising due to same problem.

    Follow these steps: Check the WPF key (absence) in registry: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.0\Setup\Windows Presentation Foundation My problem was due to the absence of above mentioned key in registry.

    You can modify and use following details in your registry: (Actually, you can save in file and import in registry)

    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.0\Setup\Windows Presentation Foundation] @="WPF v3.0.6920.1453" "Version"="3.0.6920.1453" "WPFReferenceAssembliesPathx86"="C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\" "WPFCommonAssembliesPathx86"="C:\Windows\System32\" "InstallRoot"="C:\Windows\Microsoft.NET\Framework\v3.0\WPF\" "InstallSuccess"=dword:00000001 "ProductVersion"="3.0.6920.1453" "WPFNonReferenceAssembliesPathx86"="C:\Windows\Microsoft.NET\Framework\v3.0\WPF\"

    I am sure it will work.

    all the best.

    Regards,

    Umesh

    0 讨论(0)
  • 2020-12-17 09:43

    In my case this is need to be added:

    <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    

    Section at App.config (VS 2015 .NET 4.5.2)

    Open any WPF project what builded before, check build, if OK - check and compare App.config's at both projects

    0 讨论(0)
  • 2020-12-17 09:55

    If you only see the TypeInitializationException with no reason or no details on what's wrong, then disable Just My Code in the Visual Studio options.

    0 讨论(0)
  • 2020-12-17 09:56

    Tracking the InnerExceptions deep down , you might find the following error:

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

    This order change happened after Visual Studio EntityFramework Wizard added the connectionStrings element to the top

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