Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Unity 3-无法解析类型名称或别名xxxx_C#_.net_Xml_Configuration_Unity Container - Fatal编程技术网

C# Unity 3-无法解析类型名称或别名xxxx

C# Unity 3-无法解析类型名称或别名xxxx,c#,.net,xml,configuration,unity-container,C#,.net,Xml,Configuration,Unity Container,我已经在这里通读了几个相关的问题,但我仍然无法让我的UnityXML配置正常工作 这是我的配置文件 <?xml version="1.0" encoding="utf-8"?> <unity xmlns="http://schemas.microsoft.com/practices/2010/unity"> <assembly name="System.Security" /> <namespace name="System.Securi

我已经在这里通读了几个相关的问题,但我仍然无法让我的UnityXML配置正常工作

这是我的配置文件

<?xml version="1.0" encoding="utf-8"?>
<unity xmlns="http://schemas.microsoft.com/practices/2010/unity">
    <assembly name="System.Security" />
    <namespace name="System.Security.Cryptography" />
    <container name="Default">
        <register type="HashAlgorithm" mapTo="SHA256Managed" />
        <register type="SymmetricAlgorithm" mapTo="AesCryptoServiceProvider" />
    </container>
</unity>

我得到的错误信息是

无法解析类型名或别名AESCryptServiceProvider。 请检查配置文件并验证此类型名称

HashAlgorithm正在正常解析,而不是AES提供程序

在我的项目中引用了System.Security程序集,如果我这样做,对称算法类型可以解决

IUnityContainer Container = new UnityContainer ();

Container.RegisterType<SymmetricAlgorithm, AesCryptoServiceProvider> ();
IUnityContainer Container=newunitycontainer();
Container.RegisterType();
。。。但是如果可能的话,我想把配置排除在代码之外

有人能帮我解决这个问题吗?

问题在于
系统安全性
中没有。您将在
System.Core
程序集中找到它

因此,您需要修复unity配置,以包括该程序集,如下所示:

<unity xmlns="http://schemas.microsoft.com/practices/2010/unity">
  <namespace name="System.Security.Cryptography" />
  <assembly name="System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
  <container name="Default">
    <register type="HashAlgorithm" mapTo="SHA256Managed" />
    <register type="SymmetricAlgorithm" mapTo="AesCryptoServiceProvider" />
  </container>
</unity>

)。当使用其名称加载类型时,大多数情况下,您都需要完全限定的名称,例如,请参见中关于类型名称的备注:

要获取的类型的程序集限定名。请参阅AssemblyQualifiedName。如果类型位于当前执行的程序集中或Mscorlib.dll中,则提供由其命名空间限定的类型名就足够了