Unity 3 - 无法解析类型名称或别名 xxxx
Unity 3 - The type name or alias xxxx could not be resolved
我已经阅读了这里的几个相关问题,但我似乎仍然无法让我的 Unity XML 配置正常工作。
这是我的配置文件...
<?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>
我收到的错误消息是...
The type name or alias AesCryptoServiceProvider could not be resolved.
Please check your configuration file and verify this type name.
HashAlgorithm 正在正常解析,而不是 AES 提供程序。
我的项目中引用了System.Security程序集,SymmetricAlgorithm类型可以解析了.. .
IUnityContainer Container = new UnityContainer ();
Container.RegisterType<SymmetricAlgorithm, AesCryptoServiceProvider> ();
...但如果可能的话,我希望将配置保留在代码之外。
谁能帮我解决这个问题?
问题是 AesCryptoServiceProvider
不在 System.Security
中。您会在 System.Core
程序集中找到它。
因此您需要修复您的统一配置以包含该程序集,如:
<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>
注意:您需要提供程序集的全名(包括版本、文化和令牌)。这是因为 Unity 只会将命名空间和程序集名称与类型名称连接起来,然后它会检查结果类型是否存在(检查 documentation here). When loading types using its name, most of the times you will need the fully qualified name, see for example the remark about the type name in Type.GetType
:
The assembly-qualified name of the type to get. See AssemblyQualifiedName. If the type is in the currently executing assembly or in Mscorlib.dll, it is sufficient to supply the type name qualified by its namespace
我已经阅读了这里的几个相关问题,但我似乎仍然无法让我的 Unity XML 配置正常工作。
这是我的配置文件...
<?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>
我收到的错误消息是...
The type name or alias AesCryptoServiceProvider could not be resolved. Please check your configuration file and verify this type name.
HashAlgorithm 正在正常解析,而不是 AES 提供程序。
我的项目中引用了System.Security程序集,SymmetricAlgorithm类型可以解析了.. .
IUnityContainer Container = new UnityContainer ();
Container.RegisterType<SymmetricAlgorithm, AesCryptoServiceProvider> ();
...但如果可能的话,我希望将配置保留在代码之外。
谁能帮我解决这个问题?
问题是 AesCryptoServiceProvider
不在 System.Security
中。您会在 System.Core
程序集中找到它。
因此您需要修复您的统一配置以包含该程序集,如:
<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>
注意:您需要提供程序集的全名(包括版本、文化和令牌)。这是因为 Unity 只会将命名空间和程序集名称与类型名称连接起来,然后它会检查结果类型是否存在(检查 documentation here). When loading types using its name, most of the times you will need the fully qualified name, see for example the remark about the type name in Type.GetType
:
The assembly-qualified name of the type to get. See AssemblyQualifiedName. If the type is in the currently executing assembly or in Mscorlib.dll, it is sufficient to supply the type name qualified by its namespace