Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.net reflection assembly loading exception

Hi i am loading an assembly as

Assembly testAssembly = Assembly.LoadFile("abc.dll");
Type t = testAssembly.GetType("abc.dll");

but getting an error "Absolute path information is required" however my dll is located in the same folder

like image 788
h_a86 Avatar asked Oct 25 '11 06:10

h_a86


2 Answers

wal has a good point about the GetType method call, but to answer the question:

string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "abc.dll");
Assembly testAssembly = Assembly.LoadFile(path);

If AppDomain.CurrentDomain isn't reliable, then a slightly more convoluted way:

string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "abc.dll");
like image 150
si618 Avatar answered Sep 23 '22 21:09

si618


You don't need to call Assembly.LoadFile if your dll is a .NET dll and in the same folder. You can simply call

Type t = Type.GetType("SomeType");

Are you really trying to get the type 'abc.dll' ? This should be a class name, not an assembly name.

like image 22
wal Avatar answered Sep 23 '22 21:09

wal