Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting TypeInitializationException in VS2012, But Not 2010

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.

like image 200
Nicholas Pappas Avatar asked Dec 26 '22 13:12

Nicholas Pappas


1 Answers

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!

like image 197
Nicholas Pappas Avatar answered Dec 29 '22 02:12

Nicholas Pappas