Solved

ObjectContext while debugging

Posted on 2001-08-17
15
373 Views
Last Modified: 2013-11-25
When creating an activex dll, and using the debugging feature of visual basic I am getting some errors which i do not get when the component has been compiled.

First some information about the dll.
The dll grabs the object context and then tries to access the response object (you will see code in a minute). Then the component is being "created" in an asp page. When I compile the component it looks just fine when I then open the asp page in my browser. But when I use the debugging feature it gives me an error on the line where I request the response object. With other words, the object context is invalid.

Is there any way that I can use Visual basic's debugging feature with my asp pages and the object context? because now I have to stop IIS, compile the component, start IIS and then over and over again. I really do hope someone is able to give me a hand here.

here's some code which will show you what is going on.

Private ObjectContext As ObjectContext
Private Response As ASPTypeLibrary.Response

Private Sub Class_Initialize()
    Set ObjectContext = GetObjectContext()
    Set Response = GetObjectContext("Response")
    Response.Write "text2"
End Sub

Private Sub Class_Terminate()
    Set ObjectContext = Nothing
End Sub


If someone can help me debugging the way I want to I will give 300 points (will be adjusted later on).

regards,
CJ
0
Comment
Question by:CJ_S
  • 6
  • 6
  • 2
  • +1
15 Comments
 
LVL 28

Expert Comment

by:AzraSound
ID: 6397716
Is the component registered in MTS\COM+?  What version of VB are you using?
0
 
LVL 2

Expert Comment

by:agriggs
ID: 6398198
You can debug the compiled version of VB components using the Visual C++ debugger, or if you don't have that, using WinDbg which can be downloaded from the Microsoft site.  But that still won't help your problem with having to stop and restart IIS.  Post a comment if you are interested in learning how to do this.
0
 
LVL 22

Author Comment

by:CJ_S
ID: 6398404
I am using Visual Basic 6 professional edition. The component is not registered into MTS, but once finished it will be. It does not matter that I am using the objectcontext since ASP.dll itself runs inside MTS and can therefore use the response, request and other ASP objects.
One reason why it has not been registered into MTS yet is because I want to debug the component first (after all I need to test about umpteenth times and restarting iis is pretty stupid, i just want to press F5 and get into debugging mode.

I do not need to debug the compiled component. Like I said above I want to debug the component as I usually do. By pressing F5 and have the component run in the VB IDE and available to ASP. I guess there is no way, just want to be sure...

regards,
CJ
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 6398454
Well I dont see why it wouldnt be possible as many sources point to how you can debug a component installed in MTS or COM+ from the VB IDE.  Those sources all show that this is indeed possible, and getting a reference to the ObjectContext is not a problem.  I will try and test this out when I get back on my dev machine with IIS installed.
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 6398463
>>after all I need to test about umpteenth times and restarting iis is pretty stupid

If you set the appropriate settings in the Internet Services Manager, you dont have to shut down the service and restart to re-compile and test your component (under Win2k).
0
 
LVL 22

Author Comment

by:CJ_S
ID: 6398634
May I know where that setting is located? :-)...
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 6398653
Let me see if I can remember well enough off hand to tell you as I dont have it in front of me...

Open up the Internet Services Manager
Right Click your default website and choose Properties
Click on the Home Directory Tab
There is a drop down indicating Execute Permissions which you can set to Scripts and Executables
Right below that is another drop down box (dont remember the description), but you choose High - Isolated.

Youll notice a greyed button that says Unload there.  Once you compile a component, and run it, it becomes "loaded" by IIS.  If and when you need to recompile that component, open up the Internet Services Manager to that same tab and click the Unload button.  This should unload the component from memory held by IIS and allow you to recompile w/o stopping/starting the service each time.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 22

Author Comment

by:CJ_S
ID: 6398932
UHM, will still take too much interaction if you ask me. I do remember there was another level somehow somewhere in IIS. I'll see what I can find myself tomorrow... maybe the settings are located at the same place as you just mentioned.  Thnx :-)

Regards,
CJ
0
 
LVL 6

