Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

System.MissingMethodException Int32 System.Environment. get_CurrentManagedThreadId()

Tags:

c#

.net-4.0

What could cause the following exception?

System.MissingMethodException Int32 System.Environment.get_CurrentManagedThreadId() 

This method call seems to be generated by C# compiler for methods yielding IEnumerable<>.

.NET Framework v4.0 x86 is installed and the binary is compiled for v4.0 Any CPU.

like image 280
TN. Avatar asked Mar 22 '13 11:03

TN.


1 Answers

CurrentManagedThreadId is a .NET 4.5 property, so you will need 4.5 to run the code. See Iterator blocks, missing methods, and .NET 4.5 for an analysis of how this problem might occur.

In short:

If you build your application (targeted at .NET 4.0) on a system with .NET 4.5 installed, it will use 4.5 as basis for the compilation, because the .NET 4.0 Framework is always overwritten by .NET 4.5.

If your application then also uses yield return, it will fail on systems having only 4.0 installed because the implementation of this statement uses a new property when compiled for the 4.5 Framework.

To solve it, make sure your compiler system has the 4.0 reference assemblies.

like image 152
floele Avatar answered Sep 21 '22 04:09

floele