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

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: <Reference Include="mscorlib"> <HintPath>D:\Program Files\Unity\Edito - Pastebin.com . 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.

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

4 Likes

Thank you very much, it solves my problem!

1 Like

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

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?

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.

I think you may want to name the file csc.rsp instead of mcs.rcp.

I am trying both but I got same error.

What Scripting Runtime Version and Api Compatibility Level settings are you using?

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?

Yes, that line should be enough.

5712442--598153--Screenshot 2020-04-15 at 01.23.55.png

That looks correct - I’m unsure why this does not work. You could try a newer version of Unity - maybe a 2018.4 release.

See this correct root Path right?

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.

Are you using assembly definition files at all? RSP files are ignored by those in versions prior to 2018.3 .

In my project I solved this by switching from .NET 4x to .NET Standard 2.0

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.

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.

Thank you, I changed the version to a older one and it worked