Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2010 startup: "type initializer for '<Module>' threw an exception."

I'm working on a simple command line project. I changed the properties from .NET 3.5 to .NET 4.0 and restarted Visual Studio 2010. I get this error:

The type initializer for '<Module>' threw an exception.

The type initializer for 'Module' threw an exception.

and Visual Studio does not start.

I have tried starting with devenv.exe /SafeMode and devenv.exe /reset, which make no difference. Google is not helping me either.

Help!


EDIT: I still can't get Visual Studio to do anything. I tried installing SharpDevelop, but that also fails to start, but with a more informative error:

Unhandled exception terminated SharpDevelop Exception thrown: System.TypeInitializationException: The type initializer for 'ICSharpCode.Core.Presentation.MenuService' threw an exception. ---> System.TypeInitializationException: The type initializer for '<Module>' threw an exception. ---> <CrtImplementationDetails>.ModuleLoadException: The C++ module failed to load during appdomain initialization. ---> System.DllNotFoundException: C:\Windows\Microsoft.NET\Framework\v4.0.21006\WPF\wpfgfx_v0400.dll ---> System.ComponentModel.Win32Exception: The specified module could not be found

I don't have .NET 4 at the path in the above error, I have a different version so it is installed at C:\Windows\Microsoft.NET\Framework\v4.0.30319

I have tried uninstalling .NET 4 and re-installing it, but it doesn't make either VS or #develop work, nor does it change the installation path.

like image 999
Colin Pickard Avatar asked May 12 '11 15:05

Colin Pickard


People also ask

What is type initialization exception in C#?

Most commonly, a TypeInitializationException exception is thrown when a static constructor is unable to instantiate a type. The InnerException property indicates why the static constructor was unable to instantiate the type.


3 Answers

If Visual Studio can't start up then it's very likely a 3rd party component which is loading during startup which is causing this issue. The best way to root it out is to uninstall the extensions if possible. If not try

devenv /resetSettings

After that the next step is to try and repair the installation.

like image 168
JaredPar Avatar answered Sep 28 '22 03:09

JaredPar


I got it working with a somewhat scary hack.

Trying to run SharpDevelop gave me the same error but with more detail - it was looking for a DLL in C:\Windows\Microsoft.NET\Framework\v4.0.21006\, but my .NET 4 was installed in C:\Windows\Microsoft.NET\Framework\v4.0.30319\.

I couldn't find a way to install the old version or how to change that broken reference so I simply copied to whole v4.0.30319 folder to v4.0.21006, after which everything started working.

I did get this interesting message when I re-opened the solution I had been working on. Clicking OK opened my solution as normal. enter image description here

I guess this is related to how I triggered the problem - I must somehow have been able to set the target framework of the solution to one I don't have installed on my machine (although there was only one entry in the dropdown for .NET 4), which I guess then set some flag somewhere on my machine for my 'current' or 'active' version of .NET... I'm guessing here, but hopefully this might help someone else who stumbles on this problem.

like image 27
Colin Pickard Avatar answered Sep 28 '22 03:09

Colin Pickard


I had the same issue and downloaded .NET 4 framework and did a repair and that fix it for me!

like image 31
raminjacobson Avatar answered Sep 28 '22 04:09

raminjacobson