Discussion:
Automation Error while creating a COM Wrapper object in VB6 COM Application
(too old to reply)
Murtaza
2006-09-27 04:49:32 UTC
Permalink
I have a .NET managed class designed in C#, created COM Wrapper and am able
to create its object in Visual Basic 6 Desktop application.
I then created this .NET assembly object in Visual Basic 6 COM Application
method and created the object in it. while called the method from the ASP
client, it sometimes generates an automation error



prj_v95 error '80131904'
Automation error

/prj/Registration/Visitor_Activity/My_Viewing_History_Proxy.asp,
line 20






and


Error Type:
prj_v95 (0x800A005B)
Object variable or With block variable not set
/Vir/default.asp, line 3


and sometime this...


Error Type:
prj_v95 (0x80070020)
Automation error The process cannot access the file because it is being used
by another process.
/Vir/default.asp, line 3




Please note that i can call the same COM method via Visual Basic 6
application and it works fine. It does not allow me to call the method via
ASP Client.

Any hint???

Regards,
Murtaza
Murtaza
2006-09-28 04:00:26 UTC
Permalink
The problem is not due to the COM application. I have further investigated
the problem which is now something like this:
I have a .NET managed code written in C#, made it COMVisible, created COM
Wrapper(using regasm and gacutil).

My first question is "Will i be able to create the object of this COM
Wrapper class directly from the ASP Client using Server.CreateObject()?"
I tried, but it didn't worked. I am getting the following error message in
this case:

Error Type:
Server object, ASP 0177 (0x80004003)
Invalid pointer
/Vir/Default.asp, line 2

I then created a COM Application in VB6, added the reference of this COM
Wrapper class and created the object in it.
then created this VB6 COM Application object through my ASP Client. the
object is created successfully and worked fine.
but when i repeatedly refresh this ASP page, an error appears which is
something like this:

Error Type:
prj_v95 (0x80070020)
Automation error The process cannot access the file because it is being used
by another process.
/Vir/Default.asp, line 3

Since i am the only user hitting the page, it appears on repeatedly
refreshing the page but i am afraid if this application is deployed
on my production server(that have thousands of users), this is going to be a
bottleneck for my application.

Any help would be highly appreciated.
Thanks in advance.

Murtaza
Post by Murtaza
I have a .NET managed class designed in C#, created COM Wrapper and am able
to create its object in Visual Basic 6 Desktop application.
I then created this .NET assembly object in Visual Basic 6 COM Application
method and created the object in it. while called the method from the ASP
client, it sometimes generates an automation error
prj_v95 error '80131904'
Automation error
/prj/Registration/Visitor_Activity/My_Viewing_History_Proxy.asp,
line 20
and
prj_v95 (0x800A005B)
Object variable or With block variable not set
/Vir/default.asp, line 3
and sometime this...
prj_v95 (0x80070020)
Automation error The process cannot access the file because it is being used
by another process.
/Vir/default.asp, line 3
Please note that i can call the same COM method via Visual Basic 6
application and it works fine. It does not allow me to call the method via
ASP Client.
Any hint???
Regards,
Murtaza
"Peter Huang" [MSFT]
2006-09-29 03:31:55 UTC
Permalink
Hi Murtaza,

For your scenario I suggest you try to restart IIS,
iisreset

Yes, we can create a .NET Class library and expose it to COM by using
regasm.
To troubleshoot the error, I high recommend you test with a simple .NET
class to see if that works.
1. Write a .NET class as below.
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace TestClassLib
{
[ClassInterface(ClassInterfaceType.AutoDual),ComVisible(true)]
public class TestClass
{
public string TestMethod()
{
return "Hello";
}
}
}

2. Compile it as register it to COM
regasm TestClassLib.dll /codebase
For test purpost I did not put it in GAC for now.

3. Write a asp page to test it.
<%
Dim o
set o = Server.CreateObject("TestClassLib.TestClass")
Response.Write(o.TestMethod())
%>

4. Result the asp page will show Hello in IE.

