问题
I worked on registering the Enterprise Library assemblies into the Global Assembly Cache (GAC). I am using version 5.0 of the Enterprise Library that I signed with my own key, and I am using the assemblies in a number of .NET 4.0 applications.
After successfully registering the Enterprise Library assemblies into the GAC, the application started with this message:
The type 'Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling' cannot be resolved. Please verify the spelling is correct or that the full type name is provided.
When I unregister the Enterprise Library assemblies from the GAC, the application returns to normal operating conditions.
What is causing the application to fail when the Enterprise Library assemblies are registered into the GAC?
回答1:
This required quite a bit of hunting to figure out what happened. As it turns out, the Enterprise Library internally uses partial names to load type dynamically. In this case, the Enterprise Library is trying to load Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter dynamically because it appears in the configuration file.
To get around partial name references at runtime, simply enter a qualifyAssembly element in the configuration file (see <qualifyAssembly> Element in the MSDN documentation).
In my case, all I needed to enter was this entry:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<qualifyAssembly partialName="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling"
fullName="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</assemblyBinding>
</runtime>
来源:https://stackoverflow.com/questions/7601885/cannot-resolve-type-runtime-error-after-registering-the-enterprise-library-into