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--------------------------

Re: Cannot instantiate .NET Class Library by Richard

Richard
Tue Sep 28 14:21:54 CDT 2004

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/<OBWti2XpEHA.3524@TK2MSFTNGP15.phx.gbl>

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]

Re: Cannot instantiate .NET Class Library by Patrick

Patrick
Wed Sep 29 04:48:25 CDT 2004

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 [DevelopMentor]" <richardb@develop.com> wrote in message
news:uIHwqBZpEHA.2304@TK2MSFTNGP14.phx.gbl...
> 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
>
>