a. please perform the test and let me know the result, so that we will know
if this problem is code specific or environment specific
b. I think you may try the suggestions in my previous post, this will help
us isolate the problem, e.g. if there is any error when call CreateObject
or certian method, what is the method do and so on.
So if you could post a simple reproduce sample or some key code line will
help to do further troubleshooting.


Best regards,

Peter Huang

Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Murtaza
2006-09-29 16:48:54 UTC
Permalink
Hi Peter,

Thanks for the reply. We are almost done with your trick. the only thing
still in pending is that we are trying to "access the system registry
through our .NET assembly dll and we got to know that this is not working
due to default security settings".
The following is the code snippet:

============================================================================
===========================
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Win32; //for RegistryKey class-0
using System.Runtime.InteropServices;

namespace testClassLib
{
public interface IclsRegistry
{
void GetRegistryValues(string ApplicationRegistryKey);
}

public class clsRegistry : IclsRegistry
{
private string dBDatabase;
private string dBServerName;
private string dBUserName;
private string dBPassword;
private string cCScheduling;
private string xceedLicense;

private static RegistryKey GetKey(string baseKey, string subKey)
{
RegistryKey key;

/* --- Resolve (create or open) Base Key --- */
try
{
key = Registry.LocalMachine.OpenSubKey(baseKey, true);

if (key == null)
{
key = Registry.LocalMachine.CreateSubKey(baseKey);
}
else
{
Console.WriteLine("Base key resolved");
}
}
catch (Exception e)
{
// Exception logging omitted for brevity
return null;
}

/* --- Resolve (create or open) Sub Key --- */
try
{
key = Registry.LocalMachine.CreateSubKey(baseKey + "\\" +
subKey);
if (key == null)
{
throw (new Exception("Error creating SubKey"));
}
else
{
Console.WriteLine("Subkey resolved");
}
}
catch (Exception e)
{
// Exception logging omitted for brevity
return null;
}

return key;
}
/* Get registry values and populate the database setting variables
*/
public void GetRegistryValues(string ApplicationRegistryKey)
{
dBDatabase = clsRegistry.GetKey("Software",
ApplicationRegistryKey).GetValue("DBDatabase").ToString();
dBServerName = clsRegistry.GetKey("Software",
ApplicationRegistryKey).GetValue("DBServerName").ToString();
dBUserName = clsRegistry.GetKey("Software",
ApplicationRegistryKey).GetValue("DBUserName").ToString();
dBPassword = clsRegistry.GetKey("Software",
ApplicationRegistryKey).GetValue("DBPassword").ToString();
cCScheduling = clsRegistry.GetKey("Software",
ApplicationRegistryKey).GetValue("CCScheduling").ToString();
xceedLicense = clsRegistry.GetKey("Software",
ApplicationRegistryKey).GetValue("XceedLicense").ToString();
}
}
}
============================================================================
=============================
the following is the method call
============================================================================
=============================
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace testClassLib
{
[ClassInterface(ClassInterfaceType.AutoDual), ComVisible(true)]
public class testClass
{
public void TestMethod()
{
clsRegistry a = new clsRegistry();
a.GetRegistryValues("IPTV95"); //????? Call having
problem
}
}
}
============================================================================
=============================
============================================================================
=============================

The following is the ASP page in which the .NET class assembly object is
created.
Dim o
set o = Server.CreateObject("testClassLib.testClass")
Response.write o.TestMethod
============================================================================
=============================
============================================================================
=============================

The following is the error message being displayed in Internet Explorer when
the ASP page is executed.
============================================================================
=============================
Error Type:
testClassLib (0x80004003)
Object reference not set to an instance of an object.
/Vir/Default.asp, line 11
============================================================================
=============================
We would be grateful if you can provide us the solution regarding the above
stated problem.
All we need is to access the windows registry through our .NET class
assembly which is accessed through ASP Client.

