Share via


the type initializer for threw an exception

Question

Monday, May 6, 2013 5:29 AM

Every time I try and do almost anything with Visual Studio Express 2012 I get the error message " the type initializer for <module> threw an exception"  For example if I try and clean or build any project I get this error.  I have tried uninstalling/installing visual studio and have applied the latest patches.

All replies (16)

Sunday, May 19, 2013 4:50 AM ✅Answered | 1 vote

I discovered the same issue with VS 2010 but not with VS 2008.  I tried uninstalling all of the .NET 4.5 components and then reinstalling them with Windows update.  That seemed to solve the problem.


Monday, May 6, 2013 10:49 AM | 1 vote

First try creating a new project and see if it compiles without any changes.  I suspect from your posting your are trying to rebuild projects that were built with previous versions of VS.  I would delete the bin folder inside the project which will force all files to get rebuilt.  VS will automatically create a new bin folder when you compile.  You may get new error messages that you haven't seen before that need to be fixed.  Right now these errors aren't getting detected because the files aren't getting compiled but you are getting linking errors because the source object files and the Net libraries don't match.

jdweng


Tuesday, May 7, 2013 1:46 AM

Thanks Joel

I tried creating a new project and I got the error "Visual Studio has encountered an unexpected error".  All of the projects tested were created under Visual Studio 2012.  At some point about the same time my problems started the background color for Visual Studio 2012 changed from light to dark.

James


Tuesday, May 7, 2013 2:15 AM

Can you try starting Visual Studio in SafeMode, once VS has started has the theme changed? Can you create a new project ?

Devenv /SafeMode http://msdn.microsoft.com/en-us/library/vstudio/ms241278.aspx

Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.


Tuesday, May 7, 2013 4:59 AM

Hello,

Thank you for your post.

I did some search about this error message.

Please try the solution in the blog: http://blogs.msdn.com/b/rajakedar_ganta/archive/2012/06/12/the-type-initializer-for-lt-module-gt-threw-an-exception.aspx

In addition, there is a Microsoft connection about this issue. http://connect.microsoft.com/VisualStudio/feedback/details/536766/the-type-initializer-for-module-throw-an-exception

Please see Exatex’s solution. As Weston said maybe it is an installation error.

If uninstalling /installing VS can’t resolve your issue, you can try reinstalling OS and VS as Exatex did.

Best regards,

Amanda Zhu [MSFT]
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.


Tuesday, May 7, 2013 6:52 PM

I am using visual studio express and I cannot find Devenv.exe on my hard drive.

Since the Start menu uses the link "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\WDExpress.exe",  I tried this with the /SafeMode option.

If I create a c# console application and I got a "Visual Studio has encountered an unexpected error" when I Build/ProjectOnly/CleanOnly

If I create a C# windows form application I get the "type initializer for <Module> threw an exception" error when I create the project.

James


Tuesday, May 7, 2013 7:15 PM

Thank you Amanda

I tried opening a console Window and typing

set complus_version="v4.0.30319"

There is a v4.0.30319 subdirectory in C:\Windows\Microsoft.NET\Framework

I then changed my working directory to C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE.  I then started Visual Studio 2012 Express with the command

WDExpress

I then immediately got an error "The type initializer for '<Module>' threw an exception".  This error occurred before I did anything with Visual Studio.  Before setting the complus_version I got the error only after trying to do an operation on a project.


Wednesday, May 8, 2013 1:42 AM

You can try the workaround below:

  • Please use the .NET Framework Setup Verification Utility and verified .NET Framework 4 first.
  • View the log and check whether your .NET Frameworks are fine.
  • If no, please uninstall VS2012, .NET Framework 4.5 and .NET Framework 4.
  • Re-install them.

崖山之後無中國,明亡之後無華夏


Wednesday, May 8, 2013 4:08 AM

I got "product verification successful" for all installed versions of .NET.

.NET Framework 4.5

.NET Framework 4 Full

.NET Framework 4 Client

.NET Framework 3.5 SP1

.NET Framework 3.0 SP2

.NET Framework 2.0 SP2

James


Thursday, May 9, 2013 2:48 AM

Hello,

Glad to receive your reply.

Ifstill no help, I’m afraid that I don’t have other good idea about this issue. Since I can't repro this issue, I suggest that you could submit this feedback to Microsoft Connect feedback portal: http://connect.microsoft.com,
Microsoft engineers will evaluate them seriously. Thanks for your understanding.
After you submit the feedback, you can post the link here which
will be beneficial for other members with the similar issue. And I will help you to vote it.

Best regards,

Amanda Zhu [MSFT]
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.


Sunday, May 19, 2013 5:00 AM

I though Net 4.5 was only for VS 2012.  VS 2010 and below should be using 1.0, 2.0, 3.0, 3.5, and 4.0.  The Net 4.5 is a standalone and doesn't need the other Net pieces (1.0 - 4.0).  I suspect the windows update by itself woulld of corrected the problem.  VS 2010 wasn't pointing to the correct libraries.  Also updating windows probably forces the entire project ot get recompiled.  I sometimes find deleting the bin folder of a project (especially when upgrading Net or VS) is required to make sure all the comiled objects are pointing to the latest libraries.

jdweng


Sunday, May 19, 2013 5:57 PM

VS2012 or VS2010 through the exception rather my code throwing the exception.  My code is not executing if I create a new project or clean an existing project.  I think there was some problem with the libraries the VS was using rather than any libraries linked into a project.


Sunday, May 19, 2013 6:03 PM

I agree it not the project that was wrong.  When they is an issue with the Net library it is hard to tell if the problem is with the library or the linking between VS and the library.  Anyway, I'm glad you solved the problem.

jdweng


Monday, September 23, 2013 8:14 PM

I got the same thing when I cleaned out a folder and accidentally removed an .accdb that was read during start-up.  Putting it back fixed it.


Friday, October 27, 2017 11:54 AM

is this the right way  for solving this problem ??

can u try this ur slf ??


Tuesday, November 14, 2017 1:47 PM

Hi All,

Kindly check the .Net version.

Uninstall the same if the version is higher than 4.5.