Cannot instantiate .NET Class Library

  • Thread starter Thread starter Patrick
  • Start date Start date
P

Patrick

1) I have created a very very simple .NET class library as follows appended
at the end of this post
2) I have registered the code as follows:
regasm /tlb:testInterop.tlb testinterop.dll
3) I could browse this testInterop.tlb with even the object browser in
Microsoft Word 2003 VBA!
4) If I try to invoke the code from VBScript/ASP as follows:
--------Start of VBScript Code-------

Dim objTest
Set objTest = CreateObject("testInterop.Test")
objTest.DoSomething
--------End of VBScript Code-------

4.1) I get error as follows:
------start of error------
Microsoft VBScript runtime error '800a01ad'
ActiveX component can't create object: 'testInterop.Test'

/testInterop.asp, line 4

------end of error------



I can't think the code could get any simpler any yet it's not working!!
Please help!!!

--------------------------Start of .NET Code--------------------------
using System;
using System.Runtime.InteropServices;
using System.IO;


namespace MyOrg.web.publications
{


[ClassInterface(ClassInterfaceType.AutoDual)]
public class Test
{
public Test()
{
//
// TODO: Add constructor logic here
//
}

public void DoSomething()
{
StreamWriter fileStream;
fileStream = File.CreateText("c:\\temp\\test.txt");
fileStream.WriteLine("Test");
fileStream.Flush();
fileStream.Close();
}

}
}
--------------------------End of .NET Code--------------------------
 
I assume you have not given the assembly a strong name and installed it in the GAC. The problem is that the COM loader gets pointed to mscoree.dll (the runtime) and then passes mscoree.dll the CLSID of the COM object (via DllGetClassObject) mscoree goes to the registry and looks under that CLSID and finds the assembly name, class anme and a bunch of other stuff. Now the problem is mscoree doesn't know where your class is so it tries to load it by name and fails dismally as the assembly isn't in the APPBASE (or subdirectory) of the executing process (cscript.exe or inetinfo.exe I guess in these scenarios).

Just to show things working, change your regasm command line to

regasm /tlb:testInterop.tlb testInterop.dll /codebase

You will get a warning about the assembly not having a strong name but just ignore that for now. Hopefully enverything will now work (regasm puts the path to the assembly - the CODEBASE - under the CLSID as well so mscoree knows where to find it).

In reality however, you should strong name and GAC the interop assembly

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog

nntp://news.microsoft.com/microsoft.public.dotnet.framework/<[email protected]>

1) I have created a very very simple .NET class library as follows appended
at the end of this post
2) I have registered the code as follows:
regasm /tlb:testInterop.tlb testinterop.dll
3) I could browse this testInterop.tlb with even the object browser in
Microsoft Word 2003 VBA!
4) If I try to invoke the code from VBScript/ASP as follows:
--------Start of VBScript Code-------

Dim objTest
Set objTest = CreateObject("testInterop.Test")
objTest.DoSomething
--------End of VBScript Code-------

4.1) I get error as follows:
------start of error------
Microsoft VBScript runtime error '800a01ad'
ActiveX component can't create object: 'testInterop.Test'

/testInterop.asp, line 4

------end of error------



I can't think the code could get any simpler any yet it's not working!!
Please help!!!

--------------------------Start of .NET Code--------------------------
using System;
using System.Runtime.InteropServices;
using System.IO;


namespace MyOrg.web.publications
{


[ClassInterface(ClassInterfaceType.AutoDual)]
public class Test
{
public Test()
{
//
// TODO: Add constructor logic here
//
}

public void DoSomething()
{
StreamWriter fileStream;
fileStream = File.CreateText("c:\\temp\\test.txt");
fileStream.WriteLine("Test");
fileStream.Flush();
fileStream.Close();
}

}
}
--------------------------End of .NET Code--------------------------



---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.770 / Virus Database: 517 - Release Date: 27/09/2004



[microsoft.public.dotnet.framework]
 
This is weird.....

I tried exactly what you did:
1) I could do the following in Microsoft Word 2003 Macro (after adding a
reference to testInterop.tlb):
------------------------start of functioning VBA
Code------------------------
Dim objTest As New testInterop.test
objTest.DoSomething
------------------------end of functioning VBA Code------------------------
2.1) When I try the following ASP code on Windows XP Professional SP1 with
IIS5.1
-----------------------------startof ASP Code-----------------------------
<%
Dim objTest
Set objTest = CreateObject("testInterop.test")
objTest.DoSomething
%>
------------------------------end of ASP Code------------------------------
2.2) I still get the following error
--------------------------------start of ASP
error--------------------------------
Microsoft VBScript runtime error '800a01ad'

ActiveX component can't create object: 'testInterop.test'

/testInterop.asp, line 3
--------------------------------end of ASP
error--------------------------------
3) If I put the ASP code in VBScript, I get the following error:
----------------------------start of VBScript
Error---------------------------
C:\Temp\testactivex.vbs(2, 5) Microsoft VBScript runtime error: ActiveX
componen
t can't create object: 'testInterop.test'
----------------------------end of VBScript Error---------------------------

Why is this and how could this be resolved?

Richard Blewett said:
I assume you have not given the assembly a strong name and installed it in
the GAC. The problem is that the COM loader gets pointed to mscoree.dll (the
runtime) and then passes mscoree.dll the CLSID of the COM object (via
DllGetClassObject) mscoree goes to the registry and looks under that CLSID
and finds the assembly name, class anme and a bunch of other stuff. Now the
problem is mscoree doesn't know where your class is so it tries to load it
by name and fails dismally as the assembly isn't in the APPBASE (or
subdirectory) of the executing process (cscript.exe or inetinfo.exe I guess
in these scenarios).
Just to show things working, change your regasm command line to

regasm /tlb:testInterop.tlb testInterop.dll /codebase

You will get a warning about the assembly not having a strong name but
just ignore that for now. Hopefully enverything will now work (regasm puts
the path to the assembly - the CODEBASE - under the CLSID as well so mscoree
knows where to find it).
 
Have a look in the registry and find out what the InprocServer32 key looks like for your .NET object.

Also, ASP and vbscript are creating the object via its progid - is testInterop.test the fully qualified name (including full namespace) of the class you are trying to create?

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog

nntp://news.microsoft.com/microsoft.public.dotnet.framework/<[email protected]>

This is weird.....

I tried exactly what you did:
1) I could do the following in Microsoft Word 2003 Macro (after adding a
reference to testInterop.tlb):
------------------------start of functioning VBA
Code------------------------
Dim objTest As New testInterop.test
objTest.DoSomething
------------------------end of functioning VBA Code------------------------
2.1) When I try the following ASP code on Windows XP Professional SP1 with
IIS5.1
-----------------------------startof ASP Code-----------------------------
<%
Dim objTest
Set objTest = CreateObject("testInterop.test")
objTest.DoSomething
%>
------------------------------end of ASP Code------------------------------
2.2) I still get the following error
--------------------------------start of ASP
error--------------------------------
Microsoft VBScript runtime error '800a01ad'

ActiveX component can't create object: 'testInterop.test'

/testInterop.asp, line 3
--------------------------------end of ASP
error--------------------------------
3) If I put the ASP code in VBScript, I get the following error:
----------------------------start of VBScript
Error---------------------------
C:\Temp\testactivex.vbs(2, 5) Microsoft VBScript runtime error: ActiveX
componen
t can't create object: 'testInterop.test'
----------------------------end of VBScript Error---------------------------

Why is this and how could this be resolved?

Richard Blewett said:
I assume you have not given the assembly a strong name and installed it in
the GAC. The problem is that the COM loader gets pointed to mscoree.dll (the
runtime) and then passes mscoree.dll the CLSID of the COM object (via
DllGetClassObject) mscoree goes to the registry and looks under that CLSID
and finds the assembly name, class anme and a bunch of other stuff. Now the
problem is mscoree doesn't know where your class is so it tries to load it
by name and fails dismally as the assembly isn't in the APPBASE (or
subdirectory) of the executing process (cscript.exe or inetinfo.exe I guess
in these scenarios).
Just to show things working, change your regasm command line to

regasm /tlb:testInterop.tlb testInterop.dll /codebase

You will get a warning about the assembly not having a strong name but
just ignore that for now. Hopefully enverything will now work (regasm puts
the path to the assembly - the CODEBASE - under the CLSID as well so mscoree
knows where to find it).
In reality however, you should strong name and GAC the interop assembly

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog



---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.770 / Virus Database: 517 - Release Date: 27/09/2004



[microsoft.public.dotnet.framework]
 
Nice one!

The ProgId was set to MyOrg.web.publications.Test and not testInterop.Test!

So CreateObject("MyOrg.web.publications.Test") works!

Richard Blewett said:
Have a look in the registry and find out what the InprocServer32 key looks like for your .NET object.

Also, ASP and vbscript are creating the object via its progid - is
testInterop.test the fully qualified name (including full namespace) of the
class you are trying to create?
Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog
nntp://news.microsoft.com/microsoft.public.dotnet.framework/ said:
This is weird.....

I tried exactly what you did:
1) I could do the following in Microsoft Word 2003 Macro (after adding a
reference to testInterop.tlb):
------------------------start of functioning VBA
Code------------------------
Dim objTest As New testInterop.test
objTest.DoSomething
------------------------end of functioning VBA Code------------------------
2.1) When I try the following ASP code on Windows XP Professional SP1 with
IIS5.1
-----------------------------startof ASP Code-----------------------------
<%
Dim objTest
Set objTest = CreateObject("testInterop.test")
objTest.DoSomething
%>
------------------------------end of ASP Code------------------------------
2.2) I still get the following error
--------------------------------start of ASP
error--------------------------------
Microsoft VBScript runtime error '800a01ad'

ActiveX component can't create object: 'testInterop.test'

/testInterop.asp, line 3
--------------------------------end of ASP
error--------------------------------
3) If I put the ASP code in VBScript, I get the following error:
----------------------------start of VBScript
Error---------------------------
C:\Temp\testactivex.vbs(2, 5) Microsoft VBScript runtime error: ActiveX
componen
t can't create object: 'testInterop.test'
----------------------------end of VBScript Error---------------------------

Why is this and how could this be resolved?

Richard Blewett said:
I assume you have not given the assembly a strong name and installed it
in
the GAC. The problem is that the COM loader gets pointed to mscoree.dll (the
runtime) and then passes mscoree.dll the CLSID of the COM object (via
DllGetClassObject) mscoree goes to the registry and looks under that CLSID
and finds the assembly name, class anme and a bunch of other stuff. Now the
problem is mscoree doesn't know where your class is so it tries to load it
by name and fails dismally as the assembly isn't in the APPBASE (or
subdirectory) of the executing process (cscript.exe or inetinfo.exe I guess
in these scenarios).
Just to show things working, change your regasm command line to

regasm /tlb:testInterop.tlb testInterop.dll /codebase

You will get a warning about the assembly not having a strong name but
just ignore that for now. Hopefully enverything will now work (regasm puts
the path to the assembly - the CODEBASE - under the CLSID as well so mscoree
knows where to find it).
In reality however, you should strong name and GAC the interop assembly

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog



---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.770 / Virus Database: 517 - Release Date: 27/09/2004



[microsoft.public.dotnet.framework]
 
Now that I have got the mickey mouse .NET interop problem sorted (exposing
..NET library to ASP/VB6), I want to demo the real problem I am having.

What I want to achive is actually expoing a C#.NET Class Library for making
Web Service calls to ASP pages.

From my mickey mouse example, I learnt the following:
1) It's best to define interfaces as follows:
--------------------start of interface--------------------
using System.Runtime.InteropServices;
namespace MyOrg.web.publications
{



//[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://twoten.press.
net/webservices/")]
[InterfaceTypeAttribute(ComInterfaceType.InterfaceIsDual)]
public interface ITest
{
void DoSomething();
}
}
--------------------end of interface--------------------
2) The class, I just need to implement the interface (other than using
[ClassInterface(ClassInterfaceType.AutoDual)])
3) install the .NET dll into gac
4) use regasm to install the type library
5) the DLL usable with Late Binding:
e.g. Set objTest = CreateObject("MyOrg.web.publications.Test")

***The real real use/problem I am having is as follows:
(The code for the web service client class library is as follows)
---------------Start of WebService client Class Library Code---------------
using System.Diagnostics;
using System.Xml.Serialization;
using System;
using System.IO;
using System.Web.Services.Protocols;
using System.ComponentModel;
using System.Web.Services;
using System.Runtime.InteropServices;


namespace MyOrg.web.publications
{
/// <remarks/>
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Web.Services.WebServiceBindingAttribute(Name="iOrderSoap",
Namespace="http://testServer/webservices/")]
public class Order : Microsoft.Web.Services2.WebServicesClientProtocol ,
IOrder
{
/// <remarks/>
public Order()
{
this.Url = "https://testServer/iPubData/iOrder.asmx";
}


}

/// <remarks/>

[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://Pub.press
..net/webservices/PlaceOrder",
RequestNamespace="http://Pub.press.net/webservices/",
ResponseNamespace="http://Pub.press.net/webservices/",
Use=System.Web.Services.Description.SoapBindingUse.Literal,
ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public void PlaceOrder(SimpleOrderData order)
{
try
{
StreamWriter fileStream;
fileStream = File.CreateText("c:\\temp\\test.txt");
fileStream.WriteLine("TestOrder=" + order.TestOrder);
fileStream.WriteLine("FirstName" + order.FirstName);
fileStream.WriteLine("Surname" + order.Surname );
fileStream.WriteLine("order.OrderLines(0).StockCode" +
order.OrderLines[0].StockCode);
fileStream.Flush();
fileStream.Close();
//fileStream.WriteLine("" + );
// this.Invoke("PlaceOrder", new object[] {
// order});
}
catch (Exception ex)
{
System.Diagnostics.Trace.WriteLine(ex);
}
}

/// <remarks/>
public System.IAsyncResult BeginPlaceOrder(SimpleOrderData order,
System.AsyncCallback callback, object asyncState)
{
return this.BeginInvoke("PlaceOrder", new object[] {
order}, callback, asyncState);
}

/// <remarks/>
public void EndPlaceOrder(System.IAsyncResult asyncResult)
{
this.EndInvoke(asyncResult);
}

}
---------------End of WebService client Class Library Code---------------


1) I could compile, gacutil /i and regasm the class library with no problem
2) When I try to use it in ASP as follows:
2.1) Set objOnlyOrder =
CreateObject("MyOrg.web.publications.SimpleOrderData")
2.2) I get the following error:
------------------------start of asp error------------------------
Active Server Pages error 'ASP 0115'

Unexpected error

/test.asp

A trappable error (C0000005) occurred in an external object. The script
cannot continue running.
------------------------end of asp error------------------------
3.1) If I try to use it from VBA with Early Binding, then there are no
errors, but the class library doesn't seem to be reading reading in the
write value by writing to "C:\temp\test.txt" (it simply creates a blank
test.txt file)!
-------------------------start of VBA Code-------------------------
Dim objOnlyOrderLine As New iPubClient.OrderLine
Dim objOnlyOrder As New iPubClient.SimpleOrderData
Dim objIPubClient As New iPubClient.Order
Dim arrOrderLines(0) As String

objOnlyOrderLine.StockCode = "A123"
objOnlyOrderLine.Quantity = 2

objOnlyOrder.TestOrder = True
objOnlyOrder.FirstName = "Mickey"
objOnlyOrder.Surname = "Mouse"

arrOrderLines(0) = objOnlyOrderLine
objOnlyOrder.OrderLines = arOrderLines

MsgBox "before"
objIPubClient.PlaceOrder objOnlyOrder
MsgBox "after"
Set objOnlyOrderLine = Nothing
Set objOnlyOrder = Nothing
Set objIPubClient = Nothing
-------------------------End of VBA Code-------------------------



Richard Blewett said:
Have a look in the registry and find out what the InprocServer32 key looks like for your .NET object.

Also, ASP and vbscript are creating the object via its progid - is
testInterop.test the fully qualified name (including full namespace) of the
class you are trying to create?
Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog
nntp://news.microsoft.com/microsoft.public.dotnet.framework/ said:
This is weird.....

I tried exactly what you did:
1) I could do the following in Microsoft Word 2003 Macro (after adding a
reference to testInterop.tlb):
------------------------start of functioning VBA
Code------------------------
Dim objTest As New testInterop.test
objTest.DoSomething
------------------------end of functioning VBA Code------------------------
2.1) When I try the following ASP code on Windows XP Professional SP1 with
IIS5.1
-----------------------------startof ASP Code-----------------------------
<%
Dim objTest
Set objTest = CreateObject("testInterop.test")
objTest.DoSomething
%>
------------------------------end of ASP Code------------------------------
2.2) I still get the following error
--------------------------------start of ASP
error--------------------------------
Microsoft VBScript runtime error '800a01ad'

ActiveX component can't create object: 'testInterop.test'

/testInterop.asp, line 3
--------------------------------end of ASP
error--------------------------------
3) If I put the ASP code in VBScript, I get the following error:
----------------------------start of VBScript
Error---------------------------
C:\Temp\testactivex.vbs(2, 5) Microsoft VBScript runtime error: ActiveX
componen
t can't create object: 'testInterop.test'
----------------------------end of VBScript Error---------------------------

Why is this and how could this be resolved?

Richard Blewett said:
I assume you have not given the assembly a strong name and installed it
in
the GAC. The problem is that the COM loader gets pointed to mscoree.dll (the
runtime) and then passes mscoree.dll the CLSID of the COM object (via
DllGetClassObject) mscoree goes to the registry and looks under that CLSID
and finds the assembly name, class anme and a bunch of other stuff. Now the
problem is mscoree doesn't know where your class is so it tries to load it
by name and fails dismally as the assembly isn't in the APPBASE (or
subdirectory) of the executing process (cscript.exe or inetinfo.exe I guess
in these scenarios).
Just to show things working, change your regasm command line to

regasm /tlb:testInterop.tlb testInterop.dll /codebase

You will get a warning about the assembly not having a strong name but
just ignore that for now. Hopefully enverything will now work (regasm puts
the path to the assembly - the CODEBASE - under the CLSID as well so mscoree
knows where to find it).
In reality however, you should strong name and GAC the interop assembly

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog



---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.770 / Virus Database: 517 - Release Date: 27/09/2004



[microsoft.public.dotnet.framework]
 
Hi Patrick,

I will research the issue and update you with new information ASAP.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
I could confirm that this is 101% not a permission issue. The following
might be interesting summary of my observation
1) Added IUSR_<machineName> to local administrators group does NOT solve the
problem.
2) Just to clarify in the ASP Code, the following code does work with no
problem
Set objOnlyOrderLine =
CreateObject("MyOrg.web.publications.OrderLine")
Set objOnlyOrder =
CreateObject("MyOrg.web.publications.SimpleOrderData")
3) The following line fails:
Set objITwoTenDataClient =
CreateObject("MyOrg.web.publications.Order")

4) I haven't include the code for OrderLine or SimpleOrderData, but
effectively they are "Data classes" which takes contains public members no
funkier than String, Integer and String[] (types all tested under my micket
mouse example posted at
nntp://news.microsoft.com/microsoft.public.dotnet.framework under the
subject "Re: Cannot instantiate .NET Class Library")

5) NOTE- My Order class *inherits* .NET Managed class
Microsoft.Web.Services2.WebServicesClientProtocol. This is a key difference
between my Data Class (which instantiates ok) and my mickey mouse Test class

6) I could instantiate the Order class and call it from VBA, but it doesn't
produce the desired outcome (it merely creates the blank file
c:\temp\test.txt)

7) Cannot use Late Binding to create Order class from VBA or ASP!
 
Hi Patrick,

I reviewed the thread and find that our colleague is working with you on
this issue, I think you may try to take care with that thread.

Thank you for you understanding.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
I still couldn't get this working :-(

I *suspect* it is something to do with the fact my client class inherits
from Microsoft.Web.Services2.WebServicesClientProtocol, which obviously is a
..NET Managed class. I can't think of how I could expose that as well as the
inheritance tree to COM (in fact, I think inheritance tree are flattened).
In fact, I very much suspect, the class is having trouble looking for
this.url (which is from the base class). Is there a solution to this
(without having to re-write WebServicesClientProtocol)?

Patrick said:
Now that I have got the mickey mouse .NET interop problem sorted (exposing
.NET library to ASP/VB6), I want to demo the real problem I am having.

What I want to achive is actually expoing a C#.NET Class Library for making
Web Service calls to ASP pages.

From my mickey mouse example, I learnt the following:
1) It's best to define interfaces as follows:
--------------------start of interface--------------------
using System.Runtime.InteropServices;
namespace MyOrg.web.publications
{



//[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://twoten.press.
net/webservices/")]
[InterfaceTypeAttribute(ComInterfaceType.InterfaceIsDual)]
public interface ITest
{
void DoSomething();
}
}
--------------------end of interface--------------------
2) The class, I just need to implement the interface (other than using
[ClassInterface(ClassInterfaceType.AutoDual)])
3) install the .NET dll into gac
4) use regasm to install the type library
5) the DLL usable with Late Binding:
e.g. Set objTest = CreateObject("MyOrg.web.publications.Test")

***The real real use/problem I am having is as follows:
(The code for the web service client class library is as follows)
---------------Start of WebService client Class Library Code---------------
using System.Diagnostics;
using System.Xml.Serialization;
using System;
using System.IO;
using System.Web.Services.Protocols;
using System.ComponentModel;
using System.Web.Services;
using System.Runtime.InteropServices;


namespace MyOrg.web.publications
{
/// <remarks/>
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Web.Services.WebServiceBindingAttribute(Name="iOrderSoap",
Namespace="http://testServer/webservices/")]
public class Order : Microsoft.Web.Services2.WebServicesClientProtocol ,
IOrder
{
/// <remarks/>
public Order()
{
this.Url = "https://testServer/iPubData/iOrder.asmx";
}


}

/// <remarks/>

[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://Pub.press
.net/webservices/PlaceOrder",
RequestNamespace="http://Pub.press.net/webservices/",
ResponseNamespace="http://Pub.press.net/webservices/",
Use=System.Web.Services.Description.SoapBindingUse.Literal,
ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public void PlaceOrder(SimpleOrderData order)
{
try
{
StreamWriter fileStream;
fileStream = File.CreateText("c:\\temp\\test.txt");
fileStream.WriteLine("TestOrder=" + order.TestOrder);
fileStream.WriteLine("FirstName" + order.FirstName);
fileStream.WriteLine("Surname" + order.Surname );
fileStream.WriteLine("order.OrderLines(0).StockCode" +
order.OrderLines[0].StockCode);
fileStream.Flush();
fileStream.Close();
//fileStream.WriteLine("" + );
// this.Invoke("PlaceOrder", new object[] {
// order});
}
catch (Exception ex)
{
System.Diagnostics.Trace.WriteLine(ex);
}
}

/// <remarks/>
public System.IAsyncResult BeginPlaceOrder(SimpleOrderData order,
System.AsyncCallback callback, object asyncState)
{
return this.BeginInvoke("PlaceOrder", new object[] {
order}, callback, asyncState);
}

/// <remarks/>
public void EndPlaceOrder(System.IAsyncResult asyncResult)
{
this.EndInvoke(asyncResult);
}

}
---------------End of WebService client Class Library Code---------------


