0
votes

In my c# application , i am using reflection to load "A.dll" and use its methods to display a collection of records.

In the code i loads the dll from another folder(d:\loader\A.dll) at runtime.

Assembly dataAssembly = null;
dataAssembly = Assembly.LoadFrom("d:\loader\A.dll");

But I miss some column data in the datagridview and found that putting B.dll that was present in same folder where in A.dll was present to my exe execution path resolves the issue. However A.dll doesn't directly refer to B.dll and neither does B.dll show in reference assembiles of dataAssembly.

            dataAssembly.GetReferencedAssemblies()
            .Select(assemblyName => assemblyName.FullName);

Now i have a solution that B.dll is required in the exe execution path to show data but somehow i am restricted from adding it there in production environment.

I don't know what's there inside B.dll but i am 100% sure that i need to load this while accessing A.dll in my application.

Since i am using reflection for loading A.dll , i want to understand how i can handle this situation so that my application is able to find B.dll when it is running A.dll methods.

The folder path for B.dll is the same as that of A.dll .

Sorry and excuse me for the lack of understanding , but if you have any clues or hints , kindly advise.

1
Is what possible to do? Are you saying that the explicitly-loaded DLL A refers to some other DLL B and that this is somehow leading to the wrong result? How? Is it that B isn't present at all? Is A winding up calling code in a different B than you want? So far, this question seems very vague. - Peter Duniho
Yes peter. DLL A is referring to DLL B for showing some data. Now how i found this is like 1)When i point my application output to product installation folder wherein all dll's are present the column values are not empty 2) when i add a direct reference to B dll in my project and run the project the column values are not empty 3) when i don't refer the B dll in my project but put this dll in my application running folder ,still i get no empty values . But if i don't have this DLL anywhere , its giving empty values. - battech
So you are asking whether there's a way to get the results you want, but without DLL B being present? Or do you know where B is, but it's just that it's not being found by .NET? How does DLL A reference B? Is it a regular assembly reference, or is it loading it dynamically? I'm assuming the latter, since normally if it were the former, a missing DLL would cause a run-time exception. - Peter Duniho
yeah. Both DLL A and DLL B will be there in same directory . But i might need to explicitly write a code to load DLL B in the same assembly so that the values come. - battech
Hence i hope if DLL B is somehow loaded in the same assembly where DLL A is loaded , i should get the data. However i am not sure how to go about it . Assembly dataAssembly = null; dataAssembly = Assembly.LoadFrom(Path.Combine("D:\loader", @"A.dll")); - battech

1 Answers

0
votes

I think you need the AppDomain.AssemblyResolve event. Hooking into this event will allow you to specify the path of the dependent assemblies as they are needed.