I need some clarification. I have a Reportwriter dll that uses Crystal Reports. It is written in VB6. I have to add this dll to my asp.net project, where it creates an interop dll.

To my understanding, the interop dll is there as an intermediary so that my .net code can speak to the Reportwriter dll.

So do I register the interop dll or do I register the original dll?


Solution 1:

When you write code in VB6, the compiled result is a COM component. COM components provide interfaces, coclasses, structs and enums, which are normally described using a COM type library. However, to consume that COM component in .NET, you need type description in a format that .NET understands - that is, a .NET assembly (since it cannot work with type libraries directly). An interop assembly is therefore just a "converted" COM type library, in a sense that it contains descriptions of interfaces, structs etc that correspond to the same things in a type library.

(The above is somewhat simplified, as interop assembly doesn't have to be produced from a type library - you can hand-code one if you want, for example.)

Contrary to what is often said, an interop assembly doesn't contain any executable code, and it doesn't do any marshalling. It only contains type definitions, and the only place where it can have methods is in interfaces, and methods in interfaces don't have an implementation. Marshaling .NET calls to COM ones is actually done by CLR itself based on type descriptions loaded from interop assemblies - it generates all necessary code on the fly.

Now as to your question. You need to register your COM DLL (the output of your VB6) project - for example, using regsvr32.exe. You shouldn't (in fact, you cannot) register an interop assembly that way, because it's not a COM component - it's just a plain .NET assembly, so you can either put it in the same folder with your .exe/.dll, or put it into GAC, as usual.

Solution 2:

Good answer from Pavel. In addition, beginning with the .NET Framework version 4 you do not need to deploy the interop assembly with your application - http://msdn.microsoft.com/en-us/library/tc0204w0.aspx

Solution 3:

You're correct. The interop DLL wraps the calls to the VB6 component and makes them transparent.

When registering the DLLs on the machine you'll be executing the application on, you still have to register the VB6 DLL. The interop DLL will sit your app's bin folder and Marshal the calls out.