How to resolve 'Could not load file or assembly ...

francislfrancisl Member ✭✭

Hi

This question seem to pop often in the forum without any relevant answer. (at least I didn't find any to solve my problem)

I had a working mac app with legacy target + framework 4.7 libraries.

Now I'm trying to switch to a Mac app with the 'modern' target. So I migrated all my libraries to 'netstandard 2.0'.

I tried to cleans, manual deletes of obj/ and recreated my project from zero and copy my code into it.

I always get this error:

Loaded assembly: /c#/ExpenseLogMac/ExpenseLogMac/bin/Debug/Expense Log.app/Contents/MonoBundle/Expense Log.exe
Loaded assembly: /c#/ExpenseLogMac/ExpenseLogMac/bin/Debug/Expense Log.app/Contents/MonoBundle/MultiOSFileLoader.dll
Loaded assembly: /c#/ExpenseLogMac/ExpenseLogMac/bin/Debug/Expense Log.app/Contents/MonoBundle/netstandard.dll [External]
Loaded assembly: /c#/ExpenseLogMac/ExpenseLogMac/bin/Debug/Expense Log.app/Contents/MonoBundle/ExpenseCore.dll
Loaded assembly: /c#/ExpenseLogMac/ExpenseLogMac/bin/Debug/Expense Log.app/Contents/MonoBundle/Xamarin.Mac.dll [External]

Unhandled Exception:
System.TypeLoadException: Could not load type of field 'ExpenseCore.Db:dbConnection' (1) due to: Could not load file or assembly 'SQLiteNetStandard, Version=1.5.1.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. assembly:SQLiteNetStandard, Version=1.5.1.0, Culture=neutral, PublicKeyToken=null type:<unknown type> member:<none>
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeLoadException: Could not load type of field 'ExpenseCore.Db:dbConnection' (1) due to: Could not load file or assembly 'SQLiteNetStandard, Version=1.5.1.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. assembly:SQLiteNetStandard, Version=1.5.1.0, Culture=neutral, PublicKeyToken=null type:<unknown type> member:<none>

If I compile a command line app, all is working fine. I'm not sure how I can resolve or understand this error.

Config: Visual Studio mac

Best Answer

Answers

  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai

    Hmm. It's complaining about an assembly load error. A few things to try:

    • If your XM project is a Full Target Framework then edit the csproj and add 4.7 in the first section.
    • Get more information on the load error with: MONO_LOG_LEVEL=debug MONO_LOG_MASK=asm ./Foo.App/Contents/MacOS/Foo (replace Foo with your app and add a path as needed).
  • francislfrancisl Member ✭✭

    Thanks for the answer. I tried what you said but with no luck.

    I tried rebuilding the whole projects to use pcl or netstandard1.5 + main project using the full target. But no luck

    Then I tried is to add the dependencies to the main project (which doesn't uses it, but the reference does)
    This fixed the issue, but now I have another error

    /Library/Frameworks/Mono.framework/Versions/5.8.1/lib/mono/msbuild/15.0/bin/Microsoft.Common.CurrentVersion.targets(2057,5): warning MSB3276: Found conflicts between different versions of the same dependent assembly. Please set the "AutoGenerateBindingRedirects" property to true in the project file. MMP : warning MM2006: Native library 'odbc32.dll' was referenced but could not be found. 2 Warning(s)

  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai

    So that second error suggests that you have two copies of the same assembly being referenced by mmp.

    Without build logs or an example, I'm not able to do more that make good guesses here.

  • francislfrancisl Member ✭✭

    Yeah, probably because I added the dependencies in the project and also in the references.

    I'll try to make my issue a bit more clear.

    I want to build a desktop native app for Mac and Windows. I have some code that I can reuse. Mainly system configuration file reading and all the models business logic with sqlite database.

    I recreated all my project to use a more recent VS template.

    MacUI - Xamarin.Mac Full Project

    • No Package (if I add sqlite I have the previous conflits error.
    • References: ExpenseCore, MultiOSFileLoader

    ExpenseCore - PCL Project target Framework .net standard 1.5 (for use in win and mac)
    Packages:

    • sqlite-net-pcl version 1.4.118
    • newtonsoft.Json version 11.0.2

    MultiOSFileLoader - PCL Project target Framework .net standard 1.5 (for use in win and mac)

    • No Packages
    • No References
  • francislfrancisl Member ✭✭

    This is the end of the error
    `
    Target CopyFilesToOutputDirectory:
    Copying file from "obj/Debug/Expense Log.exe" to "bin/Debug/Expense Log.exe".
    MacUI -> /workspace/c#/ExpenseSharp/MacUI/bin/Debug/Expense Log.exe
    Copying file from "obj/Debug/Expense Log.pdb" to "bin/Debug/Expense Log.pdb".
    Target _DetectSigningIdentity:
    Detected signing identity:
    Bundle Id: net.francisl.MacUI
    App Id: net.francisl.MacUI
    Target _CopyContentToBundle:
    Creating directory '/workspace/c#/ExpenseSharp/MacUI/bin/Debug/Expense Log.app/Contents/Resources/Main.storyboardc'
    Copying file from '/workspace/c#/ExpenseSharp/MacUI/obj/Debug/ibtool/Main.storyboardc/Info.plist' to '/workspace/c#/ExpenseSharp/MacUI/bin/Debug/Expense Log.app/Contents/Resources/Main.storyboardc/Info.plist'
    Copying file from '/workspace/c#/ExpenseSharp/MacUI/obj/Debug/ibtool/Main.storyboardc/MainMenu.nib' to '/workspace/c#/ExpenseSharp/MacUI/bin/Debug/Expense Log.app/Contents/Resources/Main.storyboardc/MainMenu.nib'
    Copying file from '/workspace/c#/ExpenseSharp/MacUI/obj/Debug/ibtool/Main.storyboardc/NSWindowController-B8D-0N-5wS.nib' to '/workspace/c#/ExpenseSharp/MacUI/bin/Debug/Expense Log.app/Contents/Resources/Main.storyboardc/NSWindowController-B8D-0N-5wS.nib'
    Copying file from '/workspace/c#/ExpenseSharp/MacUI/obj/Debug/ibtool/Main.storyboardc/XfG-lQ-9wD-view-gl9-gI-rbf.nib' to '/workspace/c#/ExpenseSharp/MacUI/bin/Debug/Expense Log.app/Contents/Resources/Main.storyboardc/XfG-lQ-9wD-view-gl9-gI-rbf.nib'
    Target _CompileToNative:
    /Library/Frameworks/Xamarin.Mac.framework/Versions/Current/bin/mmp /verbose /debug /output:/workspace/c#/ExpenseSharp/MacUI/bin/Debug/ "/name:Expense Log" /profile:Xamarin.Mac,Version=v4.5,Profile=Full /arch:x86_64 --http-message-handler=HttpClientHandler /minos=10.11 /nolink /assembly:/Library/.../lib/mono/4.5/mscorlib.dll /assembly:/workspace/c#/MultiOSFileLoader/MultiOSFileLoader/bin/Debug/MultiOSFileLoader.dll /assembly:/Library/.../lib/mono/4.5/System.Core.dll /assembly:/Library/.../lib/mono/4.5/System.dll /assembly:/workspace/c#/ExpenseSharp/ExpenseCore/bin/Debug/test.dll /assembly:/Library/.../lib/reference/full/Xamarin.Mac.dll /assembly:/Library/.../lib/mono/4.5/Facades/Microsoft.Win32.Primitives.dll /assembly:/Library/.../lib/mono/4.5/Facades/Microsoft.Win32.Registry.AccessControl.dll /assembly:/Library/.../lib/mono/4.5/Facades/Microsoft.Win32.Registry.dll /assembly:/Library/.../lib/mono/4.5/Facades/netstandard.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.AppContext.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Collections.Concurrent.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Collections.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Collections.NonGeneric.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Collections.Specialized.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.ComponentModel.Annotations.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.ComponentModel.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.ComponentModel.EventBasedAsync.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.ComponentModel.Primitives.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.ComponentModel.TypeConverter.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Console.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Data.Common.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Data.SqlClient.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Diagnostics.Contracts.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Diagnostics.Debug.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Diagnostics.FileVersionInfo.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Diagnostics.Process.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Diagnostics.StackTrace.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Diagnostics.TextWriterTraceListener.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Diagnostics.Tools.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Diagnostics.TraceEvent.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Diagnostics.TraceSource.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Diagnostics.Tracing.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Drawing.Primitives.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Dynamic.Runtime.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Globalization.Calendars.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Globalization.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Globalization.Extensions.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.IO.Compression.ZipFile.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.IO.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.IO.FileSystem.AccessControl.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.IO.FileSystem.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.IO.FileSystem.DriveInfo.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.IO.FileSystem.Primitives.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.IO.FileSystem.Watcher.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.IO.IsolatedStorage.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.IO.MemoryMappedFiles.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.IO.Pipes.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.IO.UnmanagedMemoryStream.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Linq.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Linq.Expressions.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Linq.Parallel.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Linq.Queryable.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Net.AuthenticationManager.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Net.Cache.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Net.HttpListener.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Net.Mail.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Net.NameResolution.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Net.NetworkInformation.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Net.Primitives.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Net.Requests.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Net.Security.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Net.ServicePoint.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Net.Sockets.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Net.Utilities.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Net.WebHeaderCollection.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Net.WebSockets.Client.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Net.WebSockets.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.ObjectModel.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Reflection.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Reflection.Emit.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Reflection.Emit.ILGeneration.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Reflection.Emit.Lightweight.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Reflection.Extensions.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Reflection.Primitives.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Reflection.TypeExtensions.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Resources.ReaderWriter.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Resources.ResourceManager.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Runtime.CompilerServices.VisualC.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Runtime.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Runtime.Extensions.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Runtime.Handles.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Runtime.InteropServices.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Runtime.InteropServices.RuntimeInformation.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Runtime.InteropServices.WindowsRuntime.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Runtime.Numerics.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Runtime.Serialization.Json.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Runtime.Serialization.Primitives.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Runtime.Serialization.Xml.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Security.AccessControl.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Security.Claims.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Security.Cryptography.Algorithms.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Security.Cryptography.DeriveBytes.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Security.Cryptography.Encoding.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Security.Cryptography.Encryption.Aes.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Security.Cryptography.Encryption.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Security.Cryptography.Encryption.ECDiffieHellman.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Security.Cryptography.Encryption.ECDsa.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Security.Cryptography.Hashing.Algorithms.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Security.Cryptography.Hashing.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Security.Cryptography.Primitives.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Security.Cryptography.ProtectedData.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Security.Cryptography.RandomNumberGenerator.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Security.Cryptography.RSA.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Security.Cryptography.X509Certificates.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Security.Principal.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Security.Principal.Windows.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Security.SecureString.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.ServiceModel.Duplex.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.ServiceModel.Http.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.ServiceModel.NetTcp.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.ServiceModel.Primitives.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.ServiceModel.Security.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.ServiceProcess.ServiceController.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Text.Encoding.CodePages.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Text.Encoding.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Text.Encoding.Extensions.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Text.RegularExpressions.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Threading.AccessControl.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Threading.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Threading.Overlapped.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Threading.Tasks.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Threading.Tasks.Parallel.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Threading.Thread.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Threading.ThreadPool.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Threading.Timer.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.ValueTuple.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Xml.ReaderWriter.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Xml.XDocument.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Xml.XmlDocument.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Xml.XmlSerializer.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Xml.XPath.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Xml.XPath.XDocument.dll /assembly:/Library/.../lib/mono/4.5/Facades/System.Xml.Xsl.Primitives.dll /assembly:/workspace/c#/MultiOSFileLoader/MultiOSFileLoader/bin/Debug/MultiOSFileLoader.dll /assembly:/workspace/c#/ExpenseSharp/ExpenseCore/bin/Debug/test.dll /assembly:/Library/.../lib/reference/full/Xamarin.Mac.dll "/root-assembly:/workspace/c#/ExpenseSharp/MacUI/bin/Debug/Expense Log.exe" /sdkroot:/Applications/Xcode.app/Contents/Developer --cache:/workspace/c#/ExpenseSharp/MacUI/obj/Debug/mmp-cache
    MMP : warning MM2013: Failed to resolve the reference to "SQLite-net, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", referenced in "test, Version=1.0.6677.41775, Culture=neutral, PublicKeyToken=null". The app will not include the referenced assembly, and may fail at runtime.
    MMP : warning MM2013: Failed to resolve the reference to "Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed", referenced in "test, Version=1.0.6677.41775, Culture=neutral, PublicKeyToken=null". The app will not include the referenced assembly, and may fail at runtime.
    MMP : warning MM2006: Native library 'odbc32.dll' was referenced but could not be found.
    Done building target "_CompileToNative" in project "MacUI.csproj".

    Done building project "MacUI.csproj".

    Build succeeded.

    MMP : warning MM2013: Failed to resolve the reference to "SQLite-net, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", referenced in "test, Version=1.0.6677.41775, Culture=neutral, PublicKeyToken=null". The app will not include the referenced assembly, and may fail at runtime.
    MMP : warning MM2013: Failed to resolve the reference to "Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed", referenced in "test, Version=1.0.6677.41775, Culture=neutral, PublicKeyToken=null". The app will not include the referenced assembly, and may fail at runtime.
    MMP : warning MM2006: Native library 'odbc32.dll' was referenced but could not be found.
    3 Warning(s)
    0 Error(s)

    Time Elapsed 00:00:10.48

    ---------------------- Done ----------------------

    Build: 0 errors, 3 warnings

    `

  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai

    So there are two possibilities that come to mind:

    • There is an msbuild somewhere that is preventing your "top level" XM app from seeing the references needed for packaging

      • I tested two configurations I could think of (App -> Lib with nuget, App -> Lib -> Lib with nuget) and both seem to work.
    • There is a project configuration issue

      • Maybe your project references are not setup correctly
      • The multiple different versions errors suggest to me you have multiple projects using different versions of the same nuget library.

    Without the project in question, or even the full build log it is extremely difficult to tell more. The partial log posted suggests we are bundling in mmp and not getting the needed references, but without more I don't know why.

  • francislfrancisl Member ✭✭

    I'll try the nuget package later.

    References seem to be ok (one has to be done manually for MultiOsFileLoader)

    I tried from a fresh clone but I still have the same errors. The dependencies files look a bit diffenrent, but not sure if it could create a conflict.

    here is my repo https://github.com/francisl/expense-sharp, https://github.com/francisl/multi-os-file-loader/blob/master/MultiOSFileLoader/project.json

    Thank you for your help

  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai
    Accepted Answer

    The project helped me nail down the actual issue. It appears to be associated with netstandard libraries, "normal" XM or XI projects don't have this issue.

    https://github.com/xamarin/xamarin-macios/issues/3949

Sign In or Register to comment.