1
votes

I have Xamarin Forms application for Android, having my dll as reference. Let's call it A.dll (.net standard 2.0).

I have 2nd dll in user folder (Environment.GetFolderPath(Environment.SpecialFolder.Personal)). Let's call it B.dll (.net standard 2.0 as well)

Fuction in A.dll tries to load class from B.dll using reflection:

var privatePath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
var asmPath = Path.Combine(privatePath, "B.dll");
if (File.Exists(asmPath))
{
    var asm = Assembly.LoadFrom(asmPath);
    foreach (var t in asm.GetTypes()) { }
}

It throws exception in GetTypes() method:

Could not load file or assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies.

Weird thing is, that it works in Debug build during debugging (in emulator), but not when trying Release build (in emulator as well).

The question is, whether such a load of dll is even possible? Why it cannot load 'netstandard' assembly when A.dll is already loaded and it's same version of .net standard? Why it works during debugging, but not release?

1
when you open the Android options for the project and compare the Linker settings for the two configs, are they any different? Do you see any other options that are different? - sisi

1 Answers

1
votes

Thanks to sisi's comment, I've found I have to change Linking option (in Android Options of *.Android project) from 'SDK Assemblies Only' only to 'None'. Now it works.