Please note that the behavior described above is not a limitation of MATLAB. It is in fact expected behavior of the .NET framework.
By default when deserializing an object, the .NET Framework will only look for the required Assembly in the "EXE directory"; it will not even look for already loaded Assemblies.
To make the deserialization work, you will thus need to either:
1. Place myAssembly1.dll in the $MATLABROOT\bin\[win32|win64] directory, or
2. Implement your own ResolveEventHandler for the AppDomain.CurrentDomain.AssemblyResolve event in myAssembly2. So for example in the constructor of myClass2 add:
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
To register your own ResolveEventHandler called CurrentDomain_AssemblyResolve. This CurrentDomain_AssemblyResolve could look like:
System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
System.Reflection.Assembly ayResult = null;
string sShortAssemblyName = args.Name.Split(',')[0];
System.Reflection.Assembly[] ayAssemblies = AppDomain.CurrentDomain.GetAssemblies();
foreach (System.Reflection.Assembly ayAssembly in ayAssemblies)
{
if (sShortAssemblyName == ayAssembly.FullName.Split(',')[0])
{
ayResult = ayAssembly;
break;
}
}
return ayResult;
}
This particular ResolveEventHandler will allow you to use already loaded Assemblies when deserializing objects.
Best Answer