COM Interop - Using a COM object from C#

G

Grant Schenck

Hello,

I'm pretty new to both COM and C#/.Net so assume I'm an idiot and you won't
be far off the mark!

I built an STA COM object using VC 6.0. I build a number of applications
which use the object in C++ & VB 6.0. It all works well.

I was able to write a test application using C# and use my object. All I
had to do was add a reference to the object and then I was free to declare
it.

Specifically, my object shows up in C# as a reference to "STControlLib".

I can then do a:

"using STCONTROLLib;"

I can then declare an instance of an object and use it:

private Ctl STCtl
STCtl.Initialize();

Now, I am working on a larger .Net application developed by another party (I
do have the source for it and am able to build it just fine.)

I wanted to use my COM object from this project so I added a reference.
However, when I go to build it it fails with:

C:\Depot\Source\main\Tools\DesktopSDK\STAPI2\Setup\Setup.vdproj File
'STControl.dll' cannot be shared in Global Assembly Cache folder; only
assemblies are allowed.
C:\Depot\Source\main\Tools\DesktopSDK\STAPI2\Setup\Setup.vdproj Assembly
'Primary output from sforcePhoneBar (Active)' cannot be in the Global
Assembly Cache because its dependency 'Interop.STCONTROLLib'
(Version='1.0.0.0') is not strongly named.

So, I read up on "strong named" issues. Sure enough the C# based solution
I'm building has entries like this:

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

So, I figured I need to do something like:

tlbimp.exe" -keyfile:\depot\source\main\tools\desktopsdk\stapi2\bandobjects.
snk STControl.tlb

That creates a file called

STControlLib.dll

However, the C# build still fails with the same error.

So, I'm thinking that somehow I need to reference the COM object differently
then using a reference...?

Bottom line is I'm looking for a simple process to be able to actually use
the object.

Thanks!
 
N

