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.
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.
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