Search Unity

Error CS0103

Discussion in 'Editor & General Support' started by Mikevincent, Mar 7, 2017.

  1. Mikevincent

    Mikevincent

    Joined:
    Mar 6, 2017
    Posts:
    14
    Hello.
    I am completely new to this and I am going thru some tutorials. Now I have encountered an error. Whever I try to make a C# script it says on both UnityEngine and MonoBehaviour (that are also marked in red) "Error CS0103 - the name does not exist in the current context". I have searched for this on Google and many people seem to have this error, yet no solution I have found has worked. I have tried to change to Net 4.5. Nothing works. Please help.
     
  2. Jaimi

    Jaimi

    Joined:
    Jan 10, 2009
    Posts:
    6,208
    Post your script, and lets take a look at it
     
  3. Mikevincent

    Mikevincent

    Joined:
    Mar 6, 2017
    Posts:
    14
    Well, it works outside of the MonoDevelop. When I hit the play button it runs as it should.

    I made a new C# without any written code and took a print screen to show you, here -
     
  4. Jaimi

    Jaimi

    Joined:
    Jan 10, 2009
    Posts:
    6,208
    In that case, it's likely just the references in the project - if you choose "Open C# project" from the assets menu, it should rebuild the project.
     
  5. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    Also don't do that... Unity is running on a 3.5 runtime equivalent.
     
  6. Mikevincent

    Mikevincent

    Joined:
    Mar 6, 2017
    Posts:
    14
    This is the error I am getting. Nothing works to fix it.

    Build failed. Could not load file or assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The module was expected to contain an assembly manifest.
     
    Last edited: Mar 10, 2017
  7. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    See my previous reply. "Version=4.0.0.0"... you can't do that. You can't target .NET 4.
     
  8. Mikevincent

    Mikevincent

    Joined:
    Mar 6, 2017
    Posts:
    14
    It doesnt matter wich I chose. Still the same issue.
    I should also mention I have enabled .NET 3.5 in Windows.
     
    Last edited: Mar 10, 2017
  9. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    Then you've referenced an assembly that targets .NET 4. System.Web to be exact.
     
  10. Mikevincent

    Mikevincent

    Joined:
    Mar 6, 2017
    Posts:
    14
    I don't even have an option to reference to anything above 3.5. But I am new to all this, I am maybe doing something wrong.
    Even if I start a new project and try to make a C# script I get this error at once.
     
  11. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    Try reinstalling, something is funky, maybe a default project template is messed up but that error means that something is referencing System.Web from .NET 4.x.
     
  12. Mikevincent

    Mikevincent

    Joined:
    Mar 6, 2017
    Posts:
    14
    I have reinstalled now. Without any errors. But the problem is still there :(

    Like this. On a new install of Unity and a new project.



    And as you can see, it is set to .Net 3.5.



    Here is another one having the exact same problem. Seems like no one knows what it is.
    http://answers.unity3d.com/questions/1239502/errors-cs0103-monodevelop.html

    Here you can see what happens when I try to debug code in Monodevelop. I get that System.web error.


    However, if I run it in Unity directly, I get no errors at all. It doesnt make any sense. To me, of course, I have only used Unity for five days now. But I am guessing somthings messed up in my Windows. It's wierd though, I get no problems with anything else. No other programs nor games is getting messed up.

     
    Last edited: Mar 11, 2017
  13. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    My advice... stop using MonoDevlop. It's garbage. Download Visual Studio 2017 Community edition. It's free. And make sure you choose visual studio tools for unity when you install.
     
  14. Mikevincent

    Mikevincent

    Joined:
    Mar 6, 2017
    Posts:
    14
    Yes. I have decided to try that. So annoying to have these kind of errors now. Like its not enough for me to learn both Unity and C# :(
     
  15. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    If I recall, I think I saw someone who mentioned that for some reason the project in Monodevelop was referencing UnityEngine.dll from the wrong Unity version causing it not to load, but I'm not positive. Visual Studio will make you so much happier though.
     
  16. Mikevincent

    Mikevincent

    Joined:
    Mar 6, 2017
    Posts:
    14
    I know now that it works with framework 3.5 as long as I untick "Use msbuild engine". However it gives the error when I try to debug again. But could this be somthing with ms build that is wrong? Can I get a never/other ms build?
     
  17. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    Are you still talking about with MonoDevelop or with Visual Studio?
     
  18. Mikevincent

    Mikevincent

    Joined:
    Mar 6, 2017
    Posts:
    14
    No, Monodevelop. The reason I really want to use it still is because I have found a very good channel on youtube with over 140videos about Unity and C#. I have watched his videos for two days now and from knowing nothing about C# I now know some very bassic foundations. I really want to use Monodevelop for now, since it is what he is using as well, it makes it easier for me as a begginer.
     
  19. Mikevincent

    Mikevincent

    Joined:
    Mar 6, 2017
    Posts:
    14
    Never mind, I found a solution for this.
     
  20. Fehler

    Fehler

    Joined:
    Nov 15, 2016
    Posts:
    1