- Home /
System.Drawing namespace not consistently found (Unity version 5.6.2f1)
This is hopefully not the same as anyone else's problem but, even though both Visual Studio and MonoDevelop apparently have no difficulty accessing the "Sytem.Drawing" namespace once an assembly reference has been created, the Unity Editor throws CS0234 "The type or namespace name 'Drawing' does not exist in the namespace `System'. Are you missing 'System.Drawing' assembly reference?", and by extension CS0246 "The type or namespace name 'Bitmap' could not be found. Are you missing an assembly reference?", compile errors. I have tried everything else I could find on the forums. Thank you for your time!
Answer by Bunny83 · Jul 15, 2017 at 07:13 PM
You can't add assembly references inside Visual Studio or MonoDevelop. Usually when you develop a .NET or Mono application you need the .NET framework or Mono installed on the PC. That way the application has access to all assemblies that are included in the framework.
Unity however uses Mono as standalone scripting environment. Every assembly that you want to use has to be physically added to your project. So you have to copy the assembly and all it dependencies into your assets folder. Unity automatically adds the references to the C# project. The C# project actually isn't "used" at all. Unity has it's own build command. It directly calls the mono compiler when you build the game.
Just to be specific: search your system for system.drawing.dll
, and copy it into your project's assets folder. I found a few various versions in subfolders of:
C:\Program Files (x86)\Reference Assemblies\$$anonymous$$icrosoft\Framework.NETFramework\
and
C:\Program Files\Unity\Editor\Data\$$anonymous$$onoBleedingEdge\lib\mono\
Not sure which one you should actually use though... the newest, I guess?
I would recommend to use the mono version. First using the microsoft version could (in theory) cause licensing issues. Even something might be free, you may not be allowed to re-distribute parts of it. I did not read through the .NET EULA. The mono version is allowed to by included.
Also since there are slight differences between $$anonymous$$ono and .NET it has a higher chance to be compatible with the rest of the framework. Of course there are exceptions to that "rule" -.-
Oh man, thank you. I should have thought of this myself, but I have the dumb.
This worked! Thank you both very much for your help. I will keep in $$anonymous$$d what you have said in future.
Answer by FadeToBlack · Apr 15, 2019 at 05:35 AM
The proper way to include dotNet library not linked in Unity3d:
Create a new text file named mcs.rsp in your Unity project's root Assets directory.
On the first line in the empty text file, enter: -r:System.Net.Http.dll and then save the file. You can replace "System.Net.Http.dll" with any included assembly that might be missing a reference.
Restart the Unity editor.
And Unity documentation states "Don’t copy them into the Project directory." (docs). This should be the accepted answer.
Working like a charm in Unity editor and Visual Studio. It have to be the accepted answer.
It doesn't work when I have an assembly definition file in the root of my project. Any clues? After removing the assembly definition file, it properly gets the .DLL. Also, it the compiler doesn't see the DLL when I build the project.