Nicholas Paldino [.NET/C# MVP]

Grant,

It looks like you are doing everything correctly. I would recommend
dropping the old reference in your VS.NET project, and then re-adding the
reference to the interop DLL, NOT the COM dll (browse for it under the .NET
tab).

Hope this helps.
 
G

Grant Schenck

Wow, that was fast! Thank you very much for your quick response.

OK, I removed the reference to my object and added a reference to the
interop DLL. However, now when I build I get this:

C:\Depot\Source\main\Tools\DesktopSDK\STAPI2\Setup\Setup.vdproj File
'STControl.dll' cannot be shared in Global Assembly Cache folder; only
assemblies are allowed.


This has me scratching my head...

Here is what I did with my .TLB:
tlbimp.exe -keyfile:\depot\source\main\tools\desktopsdk\stapi2\bandobjects.
snk STControl.tlb
Microsoft (R) .NET Framework Type Library to Assembly Converter 1.1.4322.573
Copyright (C) Microsoft Corporation 1998-2002. All rights reserved.

Type library imported to STCONTROLLib.dll
gacutil /if STControlLib.dll

Microsoft (R) .NET Global Assembly Cache Utility. Version 1.1.4322.573
Copyright (C) Microsoft Corporation 1998-2002. All rights reserved.

Assembly successfully added to the cache
regasm STControlLib.dll
Microsoft (R) .NET Framework Assembly Registration Utility 1.1.4322.573
Copyright (C) Microsoft Corporation 1998-2002. All rights reserved.

Types registered successfully
--
Grant Schenck


Nicholas Paldino said:
Grant,

It looks like you are doing everything correctly. I would recommend
dropping the old reference in your VS.NET project, and then re-adding the
reference to the interop DLL, NOT the COM dll (browse for it under the ..NET
tab).

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Grant Schenck said:
Hello,

I'm pretty new to both COM and C#/.Net so assume I'm an idiot and you
won't
be far off the mark!

I built an STA COM object using VC 6.0. I build a number of applications
which use the object in C++ & VB 6.0. It all works well.

I was able to write a test application using C# and use my object. All I
had to do was add a reference to the object and then I was free to declare
it.

Specifically, my object shows up in C# as a reference to "STControlLib".

I can then do a:

"using STCONTROLLib;"

I can then declare an instance of an object and use it:

private Ctl STCtl
STCtl.Initialize();

Now, I am working on a larger .Net application developed by another party
(I
do have the source for it and am able to build it just fine.)

I wanted to use my COM object from this project so I added a reference.
However, when I go to build it it fails with:

C:\Depot\Source\main\Tools\DesktopSDK\STAPI2\Setup\Setup.vdproj File
'STControl.dll' cannot be shared in Global Assembly Cache folder; only
assemblies are allowed.
C:\Depot\Source\main\Tools\DesktopSDK\STAPI2\Setup\Setup.vdproj Assembly
'Primary output from sforcePhoneBar (Active)' cannot be in the Global
Assembly Cache because its dependency 'Interop.STCONTROLLib'
(Version='1.0.0.0') is not strongly named.

So, I read up on "strong named" issues. Sure enough the C# based solution
I'm building has entries like this:

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

So, I figured I need to do something like:

tlbimp.exe" -keyfile:\depot\source\main\tools\desktopsdk\stapi2\bandobjects.
snk STControl.tlb

That creates a file called

STControlLib.dll

However, the C# build still fails with the same error.

So, I'm thinking that somehow I need to reference the COM object
differently
then using a reference...?

Bottom line is I'm looking for a simple process to be able to actually use
the object.

Thanks!
 
N

Nicholas Paldino [.NET/C# MVP]

Grant,

Do you have the option to place the file in the GAC checked in your
project? If so, can you not do that and register it manually, and see what
happens?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Grant Schenck said:
Wow, that was fast! Thank you very much for your quick response.

OK, I removed the reference to my object and added a reference to the
interop DLL. However, now when I build I get this:

C:\Depot\Source\main\Tools\DesktopSDK\STAPI2\Setup\Setup.vdproj File
'STControl.dll' cannot be shared in Global Assembly Cache folder; only
assemblies are allowed.


This has me scratching my head...

Here is what I did with my .TLB:
tlbimp.exe -keyfile:\depot\source\main\tools\desktopsdk\stapi2\bandobjects.
snk STControl.tlb
Microsoft (R) .NET Framework Type Library to Assembly Converter
1.1.4322.573
Copyright (C) Microsoft Corporation 1998-2002. All rights reserved.

Type library imported to STCONTROLLib.dll
gacutil /if STControlLib.dll

Microsoft (R) .NET Global Assembly Cache Utility. Version 1.1.4322.573
Copyright (C) Microsoft Corporation 1998-2002. All rights reserved.

Assembly successfully added to the cache
regasm STControlLib.dll
Microsoft (R) .NET Framework Assembly Registration Utility 1.1.4322.573
Copyright (C) Microsoft Corporation 1998-2002. All rights reserved.

Types registered successfully
--
Grant Schenck


in
message news:[email protected]...
Grant,

It looks like you are doing everything correctly. I would recommend
dropping the old reference in your VS.NET project, and then re-adding the
reference to the interop DLL, NOT the COM dll (browse for it under the .NET
tab).

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Grant Schenck said:
Hello,

I'm pretty new to both COM and C#/.Net so assume I'm an idiot and you
won't
be far off the mark!

I built an STA COM object using VC 6.0. I build a number of applications
which use the object in C++ & VB 6.0. It all works well.

I was able to write a test application using C# and use my object. All I
had to do was add a reference to the object and then I was free to declare
it.

Specifically, my object shows up in C# as a reference to
"STControlLib".

I can then do a:

"using STCONTROLLib;"

I can then declare an instance of an object and use it:

private Ctl STCtl
STCtl.Initialize();

Now, I am working on a larger .Net application developed by another party
(I
do have the source for it and am able to build it just fine.)

I wanted to use my COM object from this project so I added a reference.
However, when I go to build it it fails with:

C:\Depot\Source\main\Tools\DesktopSDK\STAPI2\Setup\Setup.vdproj File
'STControl.dll' cannot be shared in Global Assembly Cache folder; only
assemblies are allowed.
C:\Depot\Source\main\Tools\DesktopSDK\STAPI2\Setup\Setup.vdproj
Assembly
'Primary output from sforcePhoneBar (Active)' cannot be in the Global
Assembly Cache because its dependency 'Interop.STCONTROLLib'
(Version='1.0.0.0') is not strongly named.

So, I read up on "strong named" issues. Sure enough the C# based solution
I'm building has entries like this:

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

So, I figured I need to do something like:

tlbimp.exe" -keyfile:\depot\source\main\tools\desktopsdk\stapi2\bandobjects.
snk STControl.tlb

That creates a file called

STControlLib.dll

However, the C# build still fails with the same error.

So, I'm thinking that somehow I need to reference the COM object
differently
then using a reference...?

Bottom line is I'm looking for a simple process to be able to actually use
the object.

Thanks!
 
G

Grant Schenck

Currently I'm doing it manually (from the command line.)

Is that what you mean?

BTW, I notice that STControl.dll shows up in the "Global Assembly Cache
Folder" as a file along with STCONTROLLib.DLL which is listed as an
assembly.

Should I have to do something to remove STControl.dll???

Thanks,
--
Grant Schenck



Nicholas Paldino said:
Grant,

Do you have the option to place the file in the GAC checked in your
project? If so, can you not do that and register it manually, and see what
happens?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Grant Schenck said:
Wow, that was fast! Thank you very much for your quick response.

OK, I removed the reference to my object and added a reference to the
interop DLL. However, now when I build I get this:

C:\Depot\Source\main\Tools\DesktopSDK\STAPI2\Setup\Setup.vdproj File
'STControl.dll' cannot be shared in Global Assembly Cache folder; only
assemblies are allowed.


This has me scratching my head...

Here is what I did with my .TLB:
tlbimp.exe -keyfile:\depot\source\main\tools\desktopsdk\stapi2\bandobjects ..
snk STControl.tlb
Microsoft (R) .NET Framework Type Library to Assembly Converter
1.1.4322.573
Copyright (C) Microsoft Corporation 1998-2002. All rights reserved.

Type library imported to STCONTROLLib.dll
gacutil /if STControlLib.dll

Microsoft (R) .NET Global Assembly Cache Utility. Version 1.1.4322.573
Copyright (C) Microsoft Corporation 1998-2002. All rights reserved.

Assembly successfully added to the cache
regasm STControlLib.dll
Microsoft (R) .NET Framework Assembly Registration Utility 1.1.4322.573
Copyright (C) Microsoft Corporation 1998-2002. All rights reserved.

Types registered successfully
--
Grant Schenck


in
message news:[email protected]...
Grant,

It looks like you are doing everything correctly. I would recommend
dropping the old reference in your VS.NET project, and then re-adding the
reference to the interop DLL, NOT the COM dll (browse for it under the .NET
tab).

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Hello,

I'm pretty new to both COM and C#/.Net so assume I'm an idiot and you
won't
be far off the mark!

I built an STA COM object using VC 6.0. I build a number of applications
which use the object in C++ & VB 6.0. It all works well.

I was able to write a test application using C# and use my object.
All
I
had to do was add a reference to the object and then I was free to declare
it.

Specifically, my object shows up in C# as a reference to
"STControlLib".

I can then do a:

"using STCONTROLLib;"

I can then declare an instance of an object and use it:

private Ctl STCtl
STCtl.Initialize();

Now, I am working on a larger .Net application developed by another party
(I
do have the source for it and am able to build it just fine.)

I wanted to use my COM object from this project so I added a reference.
However, when I go to build it it fails with:

C:\Depot\Source\main\Tools\DesktopSDK\STAPI2\Setup\Setup.vdproj File
'STControl.dll' cannot be shared in Global Assembly Cache folder; only
assemblies are allowed.
C:\Depot\Source\main\Tools\DesktopSDK\STAPI2\Setup\Setup.vdproj
Assembly
'Primary output from sforcePhoneBar (Active)' cannot be in the Global
Assembly Cache because its dependency 'Interop.STCONTROLLib'
(Version='1.0.0.0') is not strongly named.

So, I read up on "strong named" issues. Sure enough the C# based solution
I'm building has entries like this:

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

So, I figured I need to do something like:
tlbimp.exe" -keyfile:\depot\source\main\tools\desktopsdk\stapi2\bandobjects.
snk STControl.tlb

That creates a file called

STControlLib.dll

However, the C# build still fails with the same error.

So, I'm thinking that somehow I need to reference the COM object
differently
then using a reference...?

Bottom line is I'm looking for a simple process to be able to
actually
use
the object.

Thanks!
 
N

Nicholas Paldino [.NET/C# MVP]

Grant,

Hmm, STControl.dll shouldn't be going into the GAC (it's the COM
component, right?). I would get that out of the GAC (how it got in there is
still beyond me), and then see if it works.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Grant Schenck said:
Currently I'm doing it manually (from the command line.)

Is that what you mean?

BTW, I notice that STControl.dll shows up in the "Global Assembly Cache
Folder" as a file along with STCONTROLLib.DLL which is listed as an
assembly.

Should I have to do something to remove STControl.dll???

Thanks,
--
Grant Schenck



in
message news:[email protected]...
Grant,

Do you have the option to place the file in the GAC checked in your
project? If so, can you not do that and register it manually, and see what
happens?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Grant Schenck said:
Wow, that was fast! Thank you very much for your quick response.

OK, I removed the reference to my object and added a reference to the
interop DLL. However, now when I build I get this:

C:\Depot\Source\main\Tools\DesktopSDK\STAPI2\Setup\Setup.vdproj File
'STControl.dll' cannot be shared in Global Assembly Cache folder; only
assemblies are allowed.


This has me scratching my head...

Here is what I did with my .TLB:
tlbimp.exe -keyfile:\depot\source\main\tools\desktopsdk\stapi2\bandobjects .
snk STControl.tlb
Microsoft (R) .NET Framework Type Library to Assembly Converter
1.1.4322.573
Copyright (C) Microsoft Corporation 1998-2002. All rights reserved.

Type library imported to STCONTROLLib.dll

gacutil /if STControlLib.dll

Microsoft (R) .NET Global Assembly Cache Utility. Version 1.1.4322.573
Copyright (C) Microsoft Corporation 1998-2002. All rights reserved.

Assembly successfully added to the cache

regasm STControlLib.dll
Microsoft (R) .NET Framework Assembly Registration Utility 1.1.4322.573
Copyright (C) Microsoft Corporation 1998-2002. All rights reserved.

Types registered successfully
--
Grant Schenck


"Nicholas Paldino [.NET/C# MVP]" <[email protected]>
wrote
in
message Grant,

It looks like you are doing everything correctly. I would recommend
dropping the old reference in your VS.NET project, and then re-adding the
reference to the interop DLL, NOT the COM dll (browse for it under the
.NET
tab).

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Hello,

I'm pretty new to both COM and C#/.Net so assume I'm an idiot and
you
won't
be far off the mark!

I built an STA COM object using VC 6.0. I build a number of
applications
which use the object in C++ & VB 6.0. It all works well.

I was able to write a test application using C# and use my object. All
I
had to do was add a reference to the object and then I was free to
declare
it.

Specifically, my object shows up in C# as a reference to
"STControlLib".

I can then do a:

"using STCONTROLLib;"

I can then declare an instance of an object and use it:

private Ctl STCtl
STCtl.Initialize();

Now, I am working on a larger .Net application developed by another
party
(I
do have the source for it and am able to build it just fine.)

I wanted to use my COM object from this project so I added a reference.
However, when I go to build it it fails with:

C:\Depot\Source\main\Tools\DesktopSDK\STAPI2\Setup\Setup.vdproj File
'STControl.dll' cannot be shared in Global Assembly Cache folder; only
assemblies are allowed.
C:\Depot\Source\main\Tools\DesktopSDK\STAPI2\Setup\Setup.vdproj
Assembly
'Primary output from sforcePhoneBar (Active)' cannot be in the
Global
Assembly Cache because its dependency 'Interop.STCONTROLLib'
(Version='1.0.0.0') is not strongly named.

So, I read up on "strong named" issues. Sure enough the C# based
solution
I'm building has entries like this:

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

So, I figured I need to do something like:


tlbimp.exe" -keyfile:\depot\source\main\tools\desktopsdk\stapi2\bandobjects.
snk STControl.tlb

That creates a file called

STControlLib.dll

However, the C# build still fails with the same error.

So, I'm thinking that somehow I need to reference the COM object
differently
then using a reference...?

Bottom line is I'm looking for a simple process to be able to actually
use
the object.

Thanks!
 
G

Grant Schenck

Thanks for helping so far...

I'm sure this is a stupid question but how do I remove it from the GAC?

I tried

gacutil /u STControl.dll

but it says:

"No assemblies found that match: STControl.dll"
--
Grant Schenck
http://grantschenck.tripod.com

Nicholas Paldino said:
Grant,

Hmm, STControl.dll shouldn't be going into the GAC (it's the COM
component, right?). I would get that out of the GAC (how it got in there is
still beyond me), and then see if it works.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Grant Schenck said:
Currently I'm doing it manually (from the command line.)

Is that what you mean?

BTW, I notice that STControl.dll shows up in the "Global Assembly Cache
Folder" as a file along with STCONTROLLib.DLL which is listed as an
assembly.

Should I have to do something to remove STControl.dll???

Thanks,
--
Grant Schenck



in
message news:[email protected]...
Grant,

Do you have the option to place the file in the GAC checked in your
project? If so, can you not do that and register it manually, and see what
happens?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Wow, that was fast! Thank you very much for your quick response.

OK, I removed the reference to my object and added a reference to the
interop DLL. However, now when I build I get this:

C:\Depot\Source\main\Tools\DesktopSDK\STAPI2\Setup\Setup.vdproj File
'STControl.dll' cannot be shared in Global Assembly Cache folder; only
assemblies are allowed.


This has me scratching my head...

Here is what I did with my .TLB:


tlbimp.exe -keyfile:\depot\source\main\tools\desktopsdk\stapi2\bandobject
s
.
snk STControl.tlb
Microsoft (R) .NET Framework Type Library to Assembly Converter
1.1.4322.573
Copyright (C) Microsoft Corporation 1998-2002. All rights reserved.

Type library imported to STCONTROLLib.dll

gacutil /if STControlLib.dll

Microsoft (R) .NET Global Assembly Cache Utility. Version 1.1.4322.573
Copyright (C) Microsoft Corporation 1998-2002. All rights reserved.

Assembly successfully added to the cache

regasm STControlLib.dll
Microsoft (R) .NET Framework Assembly Registration Utility 1.1.4322.573
Copyright (C) Microsoft Corporation 1998-2002. All rights reserved.

Types registered successfully
--
Grant Schenck


"Nicholas Paldino [.NET/C# MVP]" <[email protected]>
wrote
in
message Grant,

It looks like you are doing everything correctly. I would recommend
dropping the old reference in your VS.NET project, and then
re-adding
the
reference to the interop DLL, NOT the COM dll (browse for it under the
.NET
tab).

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Hello,

I'm pretty new to both COM and C#/.Net so assume I'm an idiot and
you
won't
be far off the mark!

I built an STA COM object using VC 6.0. I build a number of
applications
which use the object in C++ & VB 6.0. It all works well.

I was able to write a test application using C# and use my object. All
I
had to do was add a reference to the object and then I was free to
declare
it.

Specifically, my object shows up in C# as a reference to
"STControlLib".

I can then do a:

"using STCONTROLLib;"

I can then declare an instance of an object and use it:

private Ctl STCtl
STCtl.Initialize();

Now, I am working on a larger .Net application developed by another
party
(I
do have the source for it and am able to build it just fine.)

I wanted to use my COM object from this project so I added a reference.
However, when I go to build it it fails with:

C:\Depot\Source\main\Tools\DesktopSDK\STAPI2\Setup\Setup.vdproj File
'STControl.dll' cannot be shared in Global Assembly Cache folder; only
assemblies are allowed.
C:\Depot\Source\main\Tools\DesktopSDK\STAPI2\Setup\Setup.vdproj
Assembly
'Primary output from sforcePhoneBar (Active)' cannot be in the
Global
Assembly Cache because its dependency 'Interop.STCONTROLLib'
(Version='1.0.0.0') is not strongly named.

So, I read up on "strong named" issues. Sure enough the C# based
solution
I'm building has entries like this:

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

So, I figured I need to do something like:
tlbimp.exe" -keyfile:\depot\source\main\tools\desktopsdk\stapi2\bandobjects.
snk STControl.tlb

That creates a file called

STControlLib.dll

However, the C# build still fails with the same error.

So, I'm thinking that somehow I need to reference the COM object
differently
then using a reference...?

Bottom line is I'm looking for a simple process to be able to actually
use
the object.

Thanks!
 
G

Grant Schenck

This is weird...

I remove the reference.

Sure enough, the "global assembly cache folder" shows neither STControl.dll
nor STControlLib.dll.

Rebuild and all is happy.

Then I added a reference to STControlLib and when I go back to the cache
folder, both STControl.dll and STControlLib.dll are back! I can't seem to
get one without the other.
--
Grant Schenck


Grant Schenck said:
Thanks for helping so far...

I'm sure this is a stupid question but how do I remove it from the GAC?

I tried

gacutil /u STControl.dll

but it says:

"No assemblies found that match: STControl.dll"
--
Grant Schenck
http://grantschenck.tripod.com

message news:[email protected]...
Grant,

Hmm, STControl.dll shouldn't be going into the GAC (it's the COM
component, right?). I would get that out of the GAC (how it got in
there
is
still beyond me), and then see if it works.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Grant Schenck said:
Currently I'm doing it manually (from the command line.)

