David Kiff
David Kiff

Reputation: 1210

Entity Framework LoaderExceptions Unable to load one or more of the requested types

I have a Web Service that uses the entity framework. When releasing to a test environment, I receive the following error:

"Unable to load one or more of the requested types." - Stack trace below...

The test box has .NET 3.5 SP 1 installed, and I have read a previous post here:

Error message 'Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.'

However the answer does not solve it in my case. I have copied and pasted the working copy off my development machine onto the test box to ensure there is not a problem with debug DLLs (as the answer suggests), however no luck.

Is this a known issue? Ive spent an entire morning trying to debug this!! If anyone knows of a solution, please let me know!

Retrieve the LoaderExceptions property for more information.   at System.Reflection.Module._GetTypesInternal(StackCrawlMark& stackMark)
   at System.Reflection.Assembly.GetTypes()
   at System.Data.Metadata.Edm.ObjectItemCollection.AssemblyCacheEntry.LoadTypesFromAssembly(LoadingContext context)
   at System.Data.Metadata.Edm.ObjectItemCollection.AssemblyCacheEntry.InternalLoadAssemblyFromCache(LoadingContext context)
   at System.Data.Metadata.Edm.ObjectItemCollection.AssemblyCacheEntry.LoadAssemblyFromCache(Assembly assembly, Boolean loadReferencedAssemblies, Dictionary`2 knownAssemblies, Dictionary`2& typesInLoading, List`1& errors)
   at System.Data.Metadata.Edm.ObjectItemCollection.LoadAssemblyFromCache(ObjectItemCollection objectItemCollection, Assembly assembly, Boolean loadReferencedAssemblies)
   at System.Data.Metadata.Edm.ObjectItemCollection.LoadAssemblyForType(Type type)
   at System.Data.Metadata.Edm.MetadataWorkspace.LoadAssemblyForType(Type type, Assembly callingAssembly)
   at System.Data.Objects.ObjectContext.CreateQuery[T](String queryString, ObjectParameter[] parameters)
   at Company.Domain.ICommuicationsEntities.CreateQuery[T](String queryString, ObjectParameter[] parameters)
   at Comany.EntityFrameworkRepository`1.GetQuery()
   at Comany.Repositories.EntityFrameworkRepository`1.GetFiltered(Expression`1 filter, IncludeBuilder`1 includeBuilder)
   at Comany.Repositories.EntityFrameworkRepository`1.GetFiltered(Expression`1 filter)

Upvotes: 4

Views: 12853

Answers (3)

aliwajdan
aliwajdan

Reputation: 1

System.IO.FileNotFoundException: Could not load file or assembly 'System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified. File name: 'System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'

WRN: Assembly binding logging is turned OFF. To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.

Note: There is some performance penalty associated with assembly bind failure logging. To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

Upvotes: 0

Paul Fox
Paul Fox

Reputation: 245

The first line of the stack trace "Retrieve the LoaderExceptions property for more information" is definitely the key to this. You'll need to catch the ReflectionTypeLoadException or cast your general exception.

catch (System.Reflection.ReflectionTypeLoadException ex) {
    ex.LoaderExceptions;
} catch (Exception ex) {
    if (ex is System.Reflection.ReflectionTypeLoadException)
        ((System.Reflection.ReflectionTypeLoadException)ex).LoaderExceptions;
}

You can then check the LoaderExceptions property to find out what DLL references might be missing.

Upvotes: 1

Craig Stuntz
Craig Stuntz

Reputation: 126587

As the top line of the stack says:

Retrieve the LoaderExceptions property for more information.

You can find this by examining the exception in the debugger.

Upvotes: 5

Related Questions