Paul Turner
Paul Turner

Reputation: 39615

TypeLoadException from Mono

I'm trying to get Mono 3.4.0 working with some of the Microsoft OWIN components. I've started testing on Windows, but when my application handles an HTTP request, I get the following exception:

System.TypeLoadException: Could not load type 'Microsoft.Owin.Security.AuthenticateResult' from assembly 'Microsoft.Owin, Version=2.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.

The application is being compiled using Visual Studio as a standard .NET assembly with the expectation that it should run on the Mono runtime.

I added the Microsoft.Owin NuGet package to a console application and managed to reproduce the problem to the following code:

class Program
{
    static void Main(string[] args)
    {
        var instance = new AuthenticateResult(
            null,
            new AuthenticationProperties(),
            new AuthenticationDescription());

        Console.WriteLine(instance.GetType().AssemblyQualifiedName);
    }
}

Running this in .NET, the application starts normally and prints out the type information. If it's run through Mono, the application prints out the exception and fails.

Further, this code works in both .NET and Mono:

class Program
{
    static void Main(string[] args)
    {
        var type = typeof(AuthenticateResult);
        Console.WriteLine(type.AssemblyQualifiedName);
    }
}

I've tested with a number of types from the Microsoft.Owin assembly, with similar results. If I load the type using the typeof operator before it's needed, Mono doesn't raise the exception, instead throwing an exception trying to load a different type (presumably just the next one the code needed).

Why am I getting this strange behaviour when running in Mono? Is there something I have to specify on the command-line to load assemblies as I would expect from the .NET CLR? Is there anything I can do to get further information about why the type failed to be loaded?

Upvotes: 3

Views: 1051

Answers (1)

jageall
jageall

Reputation: 366

It looks like the type load error is caused by one of the types used by the types you reference in your code, not the types you actually use.

if you run set MONO_LOG_LEVEL=debug before running your program, you will see the following in your output:

Mono: The class System.Security.Claims.ClaimsIdentity could not be loaded, used in mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

Checking this against mono status page we can see that none of the System.Security.Claims namespace has been implemented in Mono yet.

Upvotes: 3

Related Questions