Is that what you mean?

BTW, I notice that STControl.dll shows up in the "Global Assembly Cache
Folder" as a file along with STCONTROLLib.DLL which is listed as an
assembly.

Should I have to do something to remove STControl.dll???

Thanks,
--
Grant Schenck



in
message Grant,

Do you have the option to place the file in the GAC checked in your
project? If so, can you not do that and register it manually, and see
what
happens?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Wow, that was fast! Thank you very much for your quick response.

OK, I removed the reference to my object and added a reference to the
interop DLL. However, now when I build I get this:

C:\Depot\Source\main\Tools\DesktopSDK\STAPI2\Setup\Setup.vdproj File
'STControl.dll' cannot be shared in Global Assembly Cache folder; only
assemblies are allowed.


This has me scratching my head...

Here is what I did with my .TLB:
tlbimp.exe -keyfile:\depot\source\main\tools\desktopsdk\stapi2\bandobject s
.
snk STControl.tlb
Microsoft (R) .NET Framework Type Library to Assembly Converter
1.1.4322.573
Copyright (C) Microsoft Corporation 1998-2002. All rights reserved.

Type library imported to STCONTROLLib.dll

gacutil /if STControlLib.dll

Microsoft (R) .NET Global Assembly Cache Utility. Version 1.1.4322.573
Copyright (C) Microsoft Corporation 1998-2002. All rights reserved.

