user3017167
user3017167

Reputation: 1

XMLSerializer binaries need to load from other folder apart from AppBase

The application I am using is Application.exe which will run from C:\App\Bin folder. This application internally will load C# COM object binaries from the location C:\App\COMDLL. The COM object is internally using XML Serializers. So we generated those binaries as well for our COM binary using sgen.exe tool. Since these XML Serializer dlls generated by sgen.exe is related to COM object, we kept in C:\App\COMDLL folder. But FusionLoader is searching in the AppBase folder which is C:\App\Bin folder. I cannot move the XML Serializer dlls to AppBase.

Is there any way that I can tell to FusionLoader to load the binaries from C:\App\COMDLL folder instead of C:\App\Bin?

I tried using the "AssemblyResolve" event handler. But this didn't help me much.

Solution #1

The code I have written for AssemblyResolve is like this and it didn't work:

public static void RedirectDependency()
{
  AppDomain.CurrentDomain.AssemblyResolve += ResolveHandler;
  LibLoaded = true;
}
private static bool LibLoaded = false;
public static bool ResolveHandler(object sender, ResolveEventArgs args)
{

  var libName = new AssemblyName(args.Name);
  if(libName.Name.EndsWith("XmlSerializers"))
  {
    var libPath = @"C:\App\COMDLL\COMDLL.XmlSerializers.dll";
    return Assembly.Load(libPath);
  }
  return null;
}

Solution #2

<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
     <probing privatePath="bin;bin2\subbin;bin3"/>
    </assemblyBinding>
 </runtime>
</configuration>

Here as per the documentation PrivatePath should be subdirectories of AppBase. So in our scenario it is outside, so it didn't work.

I don't have any control on APP code. I only have control on COMDLL project. So please suggest accordingly.

Upvotes: 0

Views: 33

Answers (0)

Related Questions