DBoman
DBoman

Reputation: 39

DLL doesn't work when removed from its original location

I'm writing an application in VB.NET, and one of its requirements is to interface with a piece of hardware for making optical power measurements.The company that produced the hardware has DLLs on the machine (which is running either Windows 2000 or XP, depending on which one I look at), and we currently have software which works with those DLLs and is written in VB6.

In addition to interfacing with these machines, the application I am writing also will need to interface with other machines that take measurements using hardware produced by different companies and that uses different calls. Since I don't know that the DLLs will always be there, I decided that I would include them in the program.

I checked in the VB6 project what references were being utilized, and based on those, I transferred the necessary DLLs into the project, loaded them as references, and the project compiled. But it didn't run. I've tried copying or not copying the DLLs, putting them in the same path on the computer I'm using to write the application. Everything I do seems to result in an error that reads:

Could not load file or assembly Interop.Instrument12001b, Version=1.0.0.0, Culture=neutral, Public Key Token = null or one of its dependencies. The system cannot find the file specified.

At this point, I'm not exactly sure what options I have left. I could try loading the DLLs at run-time, but 1) will I be able to ignore the errors to compile the program? and 2) will that work even though I don't know the contents of the DLLs?

EDIT: As it turns out, the entire problems was due to a bug in VS2013 Express. For whatever reason, that particular version of Visual Studio will not create Interop DLLs for .NET 2.0. I was able to get around this by using VS2010 Express instead.

Upvotes: 1

Views: 134

Answers (1)

jmcilhinney
jmcilhinney

Reputation: 54427

When you reference a COM library, VS generates an Interop DLL, which is a .NET assembly that allows your .NET application to interoperate with the COM library. When you deploy, the Interop library must be in the same folder as your EXE but you still need the COM library present and registered on the target machine, otherwise there's nothing to interoperate with.

Upvotes: 2

Related Questions