Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET 4.0 assembly built on windows 8.1 does not work on lower windows versions

We have a project consisting of c++ core library and .NET wrappers (2.0 and 4.0) using Marshall. Build machine has Windows 8.1 OS.

C++ core and .NET 2.0 wrapper are built using MSVC 2005 and works perfect on other machines with lower windows versions.

.NET 4.0 wrapper is built using Microsoft SDK 7.1. Library works fine on build machine, but crashes on other machines (with .NET 4.0 installed) with following error:

Exception: System.MissingMethodException: Method not found: 'IntPtr System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(!!0)'.

It seems like wrapper was built using higher version of .NET and i have no idea how to solve this. As far as i understood there is no way to force using specific version of .NET 4.x while building though they are not backwards compatible.

like image 528
e_ChiP Avatar asked Oct 21 '22 16:10

e_ChiP


2 Answers

You can specify the version of the .Net framework you want your app to use in the project properties window. Under the Application tab, select your preferred version under the Target framework dropdown. You can see more about targeting specific framework version on MSDN.

like image 72
WarrenG Avatar answered Oct 24 '22 12:10

WarrenG


I managed to solve the problem. Somehow MSbuild used the best avilable toolset, though environment was configured to Windows SDK 7.1

While investigating the problem i finally found this article. So in order to build project i must configure environment to SDK and tell MSbuild to use toolset from this SDK.

So the solution is to call MSbuild with flag /p:PlatformToolset=Windows7.1SDK.

Thanks to everybody who was helping!

like image 29
e_ChiP Avatar answered Oct 24 '22 12:10

e_ChiP