Assembly successfully added to the cache

regasm STControlLib.dll
Microsoft (R) .NET Framework Assembly Registration Utility 1.1.4322.573
Copyright (C) Microsoft Corporation 1998-2002. All rights reserved.

Types registered successfully
--
Grant Schenck


"Nicholas Paldino [.NET/C# MVP]" <[email protected]>
wrote
in
message Grant,

It looks like you are doing everything correctly. I would
recommend
dropping the old reference in your VS.NET project, and then re-adding
the
reference to the interop DLL, NOT the COM dll (browse for it under the
.NET
tab).

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Hello,

I'm pretty new to both COM and C#/.Net so assume I'm an idiot and
you
won't
be far off the mark!

I built an STA COM object using VC 6.0. I build a number of
applications
which use the object in C++ & VB 6.0. It all works well.

I was able to write a test application using C# and use my object.
All
I
had to do was add a reference to the object and then I was free to
declare
it.

Specifically, my object shows up in C# as a reference to
"STControlLib".

I can then do a:

"using STCONTROLLib;"

I can then declare an instance of an object and use it:

private Ctl STCtl
STCtl.Initialize();

Now, I am working on a larger .Net application developed by another
party
(I
do have the source for it and am able to build it just fine.)

I wanted to use my COM object from this project so I added a
reference.
However, when I go to build it it fails with:

