<p>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 their instructions however my WPF application fails immediately with a "TypeInitializationException".</p>

<p>The InnerException property reveals that "The type initializer for 'System.Windows.Navigation.BaseUriHelper' threw an exception."</p>

<p>Here is my app.xaml:</p>

<pre><code>&lt;Application x:Class="MyNamespace.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt;
    &lt;Application.Resources&gt;         
    &lt;/Application.Resources&gt;
&lt;/Application&gt;
</code></pre>

<p>And here is my app.xaml.cs (exception thrown at "public App()"):</p>

<pre><code>public partial class App : Application
{
    public App()
    {
        Bootstrapper bootStrapper = new Bootstrapper();
        bootStrapper.Run();
    }
}
</code></pre>

<p>I have set the "App" class as the startup object in the project.</p>

<p>What is going astray?</p>

[{'answer_id': 58447, 'author': 'ima', 'author_id': 5733, 'author_profile': 'https://Stackoverflow.com/users/5733', 'pm_score': 3, 'selected': False, 'text': '<p>Do you use .config file? If so, check it for errors. Initialization errors of such sort are often triggered by invalid XML: if there are no errors in XAML, XML config is the first place to look.</p>\n'}, {'answer_id': 58464, 'author': 'Adrian Clark', 'author_id': 148, 'author_profile': 'https://Stackoverflow.com/users/148', 'pm_score': 6, 'selected': True, 'text': '<p>Thanks @ima, your answer pointed me in the right direction.  I was using an app.config file and it contained this:</p>\n\n<pre><code>&lt;configuration&gt;\n  &lt;startup&gt;\n    &lt;supportedRuntime version="v2.0.50727" sku="Client"/&gt;\n  &lt;/startup&gt;\n  &lt;configSections&gt;\n    &lt;section name="modules" type="Microsoft.Practices.Composite.Modularity.ModulesConfigurationSection, Microsoft.Practices.Composite"/&gt;\n  &lt;/configSections&gt;\n  &lt;modules&gt;\n    &lt;module assemblyFile="Modules/MyNamespace.Modules.ModuleName.dll" moduleType="MyNamespace.Modules.ModuleName.ModuleClass" moduleName="Name"/&gt;\n  &lt;/modules&gt;\n&lt;/configuration&gt;\n</code></pre>\n\n<p>It seems the problem was the &lt;startup&gt; element because when I removed it the application ran fine.  I was confused because Visual Studio 2008 added that when I checked the box to utilise the "Client Profile" available in 3.5 SP1.</p>\n\n<p>After some mucking about checking and un-checking the box I ended up with a configuration file like this:</p>\n\n<pre><code>&lt;configuration&gt;\n  &lt;configSections&gt;\n    &lt;section name="modules" type="Microsoft.Practices.Composite.Modularity.ModulesConfigurationSection, Microsoft.Practices.Composite"/&gt;\n  &lt;/configSections&gt;\n  &lt;modules&gt;\n    &lt;module assemblyFile="Modules/MyNamespace.Modules.ModuleName.dll" moduleType="MyNamespace.Modules.ModuleName.ModuleClass" moduleName="Name"/&gt;\n  &lt;/modules&gt;\n  &lt;startup&gt;\n    &lt;supportedRuntime version="v2.0.50727" sku="Client"/&gt;\n  &lt;/startup&gt;\n&lt;/configuration&gt;\n</code></pre>\n\n<p>Which works!</p>\n\n<p>I\'m not sure why the order of elements in the app.config is important - but it seems it is.</p>\n'}, {'answer_id': 1012016, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>You have two sections named "modules". Place both module definitions in one section named "modules".</p>\n'}, {'answer_id': 2876057, 'author': 'Umesh Bhavsar', 'author_id': 346354, 'author_profile': 'https://Stackoverflow.com/users/346354', 'pm_score': 0, 'selected': False, 'text': '<p>I ran into a similar situation.\nAfter searching for a week time, I found the resolution and it really worked for me.\nIt solved 2-3 problems arising due to same problem.</p>\n\n<p>Follow these steps:\nCheck the WPF key (absence) in registry:\nHKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v3.0\\Setup\\Windows Presentation Foundation\nMy problem was due to the absence of above mentioned key in registry.</p>\n\n<p>You can modify and use following details in your registry: (Actually, you can save in file and import in registry)</p>\n\n<p>[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v3.0\\Setup\\Windows Presentation Foundation]\n@="WPF v3.0.6920.1453"\n"Version"="3.0.6920.1453"\n"WPFReferenceAssembliesPathx86"="C:\\Program Files\\Reference Assemblies\\Microsoft\\Framework\\v3.0\\"\n"WPFCommonAssembliesPathx86"="C:\\Windows\\System32\\"\n"InstallRoot"="C:\\Windows\\Microsoft.NET\\Framework\\v3.0\\WPF\\"\n"InstallSuccess"=dword:00000001\n"ProductVersion"="3.0.6920.1453"\n"WPFNonReferenceAssembliesPathx86"="C:\\Windows\\Microsoft.NET\\Framework\\v3.0\\WPF\\"</p>\n\n<p>I am sure it will work.</p>\n\n<p>all the best.</p>\n\n<p>Regards,</p>\n\n<p>Umesh </p>\n'}, {'answer_id': 14492905, 'author': 'Lin Song Yang', 'author_id': 247011, 'author_profile': 'https://Stackoverflow.com/users/247011', 'pm_score': 4, 'selected': False, 'text': '<p>Anything wrong in the <strong>App.config</strong> file may cause the error, such as a typo of <code>*</code> at the end of a line, eg <code>...&lt;/startup&gt;</code> has an additional "*" at the end of the line <code>...&lt;/startup&gt;*</code>.</p>\n'}, {'answer_id': 36924610, 'author': 'usefulBee', 'author_id': 2093880, 'author_profile': 'https://Stackoverflow.com/users/2093880', 'pm_score': 2, 'selected': False, 'text': '<p>Tracking the InnerExceptions deep down , you might find the following error:</p>\n\n<p><code>"Only one &lt;configSections&gt; element allowed per config file and if present must be the first child of the root &lt;configuration&gt; element"</code></p>\n\n<p>This order change happened after Visual Studio EntityFramework Wizard added the connectionStrings element to the top</p>\n'}, {'answer_id': 39642579, 'author': 'lvmeijer', 'author_id': 393367, 'author_profile': 'https://Stackoverflow.com/users/393367', 'pm_score': 2, 'selected': False, 'text': "<p>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. </p>\n"}, {'answer_id': 42322164, 'author': 'Denis Kirin', 'author_id': 7191785, 'author_profile': 'https://Stackoverflow.com/users/7191785', 'pm_score': 0, 'selected': False, 'text': '<p>In my case this is need to be added:</p>\n\n<pre><code>&lt;configSections&gt;\n&lt;!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --&gt;\n&lt;section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /&gt;\n</code></pre>\n\n<p></p>\n\n<p>Section at App.config (VS 2015 .NET 4.5.2)</p>\n\n<p>Open any WPF project what builded before, check build, if OK - check and compare App.config\'s at both projects</p>\n'}, {'answer_id': 46125350, 'author': 'Jason Cheng', 'author_id': 1419440, 'author_profile': 'https://Stackoverflow.com/users/1419440', 'pm_score': 2, 'selected': False, 'text': '<p>For me, I had copied app settings over from another application into my app.config into a new section called "userSettings".  However, there needs to be a "configSections" also added to the app.config which defines "userSettings".  I deleted the userSettings section then edited the app settings and saved it.  VS automatically creates the correct "userSettings" and "configSections" for you if they are absent.</p>\n'}, {'answer_id': 63356436, 'author': 'Sely Lychee', 'author_id': 5128530, 'author_profile': 'https://Stackoverflow.com/users/5128530', 'pm_score': 0, 'selected': False, 'text': '<p>For me I renamed my Application name and caused this error. I had a server and client app. the server app was not having this issue. so i checked App.config file of both server and client. I found</p>\n<pre><code>&lt;startup&gt;\n&lt;supportedRuntime version=&quot;v4.0&quot; sku=&quot;.NETFramework,Version=v4.6.1&quot; /&gt;\n&lt;/startup&gt;\n\n&lt;configSections&gt;\n&lt;section name=&quot;entityFramework&quot; type=&quot;System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089&quot; requirePermission=&quot;false&quot; /&gt;\n&lt;!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --&gt;\n&lt;/configSections&gt;\n</code></pre>\n<p>&lt;startup&gt; tag above &lt;configSections&gt; tag in client and server had the other way so I copy pasted startup tag down configSections tag and it worked. Like this.</p>\n<pre><code>&lt;configSections&gt;\n&lt;section name=&quot;entityFramework&quot; type=&quot;System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089&quot; requirePermission=&quot;false&quot; /&gt;\n&lt;!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --&gt;\n&lt;/configSections&gt;\n\n&lt;startup&gt;\n&lt;supportedRuntime version=&quot;v4.0&quot; sku=&quot;.NETFramework,Version=v4.6.1&quot; /&gt;\n&lt;/startup&gt;\n</code></pre>\n'}, {'answer_id': 70990589, 'author': 'AviB', 'author_id': 4653372, 'author_profile': 'https://Stackoverflow.com/users/4653372', 'pm_score': 0, 'selected': False, 'text': "<p>I was getting the same error. The suggestions mentioned above did not work for me. i was getting the following error after running</p>\n<pre><code>System.TypeInitializationException\n  HResult=0x80131534\n  Message=The type initializer for 'System.Windows.Application' threw an exception.\n  Source=PresentationFramework\n  StackTrace:\n   at System.Windows.Application..ctor()\n   at ShortBarDetectionSystem.App..ctor()\n   at ShortBarDetectionSystem.App.Main()\n\nInner Exception 1:\nTypeInitializationException: The type initializer for 'System.Windows.Navigation.BaseUriHelper' threw an exception.\n\nInner Exception 2:\nTypeInitializationException: The type initializer for 'MS.Internal.TraceDependencyProperty' threw an exception.\n\nInner Exception 3:\nConfigurationErrorsException: Configuration system failed to initialize\n\nInner Exception 4:\nConfigurationErrorsException: Section or group name 'oracle.manageddataaccess.client' is already defined. Updates to this may only occur at the configuration level where it is defined. (C:\\ShortBarDetectionSystem\\code\\framework\\TypeInitializationException\\ver0_1\\ShortBarDetectionSystem\\ShortBarDetectionSystem\\bin\\x64\\Debug\\GrateBarDefectDetectionSystem.exe.Config line 4)\n</code></pre>\n<p>I was getting an error in my exe.config file line 4. The .exe.config file was :</p>\n<pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;\n&lt;configuration&gt;\n  &lt;configSections&gt;\n    &lt;section name=&quot;oracle.manageddataaccess.client&quot; type=&quot;OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Version=4.122.21.1, Culture=neutral, PublicKeyToken=89b483f429c47342&quot; /&gt;\n  &lt;/configSections&gt;\n  &lt;startup&gt;\n    &lt;supportedRuntime version=&quot;v4.0&quot; sku=&quot;.NETFramework,Version=v4.7.2&quot; /&gt;\n  &lt;/startup&gt;\n  &lt;system.data&gt;\n    &lt;DbProviderFactories&gt;\n      &lt;remove invariant=&quot;Oracle.ManagedDataAccess.Client&quot; /&gt;\n      &lt;add name=&quot;ODP.NET, Managed Driver&quot; invariant=&quot;Oracle.ManagedDataAccess.Client&quot; description=&quot;Oracle Data Provider for .NET, Managed Driver&quot; type=&quot;Oracle.ManagedDataAccess.Client.OracleClientFactory, Oracle.ManagedDataAccess, Version=4.122.21.1, Culture=neutral, PublicKeyToken=89b483f429c47342&quot; /&gt;\n    &lt;/DbProviderFactories&gt;\n  &lt;/system.data&gt;\n  &lt;runtime&gt;\n    &lt;assemblyBinding xmlns=&quot;urn:schemas-microsoft-com:asm.v1&quot;&gt;\n      &lt;dependentAssembly&gt;\n        &lt;assemblyIdentity name=&quot;System.Runtime.CompilerServices.Unsafe&quot; publicKeyToken=&quot;b03f5f7f11d50a3a&quot; culture=&quot;neutral&quot; /&gt;\n        &lt;bindingRedirect oldVersion=&quot;0.0.0.0-6.0.0.0&quot; newVersion=&quot;6.0.0.0&quot; /&gt;\n      &lt;/dependentAssembly&gt;\n      &lt;dependentAssembly&gt;\n        &lt;assemblyIdentity name=&quot;System.Text.Json&quot; publicKeyToken=&quot;cc7b13ffcd2ddd51&quot; culture=&quot;neutral&quot; /&gt;\n        &lt;bindingRedirect oldVersion=&quot;0.0.0.0-6.0.0.0&quot; newVersion=&quot;6.0.0.0&quot; /&gt;\n      &lt;/dependentAssembly&gt;\n    &lt;/assemblyBinding&gt;\n  &lt;/runtime&gt;\n&lt;/configuration&gt;\n</code></pre>\n<p>However after trial and error i figured out that deleting the configSections</p>\n<pre><code>&lt;configSections&gt;\n    &lt;section name=&quot;oracle.manageddataaccess.client&quot; type=&quot;OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Version=4.122.21.1, Culture=neutral, PublicKeyToken=89b483f429c47342&quot; /&gt;\n  &lt;/configSections&gt;\n</code></pre>\n<p>worked for me.</p>\n"}]
['https://Stackoverflow.com/questions/58425', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/148/']