views:

120

answers:

3

Hi all,

I have 2 .net dll's which I expose to COM using REGASM. In order to simplify referencing within a COM client I would like to make these into one file.

I have tried converting both files to IDL and then copying the contents of the Library section of one into the other and then compiling back to .tlb with MIDL. This works fine for the TypeDefs within the second IDL however it seems to fail when it comes to the interfaces I copied in. OLE/COM viewer can see the interface definitions but when I try and use the TLB via COM it cant find the interfaces that I copied in.

I wanted to make sure before I spend too much time on this, that it is actually possible to meagre IDL's in this way.

+1  A: 

Could you use ILMerge to first combine the .NET assemblies and then use REGASM on the resulting assembly?

ILMerge is a utility for merging multiple .NET assemblies into a single .NET assembly. It works on executables and DLLs alike and comes with several options for controlling the processing and format of the output.

Mitch Wheat
Hi Mitch, this would seem to be a good option, however when merging the dll's I get an error "An exception occurred during merging: ILMerge.Merge: The assembly 'Sim.Common' was not merged in correctly. It is still listed as an external reference in the target assembly. at ILMerging.ILMerge.Merge() at ILMerging.ILMerge.Main(String[] args)"I am guessing that this is because the first dll references the second one in the source code. However this reference is required.
Jambobond
Ok I used the /closed option which fixed the above problem, however now I cant seem to use regasm on the new dll I created. I get an error "RegAsm : error RA0000 : The given path's format is not supported."Any Ideas?
Jambobond
@Jambobond: I've never combined 2 .NET assemblies and then tried to regasm them.
Mitch Wheat
I think you will need to make sure your dll is in the same folder as your tlb and that your other assemblies that are not in the GAC are present in the folder when you run the regasm.
Mitch Wheat
"make sure your dll is in the same folder as your tlb" but RegAsm generates the tlb? "your other assemblies that are not in the GAC" They are not. "are present in the folder when you run the regasm" They are :)
Jambobond
+1  A: 

I don't see an obvious way this would fail. You said you merged the library sections but you didn't say you copy-pasted the interface declarations from the other .idl. That would be an obvious, but unlikely, explanation.

One failure mode is when the client app uses the type library to marshal interface pointers across apartment boundaries or out-of-process. That however requires registry keys in HKCR\Interfaces. .NET doesn't create them, you'd have to do that yourself. You'd know if you did, not much of an explanation either.

Hans Passant
@Hans Passant Sorry for the poor explanation, my understanding of IDL and COM is pretty limited (which you prolly knew since you answer all my questions about it). You are right I did do a straight copy and paste without adding reg entries, I had hoped that since the GUID's of the other assembly's would have been registered that it would have resolved the registry for me?
Jambobond
Agreed, that should work, as long as you used Regasm.exe on both DLLs. But the registration doesn't have anything to do with the use of the type library by the compiler. No clue, you ought to put the .tlb and the .idl files on a file sharing service so we can take a look at it.
Hans Passant
A: 

Ok so it turns out that the issues I was experiencing were not related to merging the idl's.

If you wish to merge to idl's you can do so by simply copying the content of a library section in one idl into another. Then run midl on the merged file to turn it into a tlb.

Jambobond

related questions