Coder Perfect

Message of error ‘One or more of the required types could not be loaded. For further information, look up the LoaderExceptions field.’

Problem

Entity Framework, SQL Server 2000, Visual Studio 2008, and Enterprise Library were used to create an application.

It works perfectly locally, however when I try to deploy it to our test environment, I get the following error:

I’m having trouble with Entity Framework; do you have any ideas how to fix it?

Asked by The Light

Solution #1

There is no one-size-fits-all solution to this problem. The trick is to have all of the necessary information to comprehend the situation. A referenced assembly is most likely missing from a dynamically loaded assembly. That assembly must be located in your application’s bin directory.

To figure out what’s missing, use this code.

using System.IO;
using System.Reflection;
using System.Text;

try
{
    //The code that causes the error goes here.
}
catch (ReflectionTypeLoadException ex)
{
    StringBuilder sb = new StringBuilder();
    foreach (Exception exSub in ex.LoaderExceptions)
    {
        sb.AppendLine(exSub.Message);
        FileNotFoundException exFileNotFound = exSub as FileNotFoundException;
        if (exFileNotFound != null)
        {                
            if(!string.IsNullOrEmpty(exFileNotFound.FusionLog))
            {
                sb.AppendLine("Fusion Log:");
                sb.AppendLine(exFileNotFound.FusionLog);
            }
        }
        sb.AppendLine();
    }
    string errorMessage = sb.ToString();
    //Display or log the error based on your application.
}

Answered by Ben Gripka

Solution #2

Setting the Copy Local attribute of my project’s references to true fixed the problem.

Answered by Mentoliptus

Solution #3

I found that deleting the bin/ and obj/ files and rebuilding the solution worked for me.

Update:

You might also try right-clicking the Solution node in the “Solution Explorer” and selecting “Clean Solution,” followed by “Rebuild Solution” (thanks Emre Guldogan)

Answered by Kenny Eliasson

Solution #4

Two possible solutions:

Answered by William Edmondson

Solution #5

As previously stated, it is generally the case that an assembly is not present.

Attach your debugger, hit a breakpoint, and drill down to the ‘LoaderExceptions’ property when you see the exception object to figure out which assembly you’re missing. The missing component should be present.

Hope it helps!

Answered by mkorman

Post is based on https://stackoverflow.com/questions/1091853/error-message-unable-to-load-one-or-more-of-the-requested-types-retrieve-the-l