By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,759 Members | 1,273 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,759 IT Pros & Developers. It's quick & easy.

using a C# class library in both COM and .NET code?

P: n/a
i have a C# class library full of objects.

the immediate need was to instantiate these objects in classic ASP, so
i inherit ServicedComponent and build the project with COM Interop set
to true. and the objects work in classic ASP just fine.

however, we are slowly introducing ASP.NET code, and i would like to
make use of the same objects. however, i don't want to use the old COM
method of Server.CreateObject(). i would like to use Import/using
statements to gain access to everything in the namespace.

but when i try add a reference to the .NET application for the class
library, it says:

A reference to 'MyLibrary' could not be added. Converting the type
library to a .NET assembly failed. Type library RCObjects was exported
from a CLR assembly and can not be re-imported as a CLR assembly.

it seems amusing that it can import a COM library into .NET, so long as
the COM library wasn't originally coded in .NET.

so my question is, what's the most appropriate way to make this library
available to both the classic ASP and ASP.NET code?

thanks for any help,

jason

Nov 17 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Jason,

If you want to use this library in .NET code, then why not just add a
reference to the dll itself, and not to the TLB that you export so that you
can use it in COM?

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"jason" <ia****@yahoo.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
i have a C# class library full of objects.

the immediate need was to instantiate these objects in classic ASP, so
i inherit ServicedComponent and build the project with COM Interop set
to true. and the objects work in classic ASP just fine.

however, we are slowly introducing ASP.NET code, and i would like to
make use of the same objects. however, i don't want to use the old COM
method of Server.CreateObject(). i would like to use Import/using
statements to gain access to everything in the namespace.

but when i try add a reference to the .NET application for the class
library, it says:

A reference to 'MyLibrary' could not be added. Converting the type
library to a .NET assembly failed. Type library RCObjects was exported
from a CLR assembly and can not be re-imported as a CLR assembly.

it seems amusing that it can import a COM library into .NET, so long as
the COM library wasn't originally coded in .NET.

so my question is, what's the most appropriate way to make this library
available to both the classic ASP and ASP.NET code?

thanks for any help,

jason

Nov 17 '05 #2

P: n/a
huh! manually browsing for the .DLL did the trick. how will this be
resolved during runtime though, i wonder?

thanks though. i can at least start coding with this help

Nov 17 '05 #3

P: n/a
Jason,

What you are doing is two completely different things. When you
registered through COM (which you did incorrect, btw, you need to call
regsvcs to register assemblies for COM+, I believe), it created a TLB and
then registered that. .NET uses a completely different mechanism to find
assemblies.

Chances are your assembly is in the GAC as a result of the COM
registration, so I wouldn't worry. If it isn't, then place a copy of the
..NET assembly in the bin subdirectory of your ASP.NET application, and it
will find it just fine.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"jason" <ia****@yahoo.com> wrote in message
news:11*********************@g47g2000cwa.googlegro ups.com...
huh! manually browsing for the .DLL did the trick. how will this be
resolved during runtime though, i wonder?

thanks though. i can at least start coding with this help

Nov 17 '05 #4

P: n/a
ok, that makes sense. i remember reading a little blurb about the .NET
library in the /bin subdirectory thing. that should be no problem.

what makes you think i misregistered the COM library, though? i never
even mentioned how i did it. i use the COM+ MMC to register the
com-wrapped library, and it works just fine. what's wrong with that
method?

Nov 17 '05 #5

P: n/a
Jason,

If you have a class that derives from ServicedComponent, you need to
call the regsvcs utility to correctly register it with COM+ so that it can
be used by COM components AND by .NET. Registering the TLB through COM+
isn't sufficient if you want to get the same benefits in your .NET code.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"jason" <ia****@yahoo.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
ok, that makes sense. i remember reading a little blurb about the .NET
library in the /bin subdirectory thing. that should be no problem.

what makes you think i misregistered the COM library, though? i never
even mentioned how i did it. i use the COM+ MMC to register the
com-wrapped library, and it works just fine. what's wrong with that
method?

Nov 17 '05 #6

P: n/a
ahh, i see! i appreciate the information. i read the MSDN articles on
the regsvcs utility, and ran the following:

regsvcs /appname:ExistingMyApplication MyLibrary.dll

and it did register the components successfully in COM+ ... however,
none of the ASP classic pages can successfully execute a
Server.CreateObject now that i've used that utility.

is there something i'm missing to successfully register the COM
portion? the articles say that the TLB is created and registered by
default. or perhaps if it is more efficient, do you know of other good
references for the regsvcs.exe utility?

Nov 17 '05 #7

P: n/a

"jason" <ia****@yahoo.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
ahh, i see! i appreciate the information. i read the MSDN articles on
the regsvcs utility, and ran the following:

regsvcs /appname:ExistingMyApplication MyLibrary.dll

and it did register the components successfully in COM+ ... however,
none of the ASP classic pages can successfully execute a
Server.CreateObject now that i've used that utility.

is there something i'm missing to successfully register the COM
portion? the articles say that the TLB is created and registered by
default. or perhaps if it is more efficient, do you know of other good
references for the regsvcs.exe utility?


What error is returned by the CreateObject call?
Is your assembly stored in the GAC?
Did you try to call your method from a simple script using VBScript or
JScript?

Willy.


Nov 17 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.