Thanks in advance.
Murtaza
Post by "Peter Huang" [MSFT]
Hi Murtaza,
For your scenario I suggest you try to restart IIS,
iisreset
Yes, we can create a .NET Class library and expose it to COM by using
regasm.
To troubleshoot the error, I high recommend you test with a simple .NET
class to see if that works.
1. Write a .NET class as below.
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace TestClassLib
{
[ClassInterface(ClassInterfaceType.AutoDual),ComVisible(true)]
public class TestClass
{
public string TestMethod()
{
return "Hello";
}
}
}
2. Compile it as register it to COM
regasm TestClassLib.dll /codebase
For test purpost I did not put it in GAC for now.
3. Write a asp page to test it.
<%
Dim o
set o = Server.CreateObject("TestClassLib.TestClass")
Response.Write(o.TestMethod())
%>
4. Result the asp page will show Hello in IE.
a. please perform the test and let me know the result, so that we will know
if this problem is code specific or environment specific
b. I think you may try the suggestions in my previous post, this will help
us isolate the problem, e.g. if there is any error when call CreateObject
or certian method, what is the method do and so on.
So if you could post a simple reproduce sample or some key code line will
help to do further troubleshooting.
Best regards,
Peter Huang
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Luke Zhang [MSFT]
2006-10-02 06:46:03 UTC
Permalink
Hello Murtaza,

To access system registry, we need to grant the permission to the user
account "IUser_ServerName" for an ASP application. Anyway, to ensure this
is a security issue, you try to create a VBS file with following code:

set o = CreateObject("testClassLib.testClass")
msgbox o.TestMethod

And run the VBS file on your desktop. If it can be run successfully, we can
ensure this is security issue. (VBS file will be run under your current
logon account).

Sincerely,

Luke Zhang

Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
"Peter Huang" [MSFT]
2006-10-05 06:06:59 UTC
Permalink
Hi Murtaza,

I agree with Luke's suggestion.
To access registry key we commonly need the code running under an powerful
account, but by default, the ASP code will running under an lower
permission account commonly it is "IUSER_ServerName".

But to isolate the problem I suggest you run the ASP code in a VBS file
under an powerful account as Luke's suggestion.

Also you may take a look at the link below about how to running the code
under an powerful account.
How to implement impersonation in an ASP.NET application
http://support.microsoft.com/default.aspx?scid=kb;[LN];306158

NOTE: Since you are using ASP code, only the "Impersonate a Specific User
in Code" will work for ASP, others are asp.net specific.

Here is the VB version.
248187 How to impersonate a user from Active Server Pages
http://support.microsoft.com/default.aspx?scid=kb;EN-US;248187

You may have a try and let me know the result.
If you still have any concern, please feel free to let me know.
I look forward to hearing from you.

Best regards,

Peter Huang

Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
"Peter Huang" [MSFT]
2006-09-28 04:04:56 UTC
Permalink
Hi Murtaza,

From your description, I understand that you have written a .NET C# class
library and expose it to COM interop. So that we can call the .NET class
library in unamaged code.
e.g. VB/ASP.

Now you can use the .NET class in C# but not in the ASP code.
If I misunderstood, please feel free to let me know.

Because commonly the VB6 will use earlybinding to the COM object but ASP
will use latebinding.
So I think you may try the use VB Script to test to see if that works for
you.
e.g.
Dim o
Set o = CreateObject("MydotnetLIb.MydotnetClass")
o.TestMethod

Please make a try and let me know the result.

Also ASP code commonly running in the Server side, which is somewhat
different from the common desktop application.
(e.g. We show not Show a MessageBox in ASP code(I mean server side code,
not client scritpt)
So I sugguest you create a very simple .NET class with just one method.
e.g. just return a "Hello" string and expose it to COM.

Now you may try to test it in ASP code to see if that works, so that we can
isolate the problem.

Please perform the test and let me know the result.
BTW: from the error you post, it is occured in a few places in the asp
code, so could you show some related code snippet.
e.g.
Error Type:
prj_v95 (0x800A005B)
Object variable or With block variable not set
/Vir/default.asp, line 3

The code above may be caused by you want to invoke a method on a nothing
object.
e.g.
Dim o
Set o = CreateObject("MydotnetLIb.MydotnetClass")
'But the call is fail, so o is Nothing
'So the TestMethod call may throw the error as above.
o.TestMethod

Best regards,

Peter Huang

Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Loading...