Move C# scripts to DLLs targeting UWP/Net deployment: the type or namespace 'SerializeAttribute/Serializable' could not be found?
I created some C# code for one of my Unity 5.4.0-f3HTP projects (developing on Win10, x64). This code "lives" in the Assets folder of the Unity project. I wrote the code so that the project can be deployed to HoloLens/UWP, and other platforms (of which only Windows/Osx are used). The C# code depends on access to code that lives in the UnityEngine namespace, the System. namespace, and the Microsoft. (for the UWP platform specific backend) namespace.
My goal is to take the C# code out of the assets folder, and use visual studio 2015 to compile it into two platform specific DLL's. One that is .net 3.5 (for Windows/OSX), the other is for UWP. The .net 3.5 DLL is not a problem. I can't figure out how to set up VS2015 to compile the UWP DLL though.
If I compile a "hello world" UWP dll (referencing Microsoft.NETCore.UniversalWindowsPlatform), things work just fine (including referencing the UnityEngine.dll from "C:\Program Files\Unity HoloLens 5.4.0f3-HTP\Editor\Data\Managed\UnityEngine.dll"). But as soon as I add code from the Assets folder, I get a number of errors:
Error CS0246 The type or namespace name 'SerializableAttribute' could not be found (are you missing a using directive or an assembly reference?)
Error CS0246 The type or namespace name 'Serializable' could not be found (are you missing a using directive or an assembly reference?)
Note that I am not making any changes to the code as I move it from the Assets folder; and I am setting up the appropriate preprocessor defines for the UWP/Mono backend.
I've tried several things to mitigate the problem, including splitting the code into two DLLs; one containing generic code that only depends on .NET and/or UnityEngine.dll, another that has platform specific code for either .NET or UnityEngine - but that did not work (I think I could not add the DLL containing the generic code as a reference to the UWP DLL). So I gave up on exploring this potential solution (but I'm still not sure if I did something wrong vs. it not being possible to do what I envisioned)
Has anyone encountered this before?
I know at least Serializable is part of System, not UnityEngine. have you included that?
Answer by macho · Mar 24, 2017 at 01:31 AM
Apparently System.Serializable has been removed in UWP.
After some more headscratching and chinstroking, I am now pursuing this approach:
I've tried several things to mitigate the problem, including splitting the code into two DLLs; one containing generic code that only depends on Mono and references UnityEngine.dll, another that has platform specific code for either Mono or UWP that is referenced by this 'generic' DLL
During runtime, I have a script in my unity scene that figures out what the appropriate platform specific DLL is, loads it from the streamingresources folder, and registers the factory creation methods for the platform specific class/interface implementations for either Mono or UWP
Your answer
Follow this Question
Related Questions
VS Code missing UnityEngine.UI 1 Answer
How to attach Visual Studio to Unity in order to debug a native dll? 1 Answer
Using RuntimeInitializeOnLoadMethod inside dll and using in iOS build 1 Answer
Transfer scene from project that uses DLL back to original source code 0 Answers
Vistual Studio Code won't let me access Unity Methods 0 Answers