Global Assembly Cache for exporting COM interface

G

Guest

Hello Gurus,

I wrote a .NET application using C# and exported some interface for COM usage.
I did register my application COM interface using the REGASM.exe and some
more code in application.
It all looks fine when looking in the OLE View utility and by looking in the
registry. But when I try to instantiate the COM object using C++ or VB I'm
getting the error "The system cannot find the file specified" (Run-time error
-2147024894 (80070002)).
So I googled it and found that I need also to:
1. Give the assembly a Strong Name.
2. Place the assembly in the Global Assembly Cache (GAC).

My questions are:
(A) How do I vive the assembly a Strong Name and place it in the GAC?
(B) This same application did work using COM to instantiate the object in
earlier .NET Framework version (I think version 1.1). Can it be that it has
been changed for .NET Framework version 2.0?
 
G

Guest

Thanks Michael,

I tried to as the article says but I'm getting some errors when building the
application saying "Assembly generation failed -- Referenced assembly
'AxSMHTMLFormContainer' does not have a strong name Process3"
(I have several of this errors, each for every COM interop I'm using)

'AxSMHTMLFormContainer' is an interop wrapper for COM dll my .NET
application uses.
Process3 is my .NET application.

Please not that my application is a .NET EXE and not a DLL (Process3.exe).

What do I need to do with all COM interop I'm using in my application? or I
how can I fix that?
 
N

Nicholas Paldino [.NET/C# MVP]

Sharon,

First, make sure that you are creating the interfaces that will be
accessed from the unmanaged code through COM in another assembly. You want
to make sure you have a strict separation between your contract (interface)
and the implementation of the contract (class).

When creating your interop wrappers for your active X controls, you will
have to use the AXIMP command line tool to do this. You will have to use
the /keycontainer or /keyfile flags to indicate the key to use to strong
name the assembly.

The reason you have to do this is that in order to strong name your
assembly, every assembly that it references must be strong named.
 
S

Sharon

Hello again,

I'm here again because a new problem arouse concerning this issue.

My C# application is referencing a COM exe (lo.exe) that export an Interface
from another COM dll (lo.dll), and this COM DLL uses the iobjsafe.tlb.

After I gave my application the strong name key, it forces me to assign
strong name key for all the references I'm using.
doing that cause me an error that I can not recover from...

When I generate an interop for the lo.exe it also generate interops for the
lo.dll and for the iobjsafe.tlb. But they two do not contain strong name key,
so I deleted them and generated an interop manually with strong name key form
this two as well using the TlbImp.exe.

After adding all this new interops to my project, I'm getting an error at
run time when trying to access an interface at the lo.dll via the lo.exe like
that:

// This line produces the error below
LanguageObject.CLanguageObject LangObj=
(LanguageObject.CLanguageObject)LW.LOInterface;

LanguageObject is the interop for the lo.dll.
and LW is the interop for lo.exe (LODLLWRAPPER LW= new LODLLWRAPPER();)


The error I'm getting for this line:

Could not load file or assembly 'IObjectSafetyTLB, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=8270d3e194c15991' or one of its dependencies.
The located assembly's manifest definition does not match the assembly
reference. (Exception from HRESULT: 0x80131040)

I have generated a different key file for each COM object I'm referencing
and generated the interop using the TlbImp.exe. for example:
"C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\TlbImp.exe" LO.dll
/keyfile:C:\GACKey\lo.snk /verbose

I managed to get rid of this error only after removing the key file from my
C# application AssemblyInfo.cs.


How can use the strong key name for my C# application in this case as
described above?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top