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.
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.
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.
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.
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.
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.
I had the same issue and downloaded .NET 4 framework and did a repair and that fix it for me!
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