Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Cannot use namespace System.Net.Http and others from .NET 4.6

Discussion in 'Experimental Scripting Previews' started by menda90, Jan 9, 2018.

  1. menda90

    menda90

    Joined:
    May 8, 2014
    Posts:
    2
    I am using Unity 2017.3.0f3 and VS 2017 (ver. 15.5.2) with 4.6 .NET enabled.

    When I am trying to use some classes from namespace System.Net.Http Visual Studio telling me that "The type or namespace Http does not exists in namespace System.Net". I tried to add reference directly in *.csproj and it worked fine but - after opening solution again - it is removed. What's more regarding namespace System - I observed that in csproj there are only references like this: https://pastebin.com/xT3jn2kr . The same issue is with System.ServiceModel namespace and others.

    I have no idea how to add other references.
    What I'm doing wrong ? It looks like VS see only some libs from ...lib\mono\4.6-api directory.
     
  2. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,929
    The .csproj files generated by Unity are for output only. Unity never reads them to determine how to build things, so you want to avoid modifying them. Instead, create a file named mcs.rsp in the Assets directory of your Unity project, and add the references there, like this:

    -r:System.Net.Http.dll
     
    codestage, thorwood and menda90 like this.
  3. menda90

    menda90

    Joined:
    May 8, 2014
    Posts:
    2
    Thank you very much, it solves my problem!
     
    JoshPeterson likes this.
  4. roshaantariq

    roshaantariq

    Joined:
    Dec 6, 2017
    Posts:
    32
    I'm having the same problem on Unity 2017.3 Mac
    Tried your above given solution but didn't work out. Any idea how to resolve? Thanks in advance
     
  5. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,929
    When you add the mcs.rsp file to your project, does the error message change at all? Can you provide the specific error message that you see in that case?
     
  6. Mathan1993

    Mathan1993

    Joined:
    May 17, 2019
    Posts:
    5
    Hi, I am using 2018.1 unity version I got some error when I add some plugin error CS1070: The type `System.Net.Http.HttpClient' has been forwarded to an assembly that is not referenced. Consider adding a reference to assembly `System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
    after that I create mcs.rsp file and put it inside the asset folder in the mcs.rsp file I added -r:System.Net.Http.dll this line but I got the same error please help me out.
     
  7. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,929
    I think you may want to name the file csc.rsp instead of mcs.rcp.
     
  8. Mathan1993

    Mathan1993

    Joined:
    May 17, 2019
    Posts:
    5
    I am trying both but I got same error.
     
  9. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,929
    What Scripting Runtime Version and Api Compatibility Level settings are you using?
     
  10. Mathan1993

    Mathan1993

    Joined:
    May 17, 2019
    Posts:
    5
    inside this mcs.rcp txt file to add -r:System.Net.Http.dll this line is enough right after that no need to add any line?
     
  11. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,929
    Yes, that line should be enough.
     
  12. Mathan1993

    Mathan1993

    Joined:
    May 17, 2019
    Posts:
    5
     

    Attached Files:

  13. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,929
    That looks correct - I'm unsure why this does not work. You could try a newer version of Unity - maybe a 2018.4 release.
     
  14. Mathan1993

    Mathan1993

    Joined:
    May 17, 2019
    Posts:
    5
    See this correct root Path right?
     

    Attached Files:

  15. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,929
    Yes, that mcs.rsp or csc.rsp file should be in the Assets directory. Note that mcs.rsp will definitely not work, based on your other settings, the file must be named csc.rsp.
     
  16. TheZombieKiller

    TheZombieKiller

    Joined:
    Feb 8, 2013
    Posts:
    265
  17. PunhoNinja

    PunhoNinja

    Joined:
    Aug 30, 2017
    Posts:
    27
    In my project I solved this by switching from .NET 4x to .NET Standard 2.0
     
  18. Galactus210

    Galactus210

    Joined:
    May 10, 2019
    Posts:
    4
    I have the same problem when trying to use System.IdentityModel.Tokens.Jwt. I'll try to create that file. It has support for .net 4 up to 6, But when has run the command dotnet --info no vscode it says I'm using version 7.x.x I tried to change it to some 6.x.x version, but It didn't work.
     
  19. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,929
    Make sure that you are using a version of System.IdentityModel.Tokens.Jwt built for .NET Standard 2.0 or 2.1.

    I'm not entirely sure what that library is, but Unity does not support anything built for .NET 5 or later, right now.
     
  20. Galactus210

    Galactus210

    Joined:
    May 10, 2019
    Posts:
    4
    Thank you, I changed the version to a older one and it worked