We've recently installed .NET 4.5 onto our continuous integration build server so that it can support new projects that utilize features of .NET 4.5. This build server is also used to build and deploy older projects, as well, some of which target .NET 4.0.
Projects that target .NET 4.0 being built on this server, then deployed to a target server that has only .NET 4.0 installed are now failing with the following error:
Method not found: 'Int32 System.Environment.get_CurrentManagedThreadId()'.
Environment.CurrentManagedThreadId is a new property of .NET Framework 4.5, so it makes sense that a server running 4.0 can't find it. However, we are targeting .NET 4.0 at build time, so in theory we shouldn't need to have 4.5 installed on the production server.
To sum up:
Method not found: 'Int32 System.Environment.get_CurrentManagedThreadId()'.
What gives? Is it possible to successfully run .NET 4.0 dlls on a server with only .NET 4.0 installed when the dlls are built by a server with .NET 4.5?
If you created your app using an earlier version of . NET Framework, you can generally upgrade it to . NET Framework 4.5 and its point releases (4.5. 1 and 4.5.
NET version 5 (Visual Studio 16.8 or later) . NET Framework versions 4.8, 4.7.
NET in the File System. You can check your installed versions of . NET by navigating to Microsoft.NET\Framework under your Windows folders. The complete path is usually 'C:\Windows\Microsoft.NET\Framework.
This occurs because 4.5 is an in-place upgrade to 4.0. When the build server compiles, by default, it will find the 4.5 assemblies even if you're targeting .NET 4.
You can correct this, but you need to add the 4.0 reference assemblies to your build server (so the compiler finds them), and not just rely on the .NET 4.5 versions.
For details, see Marc Gravell's blog post on the subject.
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