4

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)
Community
  • 1
  • 1
David Kiff
  • 1,200
  • 2
  • 11
  • 24
  • 1
    "Retrieve the LoaderExceptions property for more information." OK, you've done this, and it says...? – Craig Stuntz Sep 21 '09 at 13:44
  • Ahh.. "OK, you've done this, and it says" I havent actually done that! How do I retrieve the LoaderExceptions, or log what they are? – David Kiff Sep 21 '09 at 13:58
  • 1
    It's a property of the exception, which you can inspect in the debugger: http://msdn.microsoft.com/en-us/library/system.reflection.reflectiontypeloadexception.loaderexceptions%28VS.80%29.aspx – Craig Stuntz Sep 21 '09 at 14:06
  • Yep, found that out just after I posted back! I was missing a thirdparty DLL! Your suggestion actually found the error, so post it as an answer and I will mark it! Thanks alot! – David Kiff Sep 21 '09 at 14:11

3 Answers3

5

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.

Craig Stuntz
  • 125,891
  • 12
  • 252
  • 273
1

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.

Paul Fox
  • 245
  • 2
  • 7
0

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].

jeremy
  • 9,965
  • 4
  • 39
  • 59