简体   繁体   中英

The type or namespace name `Xml' does not exist in the namespace `System.Security.Cryptography'

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

VS > Error 11 The type or namespace name Xml' does not exist in the namespace System.Security.Cryptography'. Are you missing an assembly reference?

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

error CS0234: The type or namespace name Xml' does not exist in the namespace System.Security.Cryptography'. Are you missing an assembly reference?

I then tried to directly copy the 'System.Security.dll' inside the asset folder...but still the same message!

What am I doing wrong please? What has to be done? Thanks very much!

Most of the System.Security.Cryptography namespace is excluded from the unity's default .Net 2.0 Subset API. Most probably .Xml is also stripped. So do one of the following:

  1. in Unity click on Ctrl/Cmd + Shift + B to open the build menu, click on player settings . In inspector find API Compatability Level which is set to .Net 2.0 Subset by default. Change it to .Net 2.0 which includes the rest of the previously stripped classes/namespaces.
  2. if the error persists then make sure that the .dll you are copying into Unity is from .net 2.0 framework. Unity can't import libraries targeting framework higher than .net 2.0

This is what is excluded from the unity's Subset API: https://docs.unity3d.com/412/Documentation/ScriptReference/MonoCompatibility.html

Sorry, I couldn't find the current version of this document

EDIT:

as @user2737085 suggested - you'd also have to add mcs.rsp file to your Assets folder. mcs.rsp should be a text file containing the following line:

-r:System.Security.dll

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM