trying to add class library dll to COM+ component package

J

jason

i have a c# class library that is being compiled with the "Register for
COM Interop" flag set to "True." it compiles just fine. however, when i
go into the Component Services administrative tool and attempt to add
the .dll to an application, i get the following message:

"One or more files do not contain components or type libraries. These
components cannot be installed."

i'm sure there's a step i'm missing, so how do i alter what i'm doing
so that i can access my class library through a COM interface model
(i.e. in ASP classic)

thanks for any help

jason
 
W

Willy Denoyette [MVP]

jason said:
i have a c# class library that is being compiled with the "Register for
COM Interop" flag set to "True." it compiles just fine. however, when i
go into the Component Services administrative tool and attempt to add
the .dll to an application, i get the following message:

"One or more files do not contain components or type libraries. These
components cannot be installed."

i'm sure there's a step i'm missing, so how do i alter what i'm doing
so that i can access my class library through a COM interface model
(i.e. in ASP classic)

thanks for any help

jason

..NET types need to derive from ServicedComponent and be registered using
regsvcs.exe - Check this chapter "Writing Serviced Components" in the
Framework developers guide.

Willy.
 
J

jason

thanks so much willy, that's all it took. the class is now deriving
form ServicedComponent. i also added strong naming, and the class
library registers in the COM+ utility just fine.

but i have one more question if you don't mind.

the class library has a base class which derives from
ServicedComponent. that baseclass has a public abstract method, like
the following example:

using System.EnterpriseServices;

namespace MyNS
{
public abstract class MyBaseClass : ServicedComponent
{
public MyBaseClass () { }
public abstract bool MyAbstractMethod (int nValue);
}
}

and a sample derived class might look like the following example:

namespace MyNS
{
public class MyClass : MyBaseClass
{
public MyClass() { }
public string MyString = "Hi";
public override bool MyAbstractMethod(int nValue)
{
if (nValue == 1) return true;
return false;
}
}
}

however when i instantiate this object in the COM environment of
classic ASP code, like follows:

dim oWebsite, bReturn
set oMyClass = Server.CreateObject("MyNS.MyClass")
Response.Write(oMyClass.MyString)
bReturn = oMyClass.MyAbstractMethod(1)

the instantiation works fine, the Response.Write of MyString works
fine, but when i try to access that override method, i get the
following message:

Invalid procedure call or argument: 'MyAbstractMethod'

is there something special you have to do to abstract methods to expose
them in serviced components?

thanks again,

jason
 
W

Willy Denoyette [MVP]

jason said:
thanks so much willy, that's all it took. the class is now deriving
form ServicedComponent. i also added strong naming, and the class
library registers in the COM+ utility just fine.

but i have one more question if you don't mind.

the class library has a base class which derives from
ServicedComponent. that baseclass has a public abstract method, like
the following example:

using System.EnterpriseServices;

namespace MyNS
{
public abstract class MyBaseClass : ServicedComponent
{
public MyBaseClass () { }
public abstract bool MyAbstractMethod (int nValue);
}
}

and a sample derived class might look like the following example:

namespace MyNS
{
public class MyClass : MyBaseClass
{
public MyClass() { }
public string MyString = "Hi";
public override bool MyAbstractMethod(int nValue)
{
if (nValue == 1) return true;
return false;
}
}
}

however when i instantiate this object in the COM environment of
classic ASP code, like follows:

dim oWebsite, bReturn
set oMyClass = Server.CreateObject("MyNS.MyClass")
Response.Write(oMyClass.MyString)
bReturn = oMyClass.MyAbstractMethod(1)

the instantiation works fine, the Response.Write of MyString works
fine, but when i try to access that override method, i get the
following message:

Invalid procedure call or argument: 'MyAbstractMethod'

is there something special you have to do to abstract methods to expose
them in serviced components?

thanks again,

jason

Should work. Can you try using this simple script?

' test.vbs
Set x = Wscript.CreateObject("MyNS.MyClass")
Wscript.Echo x.MyAbstractMethod(10)

Willy.
 
J

jason

i will definitely give it a shot as soon as i figure out how to use
this COM+ MMC. i created an application in COM+ to host the dll
specifically so that the file could be unlocked without having to
reboot the server, but it seems to be locked anyway, after disabling
the application in the COM+ MMC. so once i figure out how to get COM+
to work like it should, i'll give that script a try and post back the
results. thanks,

jason
 
J

jason

you're right, that DID work. so i took a closer look at the function
that isn't working, here is the actual (non-example) function
signature:

public override bool LoadByID(int nID, SqlConnection oConn)

i'm guessing the problem is with the second parameter, SqlConnection
oConn. this class library was originally built to work with ASP.NET
pages, but some pages are still in ASP classic. the data type of the
database connection that the classic pages create are of course not
SqlConnection. i'm not even sure if that's a class that CAN be
instantiated through COM.

i will try to see if i can instantiate an SqlConnection object in ASP
classic. failing that, i will have to just create a backward compatible
set of methods that work with the standard ADO object set. thanks for
walking through this with me.
 

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