C:\Depot\Source\main\Tools\DesktopSDK\STAPI2\Setup\Setup.vdproj File
'STControl.dll' cannot be shared in Global Assembly Cache folder;
only
assemblies are allowed.
C:\Depot\Source\main\Tools\DesktopSDK\STAPI2\Setup\Setup.vdproj
Assembly
'Primary output from sforcePhoneBar (Active)' cannot be in the
Global
Assembly Cache because its dependency 'Interop.STCONTROLLib'
(Version='1.0.0.0') is not strongly named.

So, I read up on "strong named" issues. Sure enough the C# based
solution
I'm building has entries like this:

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

So, I figured I need to do something like:
tlbimp.exe" -keyfile:\depot\source\main\tools\desktopsdk\stapi2\bandobjects.
 
G

Grant Schenck

OK, I finally tried disabling the STControl.dll and that seemed to remove
it. I was then able to build and saw from my trace output that I could call
methods in my object! YAY!!!!!

You were a GREAT help!

What is the "correct" way to handle this? What can I automate to speed this
up? I assume I have to run TLBIMP manually or as part of a build
proceedure. Could I add some kind of pre-build step to my project to insure
I always have the latest implib DLL?

Again, thanks for all your help!
--
Grant Schenck

Grant Schenck said:
This is weird...