1) I could compile, gacutil /i and regasm the class library with no problem
2) When I try to use it in ASP as follows:
2.1) Set objOnlyOrder =
CreateObject("MyOrg.web.publications.SimpleOrderData")
2.2) I get the following error:
------------------------start of asp error------------------------
Active Server Pages error 'ASP 0115'

Unexpected error

/test.asp

A trappable error (C0000005) occurred in an external object. The script
cannot continue running.
------------------------end of asp error------------------------
3.1) If I try to use it from VBA with Early Binding, then there are no
errors, but the class library doesn't seem to be reading reading in the
write value by writing to "C:\temp\test.txt" (it simply creates a blank
test.txt file)!
-------------------------start of VBA Code-------------------------
Dim objOnlyOrderLine As New iPubClient.OrderLine
Dim objOnlyOrder As New iPubClient.SimpleOrderData
Dim objIPubClient As New iPubClient.Order
Dim arrOrderLines(0) As String

objOnlyOrderLine.StockCode = "A123"
objOnlyOrderLine.Quantity = 2

objOnlyOrder.TestOrder = True
objOnlyOrder.FirstName = "Mickey"
objOnlyOrder.Surname = "Mouse"

arrOrderLines(0) = objOnlyOrderLine
objOnlyOrder.OrderLines = arOrderLines

MsgBox "before"
objIPubClient.PlaceOrder objOnlyOrder
MsgBox "after"
Set objOnlyOrderLine = Nothing
Set objOnlyOrder = Nothing
Set objIPubClient = Nothing
-------------------------End of VBA Code-------------------------



Richard Blewett said:
Have a look in the registry and find out what the InprocServer32 key
looks
like for your .NET object.
Also, ASP and vbscript are creating the object via its progid - is
testInterop.test the fully qualified name (including full namespace) of the
class you are trying to create?
Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog
nntp://news.microsoft.com/microsoft.public.dotnet.framework/ said:
This is weird.....

I tried exactly what you did:
1) I could do the following in Microsoft Word 2003 Macro (after adding a
reference to testInterop.tlb):
------------------------start of functioning VBA
Code------------------------
Dim objTest As New testInterop.test
objTest.DoSomething
------------------------end of functioning VBA Code------------------------
2.1) When I try the following ASP code on Windows XP Professional SP1 with
IIS5.1
-----------------------------startof ASP Code-----------------------------
<%
Dim objTest
Set objTest = CreateObject("testInterop.test")
objTest.DoSomething
%>
------------------------------end of ASP Code------------------------------
2.2) I still get the following error
--------------------------------start of ASP
error--------------------------------
Microsoft VBScript runtime error '800a01ad'

ActiveX component can't create object: 'testInterop.test'

/testInterop.asp, line 3
--------------------------------end of ASP
error--------------------------------
3) If I put the ASP code in VBScript, I get the following error:
----------------------------start of VBScript
Error---------------------------
C:\Temp\testactivex.vbs(2, 5) Microsoft VBScript runtime error: ActiveX
componen
t can't create object: 'testInterop.test'
----------------------------end of VBScript Error---------------------------

Why is this and how could this be resolved?
it
in
the GAC. The problem is that the COM loader gets pointed to mscoree.dll (the
runtime) and then passes mscoree.dll the CLSID of the COM object (via
DllGetClassObject) mscoree goes to the registry and looks under that CLSID
and finds the assembly name, class anme and a bunch of other stuff. Now the
problem is mscoree doesn't know where your class is so it tries to load it
by name and fails dismally as the assembly isn't in the APPBASE (or
subdirectory) of the executing process (cscript.exe or inetinfo.exe I guess
in these scenarios).
Just to show things working, change your regasm command line to

regasm /tlb:testInterop.tlb testInterop.dll /codebase

You will get a warning about the assembly not having a strong name
but
just ignore that for now. Hopefully enverything will now work (regasm puts
the path to the assembly - the CODEBASE - under the CLSID as well so mscoree
knows where to find it).
In reality however, you should strong name and GAC the interop assembly

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog



---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.770 / Virus Database: 517 - Release Date: 27/09/2004



[microsoft.public.dotnet.framework]
 
Back
Top