Reputation: 772
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
Upvotes: 6
Views: 5221
Reputation: 763
Reading the DLL file from the specific path directly creates issues so either you have to provide the absolute path or you can just try LoadFrom()
Assembly assembly = Assembly.LoadFrom(@"D:/CodeDLL.dll");
Type t= assembly.GetType("YourNamespace.YourClass");
Upvotes: 0
Reputation: 16848
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");
Upvotes: 7
Reputation: 17719
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.
Upvotes: 1