embedded dependencies can not be resolved when the Assembly is loaded dynamically
buej
Posts: 2 New member
We use SmartAssembly to embed referenced assemblies into a main assembly, so that we only have to deploy this one single main assembly.
Example:
Assembly ABC.dll and Assembly DEF.dll are referenced by the main.dll. That we only have to deploy one main.dll we add ABC.dll and DEF.dll as embedded ressources to one single main.dll with SmartAssembly.
When the resulting main assembly is added into a .Net-project statically everything works fine.
But when the main assembly is loaded dynamically into a customer application (like calling our main.dll from Matlab) the embeded assemblies ABC.dll and DEF.dll can not be resolved anymore.
Following code in a customer application:
Assembly mainAssembly = Assembly.LoadFile("PathToMainAssembly\main.dll");
Type mainClassType = mainAssembly.GetType("main.mainClass");
ConstructorInfo mainClassConstructorInfo = mainClassType .GetConstructor(new Type[] { });
object mainClass= mainClassConstructorInfo?.Invoke(null);
Leads to a System.Exception {System.Reflection.TargetInvocationException because the assembly ABC.dll can not be resolved.
Question:
SmartAssembly states the following
So my understanding is when the main assembly is loaded, then all dependecies should be available for the application domain. But that does not happen.
So what am I missing or missunderstanding?
Is there a simple option i did not check in SmartAssembly?
Is this a generall problem with SmartAssemblies when a combined Assembly is loaded dynamically?
Does anyone knwos a workaround?
Any help would be highly appreciated.
Example:
Assembly ABC.dll and Assembly DEF.dll are referenced by the main.dll. That we only have to deploy one main.dll we add ABC.dll and DEF.dll as embedded ressources to one single main.dll with SmartAssembly.
When the resulting main assembly is added into a .Net-project statically everything works fine.
But when the main assembly is loaded dynamically into a customer application (like calling our main.dll from Matlab) the embeded assemblies ABC.dll and DEF.dll can not be resolved anymore.
Following code in a customer application:
Assembly mainAssembly = Assembly.LoadFile("PathToMainAssembly\main.dll");
Type mainClassType = mainAssembly.GetType("main.mainClass");
ConstructorInfo mainClassConstructorInfo = mainClassType .GetConstructor(new Type[] { });
object mainClass= mainClassConstructorInfo?.Invoke(null);
Leads to a System.Exception {System.Reflection.TargetInvocationException because the assembly ABC.dll can not be resolved.
Question:
SmartAssembly states the following
So my understanding is when the main assembly is loaded, then all dependecies should be available for the application domain. But that does not happen.
So what am I missing or missunderstanding?
Is there a simple option i did not check in SmartAssembly?
Is this a generall problem with SmartAssemblies when a combined Assembly is loaded dynamically?
Does anyone knwos a workaround?
Any help would be highly appreciated.
Tagged:
Answers
The Matlab-method Net.addassembly has problems by resolving the embedde dependecies.
As a workaround i used the .Net - reflection methods in a Matlab-script and not the Matlab-method.
Therefore the problem is "solved".
Jessica Ramos | Product Support Engineer | Redgate Software
Have you visited our Help Center?