473,378 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

GetObjectContext Returns Null

We have an ASP.NET website written in C# that accesses a
VB6 COM component. That component accesses the ASP-objects
in the following manner:
Set objContext = GetObjectContext
Set objRequest = objContext("Request")
strAddress = objRequest.ServerVariables("REMOTE_ADDR")
Set objContext = Nothing
Set objRequest = Nothing

On all the pages of our website the ASPCompAt-property is
set to True. We have pages in our website though where
GetObjectContext returns Nothing and others where it
returns an object.

For example, page 1 in the our ASP.NET website has
ASPCCompAt set to True and can successfully access the ASP
Request-object.

Page 2 also has the ASPCompAt-property set to True, but
the GetObjectContext-function returns Nothing (Null)
there. We've spend a significant amount of time trying to
find the difference between these two pages and the only
difference that we saw was that a Server.Transfer-call is
done before we call GetObjectContext on page 1.
As soon as we also did a Server.Transfer in page 2, the
GetObjectContext function returned a valid object.

For example:
private void Page_Load(object sender, System.EventArgs e)
{
// Doing a Server.Transfer if GetObjectContext
// returns Nothing. This is only done once
if (ourVB6Component.GetObjectContext2() == null) {
Server.Transfer("page2.aspx");
}

// The following method calls GetObjectContext internally
// and only works if a Server.Transfer is first called.
ourVB6Component.DoMethod;
}

Can anybody explain why GetObjectContext would behave
differently after a Server.Transfer? Is there a clean way
to get GetObjectContext to work correctly at all times?
Nov 18 '05 #1
6 4659
Hi Michael,

Thank you for posting to the MSDN newsgroups.

I am interested in this issue and am researching on it now. I will update
you as soon as possible.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 18 '05 #2
Hi Michael,

Based on my research, I found several articles that are helpful for this
issue. Please check them out.

HOW TO: Access ASP.NET Intrinsic Objects from .NET Components Using Visual
Basic .NET
http://support.microsoft.com/default...b;EN-US;319429

HOW TO: Access ASP.NET Intrinsic Objects from .NET Components by Using
Visual C# .NET
http://support.microsoft.com/default...b;EN-US;810928

HOW TO: Access ASP.NET Intrinsic Objects in a Visual Basic 6.0 Component
http://support.microsoft.com/default...b;EN-US;323259

If I have misunderstood your concern, please feel free to let me know.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 18 '05 #3
Hi Michael,

Thank you for your update.

I have followed the steps mentioned in the article below,

HOW TO: Access ASP.NET Intrinsic Objects in a Visual Basic 6.0 Component
http://support.microsoft.com/default...b;EN-US;323259

It seems to work fine on my side. I tested it with VS.NET 2003, however,
with the same version of .NET Framework v1.1.4322.

By checking your code, I want to know how the VB6 component was created in
your ASP.NET application. I mean the objApp variable.

It may be the problem here. In my testing code, I created a reference to
the VB6 component via the HttpServerUtility.CreateObject method.

Please let me know the detailed results.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 18 '05 #4
Jacob thank you for your help so far.

We didn't use the CreateObject-method because we're
developing our website in C# and not in VB.NET. The
HttpServerUtility.CreateObject-method is easy to use in
VB.NET, but calling methods on COM-objects created using
CreateObject in C# is really a lot of work and hardly
improves the readability of the code.

We've created a wrapper for our component using tlbimp and
we've linked that wrapper to the References of our C#-
project. We can then create an instance using early
binding.

So, this is what we've found so far:
We've created a Visual Basic 6 ActiveX-object that uses
GetObjectContext to get access to the intrinsic ASP-
objects.
We've created an instance of this object in a C# ASP.NET-
website using early binding.
We can access the ActiveX-object perfectly but the
GetObjectContext-function inside that ActiveX-object only
seems to return a valid context when it is executed after
we've called Server.Transfer or Server.Execute in the
ASP.NET-website.

Any more ideas?

Nov 18 '05 #5
Hi Michael,

Before I go ahead with a similar test with yours on my side, I found the
following important information from MSDN documentation:

If you use aspcompat mode with STA components, you should create COM
components only from the Page_Load event or later in the execution chain
and not at page construction time. For example, the following member
declaration creates the component at construction time.

<%@ ASPCOMPAT="TRUE" %>
<script runat="server" language="VB">
' The components is created at construction time.
Dim comObj As MyComObject = New MyComObject()
Public Sub Page_Load(Src As Objects, E As EventArgs)
' The object is first used here.
comObj.DoSomething()
End Sub
</script>
Instead, use code like the following:
<%@ ASPCOMPAT="TRUE" %>
<script runat="server" language="VB">
Public Sub Page_Load(Src As Objects, E As EventArgs)
' The component is created and used after the code is running
' on the STA thread pool.
comObj = New MyObject()
comObj.DoSomething()
End Sub

If you created the VB6 component at the page construction time, please
change the code appropriately and check whether the problem still exists.
According to the symptom you mentioned that the httpcontext is only
available when a server.execute or a server.transfer was executed.

I hope it helps. On my side, I am also doing a test and I will update you
with the results as soon as possible.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 18 '05 #6
Jacob,

Indeed, this is what was wrong! We've changed our code
according to your specification and it works fine now.

Thanks. I'm very glad that we've got a solution that
required very little change from our side.

Again, Thank You
Michael
Nov 18 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Rene van Hoek | last post by:
Hi, I am using Xalan 1.8.0 and Xerces 2.6.0 in C++. I have an XML document which I first transform into an other XML document using an XSL styelsheet. Then I want to parse with XPathEvaluator...
4
by: ezra epstein | last post by:
Aother head banger for me. Below is a complete example of the code Using Postgres 7.4, the function "test" gets this: psql:temp3.sql:10: ERROR: syntax error at or near "%" at character 135...
2
by: Jeff Adams | last post by:
I am using MSVC .NET to create a C program. I am having trouble creating a window. The createwindow returns NULL however no error is caught. The GetLastError() returns "operation completed...
10
by: Lyle Fairfield | last post by:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbaac11/html/acfctNZ_HV05186465.asp "If the value of the variant argument is Null, the Nz function returns the number zero or a...
4
by: Henning M | last post by:
Hej All Im relativ new to VB.net and im trying to collect som device information using cfgmgr32.dll I use - Declare Function GetListLength Lib "cfgmgr32.dll" Alias...
11
by: MLH | last post by:
I have 2 lines in a procedure that assign MyVariant a value - line #238 and line #491. When line #238 runs, the value is 152. When line #491 runs, the DLookup function returns Null. I would expect...
12
by: robertino | last post by:
Hi all, I've put together a few SPs to produce a BOM (bill of materials) listing, which together use a couple of global temp tables, and return the results from a cursor. Here's the code: ...
1
by: asilter | last post by:
Hi, I'm trying to assign variables where vpSec0 points. void * vpSec0 = NULL; CreateHVFESection0(vpSec0); CreateHVFESection0 function is below.
4
by: lage | last post by:
I am working with a system using a Com+ layer built in VB6. I am now trying to use these components from VB.Net. I have added the component as reference and .Net seem to communicate with the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.