Hi I am new to the C# world. I am having to use it because of a dependency on xceedzip.dll compressed data coming through from a multicast feed.
After hacking together some code for receiving the feed, I am facing a hurdle in invoking this dll.
From what i understand i need to use the "System.Reflection" and invoke the dll.
Currently my source code and the dll reside in the same directory. The code compiles successfully.
Assembly ass = Assembly.Load("XceedZip");
I get the System.BadImageFormatException during runtime:
Could not load file or assembly "XceedZip" or one of its dependecies. The module was expected to contain an assembly manifest.
Please help, Thanks
#
alright thanks to all your responses, i have a working version of the dll following the tlbimp command loaded into my environment. i am facing trouble with the Uncompress method signature. I need to provide a "ref object" and a "out object" as source (compressed) and destination (uncompressed) objects. I tried loading byte arrays into these positions, but it throws me an invalid arguments error. Help on "ref object" and "out object" appreciated ...
problem solved, thanks all
I suspect that this DLL is not a managed assembly but contains native code. The Assembly.Load
should only be used with managed assemblies. If you need to invoke functions from unmanaged code you could use P/Invoke. The process involves in defining a managed wrapper for the unmanaged function that you want to invoke.
For example if you wanted to invoke the MessageBox native function (actually you would never need to do this because there's already a managed equivalent, but it should be fine for the purpose of this demonstration) you could write a wrapper:
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern MessageBoxResult MessageBox(IntPtr hWnd, String text, String caption, int options);
and then invoke it:
MessageBox(IntPtr.Zero, "Text", "Caption", 0);
You will have to do the same thing with the unmanaged function that is contained inside the DLL. You will have to check the documentation to see the exact unmanaged signature which will help you define the managed wrapper.
Try clean the solution then build again. This work perfectly fine to me.
From what i understand i need to use the "System.Reflection" and invoke the dll.
No you don't. You can add a reference to the DLL in your project (since it is a managed assembly), and then use the classes and their methods that are in the DLL.
You'll have received documentation on what classes and methods to use and what parameters they expect.
I wouldn't pay € 640 for the first year and € 320 for each following year for a mere ZIP library, but that's a bit offtopic perhaps.