Can't use System.Security.Cryptography.Xml

Hello,

I have to read a signed xml with a

Using System.Security;
System.Security.Cryptography.Xml.SignedXml signedXml = new System.Security.Cryptography.Xml.SignedXml(lic);

First Unity/VS complained that

So I added a reference to System.Security in Visual Studio (C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Security.dll)…but Unity keeps complaining that

I then tried to directly copy the ‘System.Security.dll’ inside the asset folder (thus removing it from VS references) but there I get a:

What am I doing wrong please? How should I proceed?
Thanks a lot!

Create a text file named “mcs.rsp” in your project Assets folder that contains the following:

-r:System.Security.dll

Thanks for the reply…I did it, restarted Unity and I get a “error CS0006: Metadata file `System.Security.dll’ could not be found” message

Any other idea?

You need to use .NET 2.0 API compatibility level in player settings:

System.Security.dll is not available in .NET 2.0 Subset.

Tautvydas-Zilys,

Thanks so much for your reply! It now works!

May I please ask you:

  • Each time I quit and launch VisualStudio I can see that the reference to ‘System.Security.dll’ is lost
    Why is it so?
  • Removing ‘System.Security.dll’ from the asset folder doesn’t give me the ‘missing assembly’ error that I had from the beginning
    Does it mean that I don’t need to include it anymore?
  • What’s the meaning of this ‘mcs.rsp’ and what does ‘-r’ stand for?

In summary, all seems now to work with NO reference to the dll in VisualStudio and NO copy of the dll in the asset folder!

Would you please help me understand what’s happening here?

Thanks again!!

PS:
How can I fix VisualStudio from removing reference to the dll and then complaining that ‘The type or namespace name Xml' does not exist in the namespace System.Security.Cryptography’. Are you missing an assembly reference?’
Do I have to worry about this or not?

Unity doesn’t look at what you change in VS project. It generates them every time you open unity or add or remove a script.

You definitely don’t need to include System.Security.dll into your project. Unity has its own copy in <EDITOR_INSTALL_DIR>\Data\Mono\lib\mono\2.0. It is not used by default, but “mcs.rsp” file contains a list of extra arguments that should be passed to the compiler. And that’s what it contains: it tells it to reference System.Security.dll.

I’ll try to find out more info about VS use case.

Hi,

We worked on improving the handling on mcs.rsp files, especially regarding references with Visual Studio.

Feel free to send us an email at vstusp[at]microsoft[dot]com to have access to a preview build with this feature.

Regards
Sebastien Lebreton [MSFT]

1 Like

Tautvydas-Zilys,

Thank you for your reply and the time taken to help me!
Thanks to your explanation this subject is now very clear to me!

A big thank you, really!

Hi Tuatvydas,

Unity 2017.2f3 with NET 4.6 backend ( iOS Build and Android Build )

I put this into mcs.rps

-r:System.Data.dll
-r:System.Security.dll

Trying to compile for iOS but I still get at the end of the exporting process

Error building Player: DllNotFoundException: Security

Is that broken win NET 4.6? I mean seems like System.Security is not added.
Thanks, Marek.

I also get the same using NET 4.6. Tried switching to newer version to work around SSL issues with SNI certificates but I can’t get past the NotFoundException.

I’ve added toe rsp file but it doesn’t work, building for iOS and Android

I, too, have this same problem. I’m using 2017.2f3 an NET 4.6.

Can we get a bug report on that?

I was just making repro case and found out that enabling performance reporting service causes this error. After disabling performance reporting, problem goes away. I filed bug report anyways though.

Thanks! Do you have a case #?

Nice catch with the performance reporting. Tautvydas when we can expect fix for that? Will it land in 2017.2?

Case 963348

Thanks for the bug report. Unfortunately I can’t give you any ETAs on when that will be fixed.

1 Like

Has this been fixed in recent unity versions? I’m still on 2017.3.1f1 and don’t see much of a point of updating if it hasn’t.

Which specific issue are you seeing?

I am trying to use the System.Security.Cryptography.ProtectedData class but have been running into many issues.

Firstly, the ProtectedData class is not even located in the default System.Security.Cryptography namescape supplied by unity. So, I go to the Nuget package manager to download the System.Security.Cryptography.ProtectedData dll. After importing that, and placing it in my plugins folder, I still have an error, albeit a different one.

This error states: “The type name ‘ProtectedData’ could not be found in the namespace ‘System.Security.Cryptography’. This type has been forwarded to assembly ‘System.Security, Version=4.0.0.0, Culture=neutral, PubliCKeyToken=b03f5f7f11d50a3a’ Consider adding a reference to that assembly.”

So, I then delete the ProtectedData dll that I placed in the plugins folder, and place the System.Security dll in the plugins folder. After doing that, I get an error stating that it failed to load the assembly System.Security.dll.

I have tried adding the text file with text “-r:System.Security.dll” but that does not fix any of these issues either.

I am using 2017.3.1f1 right now, and would like to stay with this version if it is possible to fix this issue. Is there some fix for this version, or would I have to upgrade to the latest version? Is there even a fix for this in Unity 2018 as of yet?