Hi All,
This question is mainly about finding out why this does not work rather than any benefits of using C++/clr over C#.
I am attempting to get a purely IL DLL assembly generated from C++/clr code to run correctly in a Unity WebPlayer project.
Basically I am using the 2005 Visual C++ compiler in the following way:
> cl /clr:safe /LD *.cpp
This generates a .DLL that .NET Reflector and ildasm tells me is identical to one I compiled with the 2005 C# compiler.
Most importantly, the Target Runtime is confirmed to be v2.0.50727. This DLL can also work in Silverlight, again confirming that there is no native code in it (mainly due to the /clr:safe flag).
I am using the 2005 version of cl.exe so to ensure that the target framework is 2.0 and not higher.
It runs great in Unity for all exporters apart from the WebPlayer where it comes up with Loading script assembly “Assets/Libraries/Test.dll” failed. The editor log includes as follows.
Non platform assembly: C:\Users\kpedersen\Documents\NetSandbox\Assets\Libraries\Test.dll (this message is harmless)
Failed loading assembly Assets/Libraries/Test.dll
Loading script assembly "Assets/Libraries/Test.dll" failed!
Again, when using the C# DLL as a direct substitute, this just works.
Additional things I have tried include:
cl /clr:safe /clr:nostdlib /d1clr:nomscorlib /FU"C:\Program Files (x86)\Unity\Editor\Data\Mono\lib\mono\unity_web\mscorlib.dll"
cl /clr:safe /clr:nostdlib /d1clr:nomscorlib /FU"C:\Program Files (x86)\Unity\Editor\Data\Mono\lib\mono\unity\mscorlib.dll"
Though I think this is going in the wrong direction because the C# version of the DLL does not need to use the mscorlib from the Unity distribution.
This is just annoying because I think the IL code is fine, I think there must be some kind of metadata embedded into the .DLL that Unity’s web player build system is rejecting.
Any suggestions would be greatly appreciated.
Karsten