Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to Load C# DLL in ASP Classic

38 views
Skip to first unread message

Lee Fent

unread,
Apr 29, 2003, 12:53:21 PM4/29/03
to
I seem to be having some trouble in creating a COM Component in C#. I
can do it in VB.NET, but I'm doing something wrong for C#. Please
note that I need to load it in ASP, not ASP.NET. If anyone had an
example or a link to a howto or other information.

Thanks,
Lee

Nicholas Paldino [.NET/C# MVP]

unread,
Apr 29, 2003, 1:11:21 PM4/29/03
to
Lee,

Can you post some of your code? There could be a number of things
wrong, from how you attribute your code to how you register the assembly for
COM interop. Can you give a few more details?


--
- Nicholas Paldino [.NET/C# MVP]
- nicholas...@exisconsulting.com

"Lee Fent" <linux_...@hotmail.com> wrote in message
news:7908d1ed.0304...@posting.google.com...

Lee Fent

unread,
Apr 29, 2003, 1:50:57 PM4/29/03
to
"Nicholas Paldino [.NET/C# MVP]" <nicholas...@exisconsulting.com> wrote
in message news:eOMvCLnD...@TK2MSFTNGP10.phx.gbl...
: Lee,

:
: Can you post some of your code? There could be a number of things
: wrong, from how you attribute your code to how you register the assembly
for
: COM interop. Can you give a few more details?

I can, but there really isn't anything there yet, I just created a C# Class
Library, and then added one entry for public int. Should I have to do more
than regasm (filename.dll) to register the Component?

Thanks,
L


Nicholas Paldino [.NET/C# MVP]

unread,
Apr 29, 2003, 1:54:48 PM4/29/03
to
Lee,

The int won't be exposed because it is a field. Only properties and
methods are exposed through COM interop.

Usually, for COM interop, you should place the Guid attribute on your
class, so that when you export, you don't create a new Guid for your COM
object every time. Also, you should apply the ClassInterface attribute as
well, passing in ClassInterfaceType.AutoDispatch (at least for scripting
access, and this is the default).

However, since you are doing this in ASP and it is a late-bound call,
and you are using the program id to get the class, you shouldn't have to do
either. So if you add some methods and properties, it should work.

--
- Nicholas Paldino [.NET/C# MVP]
- nicholas...@exisconsulting.com

"Lee Fent" <laf...@NOSPAM.earthlink.net> wrote in message
news:eh79mfnD...@TK2MSFTNGP12.phx.gbl...

Lee Fent

unread,
Apr 29, 2003, 2:26:14 PM4/29/03
to

"Nicholas Paldino [.NET/C# MVP]" <nicholas...@exisconsulting.com> wrote
in message news:OBq$UjnDDH...@TK2MSFTNGP11.phx.gbl...
: Lee,

:
: The int won't be exposed because it is a field. Only properties and
: methods are exposed through COM interop.
:
: Usually, for COM interop, you should place the Guid attribute on your
: class, so that when you export, you don't create a new Guid for your COM
: object every time. Also, you should apply the ClassInterface attribute as
: well, passing in ClassInterfaceType.AutoDispatch (at least for scripting
: access, and this is the default).
:
: However, since you are doing this in ASP and it is a late-bound call,
: and you are using the program id to get the class, you shouldn't have to
do
: either. So if you add some methods and properties, it should work.
:

Nicholas,
Here is the code I have right now.

using System;

namespace LL
{
public class MyClass
{
public int Respond88()
{
return 88;
}
}
}

Is this what you were thinking should NOT work properly? What should I add
to make it work as expected/desired?

Thanks for all your help,
Lee

Nicholas Paldino [.NET/C# MVP]

unread,
Apr 29, 2003, 2:34:36 PM4/29/03
to
Lee,

This should work properly. I thought you were exposing just a field.

Can you show how you are trying to access this in ASP?

--
- Nicholas Paldino [.NET/C# MVP]
- nicholas...@exisconsulting.com

"Lee Fent" <laf...@NOSPAM.earthlink.net> wrote in message

news:eTvYTznD...@TK2MSFTNGP11.phx.gbl...

Lee Fent

unread,
Apr 29, 2003, 2:46:26 PM4/29/03
to

"Nicholas Paldino [.NET/C# MVP]" <nicholas...@exisconsulting.com> wrote
in message news:OZEZk5nD...@TK2MSFTNGP10.phx.gbl...
: Lee,

:
: This should work properly. I thought you were exposing just a field.
:
: Can you show how you are trying to access this in ASP?

Certainly...

I go into the directory where the LL.dll file is at, then register it via
regasm. It returns a normal exit saying it was successful. Then I use the
following ASP code to create an object from it. Here is the ASP Code I'm
using...

<%
Set myObj = Server.CreateObject("LL.MyClass")
Response.Write "<h1>" & myObj.Respond88 & "</h1>" & vbCRLF
Set myOjb = Nothing
Response.Write "<p>Done!</p>"
%>

But I get an error instead of anything desired. However, the VB.NET
Component works fine (all I do is change the LL.MyClass to the correct
object for the VB Version.

Thanks,
Lee


Nicholas Paldino [.NET/C# MVP]

unread,
Apr 29, 2003, 2:55:48 PM4/29/03
to
Lee,

Ahh, I just remembered. The problem is that it can not find the
assembly most likely, and therefore, can not load the type.

You should place the .NET DLL in a place where it can easily be found.
Because this is ASP that is calling it, you probably should register the
component in the GAC, which will ensure that the runtime can find your
component. Once you do that, you should be fine.


--
- Nicholas Paldino [.NET/C# MVP]
- nicholas...@exisconsulting.com

"Lee Fent" <laf...@NOSPAM.earthlink.net> wrote in message

news:%233dil%23nDDH...@TK2MSFTNGP11.phx.gbl...

Lee Fent

unread,
Apr 29, 2003, 3:05:47 PM4/29/03
to

"Nicholas Paldino [.NET/C# MVP]" <nicholas...@exisconsulting.com> wrote
in message news:OiNDaFo...@TK2MSFTNGP12.phx.gbl...
: Lee,

:
: Ahh, I just remembered. The problem is that it can not find the
: assembly most likely, and therefore, can not load the type.
:
: You should place the .NET DLL in a place where it can easily be found.
: Because this is ASP that is calling it, you probably should register the
: component in the GAC, which will ensure that the runtime can find your
: component. Once you do that, you should be fine.

Can I ask what is an easy to find place? Do you mean like \winnt directory,
or can it be deeper than that, or is one place preferred over another.

Thanks,
Lee


Lee Fent

unread,
Apr 29, 2003, 3:10:59 PM4/29/03
to

"Nicholas Paldino [.NET/C# MVP]" <nicholas...@exisconsulting.com> wrote
in message news:OiNDaFo...@TK2MSFTNGP12.phx.gbl...
: Lee,

:
: Ahh, I just remembered. The problem is that it can not find the
: assembly most likely, and therefore, can not load the type.
:
: You should place the .NET DLL in a place where it can easily be found.
: Because this is ASP that is calling it, you probably should register the
: component in the GAC, which will ensure that the runtime can find your
: component. Once you do that, you should be fine.

I tried in c:\winnt and still got the failure. Should I be using anything
else? I've seen something about an interop, but I read that material and
didn't think it was really needed. Admittedly it was paraphrased garbage,
so I should probably go read on MSDN...

Thanks,
Lee


Nicholas Paldino [.NET/C# MVP]

unread,
Apr 29, 2003, 3:09:01 PM4/29/03
to
Lee,

I don't think that dumping your assembly in the winnt directory is a
good idea. I think that it would be picked up if it was in the system32
directory, but I really can't recommend this. The GAC is made specifically
for this purpose and I would recommend putting it there.

All you have to do is generate a strong name for the assembly, and it
can be placed in the GAC. Not too hard at all.


--
- Nicholas Paldino [.NET/C# MVP]
- nicholas...@exisconsulting.com

"Lee Fent" <laf...@NOSPAM.earthlink.net> wrote in message

news:e02caJoD...@TK2MSFTNGP10.phx.gbl...

mplo...@hotmail.com

unread,
Dec 21, 2004, 9:39:02 PM12/21/04
to
B"H

Great volley of information!

your posts helped me increadibly!

Is there any other way to use C# from asp classic without registering
it in the gac.

I would like to use a C# component in asp classic however this class
that I created uses a com object inside and when I try to give the C# a
strong name it gives me an error that the interop assembly that it
refrences dosent have a strong name.

Dmitriy Lapshin [C# / .NET MVP]

unread,
Dec 22, 2004, 5:59:43 AM12/22/04
to
Hi,

Create the interop assembly with tlbimp.exe, this command-line tool can
produce strong-named interop assemblies if you specify proper keys and give
it the path to the .snk file:

tlbimp someCOM.dll /keyfile:mysecretkey.snk /out:interop.someCOM.dll

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

<mplo...@hotmail.com> wrote in message
news:1103683142.7...@c13g2000cwb.googlegroups.com...

0 new messages