could not load dll or one of its dependency

我們知道dotnet的dll的依賴dll,要麼加入GAC要麼就要在exe的目錄下才能反射加載,放到path目錄下都不行。

不過網上通過這種加載搜索的方式可以實現非exe目錄的依賴dll加載。

a. My C# program will load a dll (which is dynamic), for now let's take a.dll (similarly my program will load more dll like b.dll, c.dll, etc....).

b. My program will invoke a method "Onstart" inside a.dll (it's constant for all the dll).

I am able to achieve the above 2 cases by reflection mechanism.

The problem is

a. If my a.dll have any reference say xx.dll or yy.dll, then when I try to Invoke

OnStart method of a.dll from my program. I am getting "could not load dll or one of its dependency". See the code snippet


typically i am getting error on the line "object obj = Activator.CreateInstance(tp);" this is because a.dll has reference of xx.dll, but in my program i don't have the reference of xx.dll. Also, I cannot have the reference of xx.dll in my program because a.dll is a external assembly and can have any reference on it's own.

Basically, in the AssemblyResolve event, you need to load the referenced assemblies manually.


Not the best code, but should give you a general idea, I hope.

I do, however, agree that plugin-dlls should be packaged for complete, dependancy-less use. If they are allowed to load assemblies you don't have control over, then who knows what might happen.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章