I remove the reference.

Sure enough, the "global assembly cache folder" shows neither STControl.dll
nor STControlLib.dll.

Rebuild and all is happy.

Then I added a reference to STControlLib and when I go back to the cache
folder, both STControl.dll and STControlLib.dll are back! I can't seem to
get one without the other.
--
Grant Schenck


Grant Schenck said:
Thanks for helping so far...

I'm sure this is a stupid question but how do I remove it from the GAC?

I tried

gacutil /u STControl.dll

but it says:

"No assemblies found that match: STControl.dll"
--
Grant Schenck
http://grantschenck.tripod.com

message news:[email protected]...
Grant,

Hmm, STControl.dll shouldn't be going into the GAC (it's the COM
component, right?). I would get that out of the GAC (how it got in
there
is
still beyond me), and then see if it works.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Currently I'm doing it manually (from the command line.)

Is that what you mean?

BTW, I notice that STControl.dll shows up in the "Global Assembly Cache
Folder" as a file along with STCONTROLLib.DLL which is listed as an
assembly.

Should I have to do something to remove STControl.dll???

Thanks,
--
Grant Schenck



in
message Grant,

Do you have the option to place the file in the GAC checked in your
project? If so, can you not do that and register it manually, and see
what
happens?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Wow, that was fast! Thank you very much for your quick response.

