Reputation: 91
I have a commercial problem in my company we have a project with Wavenis product they give us SDK (DLL files) this application running under compact framework 3.5 Windows mobile 6.1 i used the dll file normally as 1- right click on references 2- add reference 3- browse and select the needed dll 4- Copy the dll to the output
now the company doesn't need to make the SDK Available to be used
i Google it and i got just use
using System.Reflection;
Assembly classLibrary1 = null;
classLibrary1 = Assembly.LoadFrom(filename);
foreach (Type type in classLibrary1.GetTypes())
if (type.GetInterfaces() != null)
return Activator.CreateInstance(type) as IClass1;
but this doesn't work for me if anyone have any idea please help me
I already read this thread Compact Framework C# loading DLL dynamically but didn't help me
Upvotes: 0
Views: 627
Reputation: 67168
The first question I would have is why isn't just Add References
enough? If you have the file at design time, you should be using that mechanism.
Mt second question would be what does "it doesn't work" mean? Do you get an exception? What type of exception? With what message?
Normally these would be under the "comments" of your question, but I'm fairly sure I know the answer.
If you use "Add References" but Studio fails or give you an error message, it's probably because the DLL is a native (i.e. not a .NET assembly) DLL. Trying to load it dynamically is going to fail as well (IIRC with a BadImageFormatException
).
You cannot just add a .NET Reference (through Studio or code) to a native DLL, which is often what 3rd-party hardware vendors supply. If it is a native DLL, you may be able to use P/Invoke to call into the library, provided it has public, non-mangled, C-exported (ie.e. not C++ classes) functions.
Upvotes: 1