- Home /
Why is platform dependent code not working
#if !UNITY_EDITOR
using Microsoft.AspNet.SignalR.Client;
#endif
When I run my project in the editor it works fine. But when I want to build my project I am being told:
Error building Player because scripts had compiler errors.
But I am not shown where. When I comment the code above out everything works fine and I can build my project whithout any trouble. Is there any way to solve this? Right now I have to comment code out every time I have a new version just to have it back to normal in the build version. Thanks for your help!
Answer by Bunny83 · Jul 06, 2017 at 02:27 PM
Since this usins statement is only active when you're not in the editor (which mean it is only used when you build your game) and you don't seem to require that namespace anywhere you can completely remove the line.
If for some reason you do need it (maybe for some framework that you don't use yet) you should check that you have the actual assembly as well as all dependencies in your project. However if you have no idea for what you need it and the project build fine without it i doubt you actually require it. Inside which file / script is that code fragment located?
Im curious, did you add your reference to that DLL your are "using"?
You can't manually add a reference to a DLL in Unity. Well you can but Unity will overwrite it anyways. You have to copy your DLLs into your project (plugins folder). Unity will automatically add the references for all assemblies in your project.
I think these two comments are the actual answer to the OP. The DLL referenced by the "using" statement has NOT been put in this folder, and so the automatically-generated reference fails, when attempting a build that actually uses it (!EDITOR_UNITY).
I did add a Reference with Visual Studio NUGet in the build version of the project
Thanks a lot for your reply! So I do use the code behind the using and where I do I have to comment it out too. I just wanted to make my question simpler. I have that code in a normal script which I added to a gameobject. I the build version I added the code content of SignalR.Client via NuGet.
Answer by LilGames · Jul 06, 2017 at 02:43 PM
Do builds complete? You're going to have to debug from a build rather than in the editor. Make sure you build a development build.
I do that but to create a build I always have to comment out some parts of the code which I don´t want since that is quite an effort.
Your answer
![](https://koobas.hobune.stream/wayback/20220612125646im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to compensate for moving platforms that move side to side 2 Answers
How can I create an animation of platforms 1 Answer
toggle rigidbody constraints? 1 Answer
Sync assets that are built in different platforms 0 Answers
Building Question 1 Answer