strange error -- COM DLL is not installed correctly?

G

Guest

Hello everyone,


I am migrating my C++ COM server to managed code (C# COM server). I am using
the same client to use the same COM class in COM server. The C++ version COM
server works properly, but when using the C# COM server, there is a strange
error indicating dll is not installed correctly (data link error).

I have tried to delete the DLL at the same time to test whether the DLL
could be found correctly when the client is invoking the DLL, and Windows
system reports error message indicating that the DLL is in use -- so I think
the DLL should be able to found. Why COM client will report the strange error
indicating the DLL is not installed properly (C# COM server)?

Any check list to solve this issue?


thanks in advance,
George
 
A

Alberto Poblacion

George said:
I am migrating my C++ COM server to managed code (C# COM server). I am
using
the same client to use the same COM class in COM server. The C++ version
COM
server works properly, but when using the C# COM server, there is a
strange
error indicating dll is not installed correctly (data link error).

I have tried to delete the DLL at the same time to test whether the DLL
could be found correctly when the client is invoking the DLL, and Windows
system reports error message indicating that the DLL is in use -- so I
think
the DLL should be able to found. Why COM client will report the strange
error
indicating the DLL is not installed properly (C# COM server)?

How did you install the DLL? When a COM DLL is developed with C# you have
to use REGASM instead of REGSVR32.
 
G

Guest

Thanks Alberto,


If I select Register for COM in build page of a C# project in Visual Studio
2005, do I still need to use Regasm to register?


regards,
George
 
A

Alberto Poblacion

George said:
If I select Register for COM in build page of a C# project in Visual
Studio
2005, do I still need to use Regasm to register?

No, Visual Studio does that automatically. You only have to use Regasm if
you want to install the dll manually in a different computer.

Another detail that you may need: The COM consumer needs to be able to
find the DLL at runtime. With an ordinary COM DLL written in a language such
as C++, it is sufficient to register the DLL for the clients to find it,
since the path to the dll is stored in the Registry. This is not enough with
a managed (C#) dll. In this case, the dll needs to be found by the .Net
runtime. One way to achieve this is to copy the dll to the same folder as
the program that is consuming it. Another way is to add a Strong Name and
install the dll into the Global Assembly Cache.
 
G

Guest

Thanks Alberto!


I am very interested in this method,

--------------------
add a Strong Name and
install the dll into the Global Assembly Cache.
--------------------

But I have never done this before, could you let me know how to configure in
more details?


regards,
George
 
A

Alberto Poblacion

George said:
I am very interested in this method,

--------------------
add a Strong Name and
install the dll into the Global Assembly Cache.
--------------------

But I have never done this before, could you let me know how to configure
in
more details?

First you need to generate a Key File. You open a Visual Studio Command
Prompt (start->Visual studio->tools) and you enter this command:
sn -k MyKeys.snk

This wil generate the file "MyKeys.snk". You only have to do this once.
Then you store MyKeys.snk in a safe place and you can use it to sign all
your programs.

Next: In the project of the dll that you want to sign with a Strong Name,
find the file AssemblyInfo.cs, open it, and you will find an attribute
called AssemblyKeyFile. There you add the path of your .snk file:

[assembly: AssemblyKeyFile(@"path\MyKeys.snk")]

You should also modify the AssemblyVersion and enter a "fixed" version
number such as "1.0.0.0" instead of the existing "auto-increment" version
number that contains an asterisk.

That's it. You now compile your dll and it will receive a Strong Name. If
you get a "cryptographic error" while compiling, that means that you wrote a
wrong path to the snk file.

Now that the assembly has a Strong Name, you can install it to the GAC.
One way to do this is to execute the command "gacutil -i mylibrary.dll".
Another way is to open c:\Windows\Assembly in Windows Explorer, and then
drag and drop your DLL to that location.

Once you have done this, any .net executable that wants to load your dll
will be able to find it, regardles of the location of the .exe in the
filesystem.
 
G

Guest

Thanks Alberto,


I have followed your steps to register dll into GAC. I am wondering how to
check from GAC that my dll is actually registered?


regards,
George

Alberto Poblacion said:
George said:
I am very interested in this method,

--------------------
add a Strong Name and
install the dll into the Global Assembly Cache.
--------------------

But I have never done this before, could you let me know how to configure
in
more details?

First you need to generate a Key File. You open a Visual Studio Command
Prompt (start->Visual studio->tools) and you enter this command:
sn -k MyKeys.snk

This wil generate the file "MyKeys.snk". You only have to do this once.
Then you store MyKeys.snk in a safe place and you can use it to sign all
your programs.

Next: In the project of the dll that you want to sign with a Strong Name,
find the file AssemblyInfo.cs, open it, and you will find an attribute
called AssemblyKeyFile. There you add the path of your .snk file:

[assembly: AssemblyKeyFile(@"path\MyKeys.snk")]

You should also modify the AssemblyVersion and enter a "fixed" version
number such as "1.0.0.0" instead of the existing "auto-increment" version
number that contains an asterisk.

That's it. You now compile your dll and it will receive a Strong Name. If
you get a "cryptographic error" while compiling, that means that you wrote a
wrong path to the snk file.

Now that the assembly has a Strong Name, you can install it to the GAC.
One way to do this is to execute the command "gacutil -i mylibrary.dll".
Another way is to open c:\Windows\Assembly in Windows Explorer, and then
drag and drop your DLL to that location.

Once you have done this, any .net executable that wants to load your dll
will be able to find it, regardles of the location of the .exe in the
filesystem.
 
G

Guest

Thanks Alberto!


I have followed your steps to register my dll into GAC. I am wondering how
to know whether the dll is correctly and actually registered into GAC? Any
tools to check?


regards,
George

Alberto Poblacion said:
George said:
I am very interested in this method,

--------------------
add a Strong Name and
install the dll into the Global Assembly Cache.
--------------------

But I have never done this before, could you let me know how to configure
in
more details?

First you need to generate a Key File. You open a Visual Studio Command
Prompt (start->Visual studio->tools) and you enter this command:
sn -k MyKeys.snk

This wil generate the file "MyKeys.snk". You only have to do this once.
Then you store MyKeys.snk in a safe place and you can use it to sign all
your programs.

Next: In the project of the dll that you want to sign with a Strong Name,
find the file AssemblyInfo.cs, open it, and you will find an attribute
called AssemblyKeyFile. There you add the path of your .snk file:

[assembly: AssemblyKeyFile(@"path\MyKeys.snk")]

You should also modify the AssemblyVersion and enter a "fixed" version
number such as "1.0.0.0" instead of the existing "auto-increment" version
number that contains an asterisk.

That's it. You now compile your dll and it will receive a Strong Name. If
you get a "cryptographic error" while compiling, that means that you wrote a
wrong path to the snk file.

Now that the assembly has a Strong Name, you can install it to the GAC.
One way to do this is to execute the command "gacutil -i mylibrary.dll".
Another way is to open c:\Windows\Assembly in Windows Explorer, and then
drag and drop your DLL to that location.

Once you have done this, any .net executable that wants to load your dll
will be able to find it, regardles of the location of the .exe in the
filesystem.
 
A

Alberto Poblacion

George said:
I have followed your steps to register my dll into GAC. I am wondering how
to know whether the dll is correctly and actually registered into GAC? Any
tools to check?

You can use "gacutil -l" to list the assemblies in the GAC.
You can also use Windows Explorer to navigate to C:\Windows\Assembly.
This will display the contents of the GAC.
 

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