Search code examples
mono

"Could not load file or assembly or one of its dependencies" in Mono but not in native .NET


The same executable that uses some proprietary DLLs, after being compiled with Mono, works natively on Windows, but doesn't work using Mono on Windows or Linux.

hello_onbase.cs:

using Hyland.Unity;
using Hyland.Types;
using System;

public class HelloOnBase
{
    public static void Main(string[] args)
    {
        var auth = Application.CreateOnBaseAuthenticationProperties("app_server_url", "user", "password", "data_source");
        var app = Application.Connect(auth);
        Console.WriteLine ("OnBase connection successful!");
    }
}

Proprietary DLLs Hyland.Unity.dll and Hyland.Types.dll are in the same directory as the file hello_onbase.cs. Unfortunately I can't share those files since they're the IP of our vendor, I'm very sorry...

I opened Mono x64 Command Prompt in Windows and compiled the file successfully with Mono:

C:\Users\apanasenco\git\docaccess\services\doc\onbase>csc -r:Hyland.Types.dll -r:Hyland.Unity.dll hello_onbase.cs
Microsoft (R) Visual C# Compiler version 3.6.0-4.20224.5 (ec77c100)
Copyright (C) Microsoft Corporation. All rights reserved.

The executable Mono compiled executes just fine natively in Windows:

C:\Users\apanasenco\git\docaccess\services\doc\onbase>hello_onbase.exe
OnBase connection successful!

However, running the executable with mono causes the following error:

C:\Users\apanasenco\git\docaccess\services\doc\onbase>mono hello_onbase.exe

Unhandled Exception:
System.TypeLoadException: Could not set up parent class, due to: Could not set up parent class, due to: Could not load type of field 'Hyland.Types.EncryptedServiceObject:_scp' (2) due to: Could not load file or assembly 'Hyland.Security.Legacy, Version=0.2.2.0, Culture=neutral, PublicKeyToken=e169a6a902bdd7a6' or one of its dependencies. assembly:C:\Users\apanasenco\git\docaccess\services\doc\onbase\Hyland.Types.dll type:EncryptedServiceObject member:(null) assembly:C:\Users\apanasenco\git\docaccess\services\doc\onbase\Hyland.Types.dll type:ParameterizedObject member:(null)
  at Hyland.Unity.OnBaseAuthenticationProperties.ConnectNormalMode (Hyland.Unity.Services.IConnectServiceAccess connectServiceAccess) [0x00000] in <80532c8c2f134d0daba2ee8243cb5721>:0
  at Hyland.Unity.OnBaseAuthenticationProperties.ConnectAndGetIntegrationApplicationOptions (Hyland.Unity.Services.IConnectServiceAccess connectServiceAccess) [0x00020] in <80532c8c2f134d0daba2ee8243cb5721>:0
  at Hyland.Unity.Application.Connect (Hyland.Unity.AuthenticationProperties connectProperties) [0x00020] in <80532c8c2f134d0daba2ee8243cb5721>:0
  at HelloOnBase.Main (System.String[] args) [0x0001b] in <73b1617068fa44e792f55cccc5974b17>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeLoadException: Could not set up parent class, due to: Could not set up parent class, due to: Could not load type of field 'Hyland.Types.EncryptedServiceObject:_scp' (2) due to: Could not load file or assembly 'Hyland.Security.Legacy, Version=0.2.2.0, Culture=neutral, PublicKeyToken=e169a6a902bdd7a6' or one of its dependencies. assembly:C:\Users\apanasenco\git\docaccess\services\doc\onbase\Hyland.Types.dll type:EncryptedServiceObject member:(null) assembly:C:\Users\apanasenco\git\docaccess\services\doc\onbase\Hyland.Types.dll type:ParameterizedObject member:(null)
  at Hyland.Unity.OnBaseAuthenticationProperties.ConnectNormalMode (Hyland.Unity.Services.IConnectServiceAccess connectServiceAccess) [0x00000] in <80532c8c2f134d0daba2ee8243cb5721>:0
  at Hyland.Unity.OnBaseAuthenticationProperties.ConnectAndGetIntegrationApplicationOptions (Hyland.Unity.Services.IConnectServiceAccess connectServiceAccess) [0x00020] in <80532c8c2f134d0daba2ee8243cb5721>:0
  at Hyland.Unity.Application.Connect (Hyland.Unity.AuthenticationProperties connectProperties) [0x00020] in <80532c8c2f134d0daba2ee8243cb5721>:0
  at HelloOnBase.Main (System.String[] args) [0x0001b] in <73b1617068fa44e792f55cccc5974b17>:0

Mono version on Windows and Linux: 6.12.0

The older versions of these two files used to work on Mono before... I'm wondering if there's some Mono setting I can tweak to relax some assembly checks to match native .NET behavior?


Solution

  • Turns out the vendor does provide a file Hyland.Security.Legacy.dll that was alluded to in the error message. Including that file resolved the issue.