Unity Error: The given assembly name or codebase was invalid

4

I am using the microsoft unity frame work and getting this error:

********** 4/15/2012 9:46:08 AM **********
Inner Exception Type: System.IO.FileLoadException
Inner Exception: The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)
Inner Source: mscorlib
Inner Stack Trace: 
   at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, Boolean loadTypeFromPartialName, ObjectHandleOnStack type)
   at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, Boolean loadTypeFromPartialName)
   at System.RuntimeType.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark)
   at System.Type.GetType(String typeName)
   at Microsoft.Practices.Unity.Configuration.ConfigurationHelpers.TypeResolverImpl.SearchAssemblies(String typeNameOrAlias)
   at Microsoft.Practices.Unity.Configuration.ConfigurationHelpers.TypeResolverImpl.ResolveTypeThroughSearch(String typeNameOrAlias)
   at Microsoft.Practices.Unity.Configuration.ConfigurationHelpers.TypeResolverImpl.ResolveTypeInternal(String typeNameOrAlias)
   at Microsoft.Practices.Unity.Configuration.ConfigurationHelpers.TypeResolverImpl.ResolveType(String typeNameOrAlias, Boolean throwIfResolveFails)
   at Microsoft.Practices.Unity.Configuration.SectionExtensionElement.GetExtensionObjectType()
   at Microsoft.Practices.Unity.Configuration.SectionExtensionElement.DeserializeElement(XmlReader reader, Boolean serializeCollectionKey)
   at Microsoft.Practices.Unity.Configuration.ConfigurationHelpers.DeserializableConfigurationElement.Deserialize(XmlReader reader)
   at Microsoft.Practices.Unity.Configuration.ConfigurationHelpers.ConfigurationElementExtensions.ReadUnwrappedElement[TElementType](ConfigurationElement baseElement, XmlReader reader, DeserializableConfigurationElementCollectionBase`1 elementCollection)
   at Microsoft.Practices.Unity.Configuration.UnityConfigurationSection.DeserializeSectionExtension(XmlReader reader)
   at Microsoft.Practices.Unity.Configuration.UnityConfigurationSection.<.cctor>b__5(UnityConfigurationSection s, XmlReader xr)
   at Microsoft.Practices.Unity.Configuration.ConfigurationHelpers.UnknownElementHandlerMap`1.ProcessElement(TContainingElement parentElement, String elementName, XmlReader reader)
   at Microsoft.Practices.Unity.Configuration.UnityConfigurationSection.OnDeserializeUnrecognizedElement(String elementName, XmlReader reader)
   at System.Configuration.ConfigurationElement.DeserializeElement(XmlReader reader, Boolean serializeCollectionKey)
   at System.Configuration.ConfigurationSection.DeserializeSection(XmlReader reader)
   at Microsoft.Practices.Unity.Configuration.UnityConfigurationSection.DeserializeSection(XmlReader reader)
   at System.Configuration.RuntimeConfigurationRecord.RuntimeConfigurationFactory.CreateSectionImpl(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader)
   at System.Configuration.RuntimeConfigurationRecord.RuntimeConfigurationFactory.CreateSectionWithRestrictedPermissions(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader)
   at System.Configuration.RuntimeConfigurationRecord.CreateSection(Boolean inputIsTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader)
   at System.Configuration.BaseConfigurationRecord.CallCreateSection(Boolean inputIsTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader, String filename, Int32 line)
Exception Type: System.Configuration.ConfigurationErrorsException
Exception: An error occurred creating the configuration section handler for unity: The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047) (C:\Calico\CDT\Dev\CalicoEnergy\EIS.Application.ManinboundedContext.Tests.Integration\bin\Debug\TestResults\Cameron_CAMERON-ENVYPC 2012-04-15 09_46_06\Out\EIS.Application.ManinboundedContext.Tests.Integration.dll.config line 15)
Source: UnityContainer().LoadConfiguration()
Stack Trace: 
   at System.Configuration.BaseConfigurationRecord.EvaluateOne(String[] keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult)
   at System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean getLkg, Boolean getRuntimeObject, Object& result, Object& resultRuntimeObject)
   at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
   at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
   at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
   at System.Configuration.BaseConfigurationRecord.GetSection(String configKey)
   at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName)
   at System.Configuration.ConfigurationManager.GetSection(String sectionName)
   at Microsoft.Practices.Unity.Configuration.UnityContainerExtensions.LoadConfiguration(IUnityContainer container)
   at EIS.Application.ManinboundedContext.Tests.Integration.DemandResponesAppServiceIntegrationTests.InitializeTesting(TestContext context) in C:\Calico\CDT\Dev\CalicoEnergy\EIS.Application.ManinboundedContext.Tests.Integration\DemandResponesAppServiceIntegrationTests.cs:line 48

I know I am missing an assembly. How do I determine what assembly I am missing? I am running mstest project. I have tried the assembly binding viewer with no results. I have added references to all assemblies to my testing project. How do I trouble shoot this? Unity does not tell me what assembly is missing.

unity-container
mstest
asked on Stack Overflow Apr 15, 2012 by Cameron • edited Apr 16, 2012 by Tim

3 Answers

4

I was not able to get fuslogvw to show me which assemplies were missing.

But

By doing a diff using beyond compare between the bin\debug dir of my test project and the directory being created by mstest to execute the test with (\TestResults\My Machine Name 2012-04-23 09_22_24\Out) I was able to identify the missing assemblies.

I was not aware that mstest was building to a new directory and not picking up some of the types being injected. Once I figured out MSTest was creating its own dir I was able to do the diff to find the issue.

FYI. It was enterprise library types that were missing.

answered on Stack Overflow Apr 23, 2012 by Cameron
1

Use the fuslogvw.exe from the SDK to find out where the binder is looking when trying to find the requested assemblies. See http://blogs.msdn.com/b/suzcook/archive/2003/05/29/57120.aspx and http://www.neovolve.com/post/2010/05/28/Resolving-assembly-bind-failures-on-a-server.aspx for some info.

answered on Stack Overflow Apr 16, 2012 by Rory Primrose • edited Jun 14, 2013 by Tom Cerul
0

Please make sure, that you have added asseblly references of the missing assebply in the project where your web.config file exists.

I was missing this. I already have added those assembly references in the project which was using Unity to resolve the class, but missed to add it in the parent project where configuration file was located. This has resolved my problem.

answered on Stack Overflow Mar 7, 2013 by user1451020

User contributions licensed under CC BY-SA 3.0