OK, I removed the reference to my object and added a reference to the
interop DLL. However, now when I build I get this:

C:\Depot\Source\main\Tools\DesktopSDK\STAPI2\Setup\Setup.vdproj File
'STControl.dll' cannot be shared in Global Assembly Cache folder; only
assemblies are allowed.


This has me scratching my head...

Here is what I did with my .TLB:
tlbimp.exe -keyfile:\depot\source\main\tools\desktopsdk\stapi2\bandobject s
.
snk STControl.tlb
Microsoft (R) .NET Framework Type Library to Assembly Converter
1.1.4322.573
Copyright (C) Microsoft Corporation 1998-2002. All rights reserved.

Type library imported to STCONTROLLib.dll

gacutil /if STControlLib.dll

Microsoft (R) .NET Global Assembly Cache Utility. Version 1.1.4322.573
Copyright (C) Microsoft Corporation 1998-2002. All rights reserved.

Assembly successfully added to the cache

regasm STControlLib.dll
Microsoft (R) .NET Framework Assembly Registration Utility 1.1.4322.573
Copyright (C) Microsoft Corporation 1998-2002. All rights reserved.

Types registered successfully
--
Grant Schenck


"Nicholas Paldino [.NET/C# MVP]"
wrote
in
message Grant,

It looks like you are doing everything correctly. I would
recommend
dropping the old reference in your VS.NET project, and then re-adding
the
reference to the interop DLL, NOT the COM dll (browse for it
under
the
.NET
tab).

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Hello,

I'm pretty new to both COM and C#/.Net so assume I'm an idiot and
you
won't
be far off the mark!

I built an STA COM object using VC 6.0. I build a number of
applications
which use the object in C++ & VB 6.0. It all works well.

I was able to write a test application using C# and use my object.
All
I
had to do was add a reference to the object and then I was
free
to
declare
it.

Specifically, my object shows up in C# as a reference to
"STControlLib".

I can then do a:

"using STCONTROLLib;"

I can then declare an instance of an object and use it:

private Ctl STCtl
STCtl.Initialize();

Now, I am working on a larger .Net application developed by another
party
(I
do have the source for it and am able to build it just fine.)

I wanted to use my COM object from this project so I added a
reference.
However, when I go to build it it fails with:
C:\Depot\Source\main\Tools\DesktopSDK\STAPI2\Setup\Setup.vdproj
File
'STControl.dll' cannot be shared in Global Assembly Cache folder;
only
assemblies are allowed.
C:\Depot\Source\main\Tools\DesktopSDK\STAPI2\Setup\Setup.vdproj
Assembly
'Primary output from sforcePhoneBar (Active)' cannot be in the
Global
Assembly Cache because its dependency 'Interop.STCONTROLLib'
(Version='1.0.0.0') is not strongly named.

So, I read up on "strong named" issues. Sure enough the C# based
solution
I'm building has entries like this:

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

So, I figured I need to do something like:
tlbimp.exe" -keyfile:\depot\source\main\tools\desktopsdk\stapi2\bandobjects.
 

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