Caching, Unity, and MSTest Error

Topics: Caching Application Block
Oct 21, 2009 at 9:49 PM
Edited Oct 21, 2009 at 9:50 PM

I've been fighting an issue with the caching application block and the construction of multiple cache managers using the unity block when running under the MS unit test framework.  When I run the unit tests in Visual Studio, run the project itself in a WinForms or Web app, it runs fine.  As soon as I run the tests from the mstest.exe command line option, it fails and gives me an error.  Because Team Build is set up to call MStest through the command line, I cannot get my project to successfully build.  I was able to replicate this on 3 machines -- Windows 7 x86, Windows 2008 R2 x64, and Windows 2008 x64.  I have a complete solution set up that will demonstrate the issue which I can zip and email.

I took the CS-Unity integration example from Enterprise Library 4.1, added a custom file backing store, placed the appropriate config sections in the app config, and successfully tested this using the WinForms app.  Here is the config modifications:

<add name="inFile" type="EntLib.CustomClasses.FileBackingStore, EntLib.CustomClasses" />

Here is the error:

Initialization method CacheTesting.ProductCacheTest.MyTestInitialize threw exception. System.ArgumentException:  System.ArgumentException: The type 'EntLib.CustomClasses.FileBackingStore, EntLib.CustomClasses' cannot be resolved. Please verify the spelling is correct or that the full type name is provided..

Microsoft.Practices.EnterpriseLibrary.Common.Configuration.AssemblyQualifiedTypeNameConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value) in E:\Docs\Code\EnterpriseLibrary4.1\Blocks\Common\Src\Configuration\AssemblyQualifiedTypeNameConverter.cs: line 62
System.ComponentModel.TypeConverter.ConvertFrom(Object value)
Microsoft.Practices.EnterpriseLibrary.Common.Configuration.NameTypeConfigurationElement.get_Type() in E:\Docs\Code\EnterpriseLibrary4.1\Blocks\Common\Src\Configuration\NameTypeConfigurationElement.cs: line 55
TProviderConfigurationBase](IPolicyList policyList, String defaultProviderName, PolymorphicConfigurationElementCollection`1 configurationObjects, IConfigurationSource configurationSource, Func`2 getName) in E:\Docs\Code\EnterpriseLibrary4.1\Blocks\Common\Src\Configuration\Unity\EnterpriseLibraryBlockExtension.cs: line 133
TProviderConfigurationBase](IPolicyList policyList, String defaultProviderName, PolymorphicConfigurationElementCollection`1 configurationObjects, IConfigurationSource configurationSource) in E:\Docs\Code\EnterpriseLibrary4.1\Blocks\Common\Src\Configuration\Unity\EnterpriseLibraryBlockExtension.cs: line 63
Microsoft.Practices.EnterpriseLibrary.Caching.Configuration.Unity.CachingBlockExtension.Initialize() in E:\Docs\Code\EnterpriseLibrary4.1\Blocks\Caching\Src\Caching\Configuration\Unity\CachingBlockExtension.cs: line 40
Microsoft.Practices.Unity.UnityContainerExtension.InitializeExtension(ExtensionContext context)
Microsoft.Practices.Unity.UnityContainer.AddExtension(UnityContainerExtension extension)
Microsoft.Practices.Unity.Configuration.UnityContainerExtensionElement.Configure(IUnityContainer container)
Microsoft.Practices.Unity.Configuration.UnityContainerElement.Configure(IUnityContainer container)
CacheTesting.ProductCacheTest.MyTestInitialize() in E:\Docs\Code\EnterpriseLibrary4.1\Quick Starts\Cache\CS-UnityIntegration\CacheTesting\ProductCacheTest.cs: line 65

Run the VS 2008 Command Prompt and call:

mstest /testcontainer:"c:\temp\test\cachetesting.dll" /resultsfile:"c:\temp\results.trx"

Again, this works when running on a web site, in a Winforms app, or in Visual Studio.  It only happens when running inside the mstest harness.

Any help would be appreciated.  Thanks!


Oct 21, 2009 at 10:53 PM

Got it!  Any assemblies that will plug into the enterprise library must be strong-named when running the unit test, using the testrunconfig settings.