Expert Comment

by:anthony_glenwright
ID: 6399577
I've had this problem for ages...  What seems to happen is that you get a "stub" ObjectContext that isn't actually the one proived by IIS, and therefore doesn't have the request, response, etc, objects in it.

Just to clarify the problem...

The object context you get is "valid", in that it is a real object context, but it does NOT contain the IIS objects.

So the line you are having a problem with is:

>>   Set Response = GetObjectContext("Response")

not

>> Set ObjectContext = GetObjectContext()

And the reason is not that ObjectContext is Nothing, it is because GetObjectContext("Response") does not exist.

Here's some code that I use - it doesn't fix the problem, but it will hopefully explain what I mean about the source of your (and my) problem:

On Error GoTo NoObjectContext
  If Not GetObjectContext Is Nothing Then
    If Not GetObjectContext("Request") Is Nothing Then
      strAuthenticatedUser = GetObjectContext("Request").ServerVariables("LOGON_USER")
      If InStr(strAuthenticatedUser, "\") <> 0 Then
        strAuthenticatedUser = Split(strAuthenticatedUser, "\")(1)
      End If
      strMachineID = GetObjectContext("Request").ServerVariables("REMOTE_ADDR")
    End If
  End If
NoObjectContext:
  ' continue

I realise this won't fix your particular problem, but hope that the extra info on the source of the problem might help someone else to provide a solution.

There's an article at http://support.microsoft.com/support/kb/articles/Q188/9/19.ASP that shows a solution, but I've never been able to make it work.

Theres also an article that lists the problem as a bug - http://support.microsoft.com/support/kb/articles/Q265/4/92.ASP

PS:  I'll give a 100 point bonus for anyone that solves this one...
0
 
LVL 28

Accepted Solution

by:
AzraSound earned 300 total points
ID: 6399646
Perhaps it is a limitation of WinNT and MTS?  Under my Win2k machine, I created a small component, ran it in debug mode, and it hit my breakpoint:

'- CJTest Class

Dim objResponse As ASPTypeLibrary.Response

Public Sub WriteTest()
    objResponse.Write "Hello CJ!"
End Sub

Public Sub OnStartPage(SC As ASPTypeLibrary.ScriptingContext)
  Set objResponse = SC.Response
End Sub




'- testPage.asp

<%@ language=vbscript %>
<html>
<body>

<%
Dim myObj
Set myObj = Server.CreateObject("CJTest.Test")
myObj.WriteTest
Set myObj = Nothing
%>

</body>
</html>


I set the breakpoint in the WriteTest sub and ran the component from the VB IDE and it hit it.  I continued, and the result was a page with "Hello CJ!" written in it.

I just noticed that you werent using the OnStartPage method to obtain the context, and I imagine this is due to the difference in how the asp.dll is used in IIS4 as opposed to IIS5.  I really dont know, as my only experience with ASP and IIS has been on a Win2k box with IIS5.
0
 
LVL 6

Expert Comment

by:anthony_glenwright
ID: 6399661
All my experience and testing has been on IIS and Win2k, too.  Ive never used the OnStartPage method, though.
0
 
LVL 22

Author Comment

by:CJ_S
ID: 6399881
*smiles*
Thank you very much for that code azrasound. But I have had my own experience with the onstartpage method. It just wasn't called when I called my component.

I am creating the component on IIS 5, w2k advanced server, the eventual production server will be IIS 4. So that's why I copied the mtxas.dll from the nt machine and used that one.

I will fiddle around with the code you gave me, and see what happens.

anthony_glenwright,
I kind of explained it the wrong way. What I meant is exactly the same as you explained, you did a better job than me in describing though :-)... thnx for the clarification and help!

Regards,
CJ
0
 
LVL 22

Author Comment

by:CJ_S
ID: 6399950
Seems to work flawlessly!

regards,
CJ
0
 
LVL 22

Author Comment

by:CJ_S
ID: 6399952
Programming between doing the household and relaxing is so cool ;-)

regards,
CJ
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 6400653
:-)
Glad you got it working!
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now