I am getting a TypeInitializationException
when I try to debug my application in Visual Studio 2012, but I am able to run the application in Visual Studio 2010 without error.
I recently moved a bunch of stuff around (including my project and several references) in order to get it into a version control system. I had to relink several items so that everything would link correctly when checked out on a different system.
Our development environment is mixed (VS2010 & VS2012). Running out of VS2010 produced no errors. But when I ran the Debug in VS2012 I received the TypeInitializationException
exception.
The project in the original directory (where it resided before moving for version control purposes) still runs fine in both VS2010 and VS2012.
There is a flag or a parameter or something that got a little messed up somewhere, but I'm not sure where. Does anyone have any ideas on what I can do to get this to work in VS2012 as well?
(please let me know what, if any, code or config information to include here)
InnerException:
The type initializer for 'System.Windows.Navigation.BaseUriHelper' threw an exception.
(Second) InnerException:
The type initializer for 'MS.Internal.TraceDependencyProperty' threw an exception.
Comments on the original question sparked further searches, which ultimately yielded a solution.
Doing a search for "The type initializer for 'System.Windows.Navigation.BaseUriHelper' threw an exception." I found the following StackOverflow question: WPF Application fails on startup with TypeInitializationException
Similar to that question I had added a <startup> </startup>
block to my "app.config" file. Where this tag block was placed made the difference:
Causes Error in VS2012:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client" />
</startup>
<configSections>
...
</configSections>
<applicationSettings>
...
</applicationSettings>
</configuration>
Everything works fine:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
...
</configSections>
<applicationSettings>
...
</applicationSettings>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client" />
</startup>
</configuration>
Moving the tag block to the bottom did the trick!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With