Get error "Unable to load one or more of the requested types." when building Select Console App

Discussions concerning general integration topics.

Moderator: Phil Barton

Post Reply
BobRichards
Posts: 1376
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Get error "Unable to load one or more of the requested types." when building Select Console App

Post by BobRichards »

The full error is probably: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information. How do I fix it?
Bob Richards, Senior Software Developer, SoftPro
BobRichards
Posts: 1376
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: Get error "Unable to load one or more of the requested types." when building Select Console App

Post by BobRichards »

When .NET loads an assembly (DLL or EXE) into your app domain, it must also ask the assembly what other assemblies it needs to function (external dependencies). If it has any external dependencies then the .NET loader will load those assemblies also. (Be aware that individual components within the assemblies will be loaded on demand but that doesn't matter here since the loader is only looking for assembly files.)

The hint that something went wrong is the exception message: Retrieve the LoaderExceptions property for more information. Here is a way you can find what file the .NET loader couldn't find. In the example here, we are a Select Console App and are putting our first call to Select in a try/catch block. Within the block, put a breakpoint on the brace immediately after the line starting with "var loaderException = ". Restart the app in debug mode and wait for the exception to be trapped.

Code: Select all

try
{
    IOrderStore os = ss.GetService<IOrderStore>();
}
catch(Exception ex)
{
    Exception inner = ex.InnerException;
    while (inner != null)
    {
        if (inner is ReflectionTypeLoadException)
        {
            var loaderException = ((ReflectionTypeLoadException)inner).LoaderExceptions;
        }
        inner = inner.InnerException;
    }
}
The code will break with the the "loaderException" of type "System.IO.FileNotFoundException". When you inspect this exception, you will see that filename that the .NET loader couldn't find in the "FileName" property. Note that the FileName will not include the DLL or EXE file extension. The file on disk will be one or the other.

Once you find the filename, you will add it to your project References.
Bob Richards, Senior Software Developer, SoftPro
BobRichards
Posts: 1376
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: Get error "Unable to load one or more of the requested types." when building Select Console App

Post by BobRichards »

Now that you know how to find the necessary files in .NET apps in general, let me tell you that the missing file is probably: Microsoft.ApplicationInsights.DLL

The requirement for this assembly was added several versions ago and is used by Select. The Visual Studio Project templates installed by the Select SDK have not been modified to include it by default yet. Just add the version that is in the Select Client folder to your project References and all will be fine. (And if not, you know how to find any other missing file.)
Bob Richards, Senior Software Developer, SoftPro
toddsou
Posts: 75
Joined: Wed Jul 25, 2012 9:39 am

Re: Get error "Unable to load one or more of the requested types." when building Select Console App

Post by toddsou »

Thanks, Bob.

My issue was two-fold:
That is, the ex.InnerException.InnerException.InnerException.LoaderExceptions array had two entries-
Microsoft.ApplicationInsights, version 2.1.0.0
IronPython, version 2.7.0.40

I assume the SDK provides neither, so I'll pull the matching versions down from a public repository.

Regards,
Todd
BobRichards
Posts: 1376
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: Get error "Unable to load one or more of the requested types." when building Select Console App

Post by BobRichards »

If you are writing a Console app, then all libraries will be in the Select Client app folder at "C:\Program Files (x86)\SoftPro\Select". (Unless you installed to a non-default library.)
Bob Richards, Senior Software Developer, SoftPro
Post Reply