1.1 -> 2.0 framework conversion problem.


B

Blasting Cap

I'm trying to convert a 1.1 app to 2.0, and keep finding one thing after
another that either Framework 2.0 or Visual Studio 2005 doesn't like.

Now this -

In the global.asax, code that has been running for nearly 4 years now is
giving me a problem. The code is supposed to give the user a "clean"
page with a login link on it and send an email to me when an app blows
up. It also is supposed to write to the event log too.

This is the code:

Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
Dim Message As String = "\n\nURL:\n http://localhost/" &
Request.Path _
& "\n\nMESSAGE:\n "
& Server.GetLastError().Message _
& "\n\nSTACK
TRACE:\n" & Server.GetLastError().StackTrace

' Create event log if it does not exist
'Message = Server.GetLastError().ToString
Dim LogName As String = "Application"
If (Not EventLog.SourceExists(LogName)) Then
EventLog.CreateEventSource(LogName, LogName)
End If

' Insert into event log
Dim Log As New EventLog
Log.Source = LogName
Log.WriteEntry(Message, EventLogEntryType.Error)

Dim mail As New MailMessage
Dim sTemp As String = Replace(Session("UserName"), " ", ".")
sTemp = sTemp & "@mycompany.com"
mail.From = New MailAddress(sTemp)
mail.To.Add("(e-mail address removed)")
mail.Subject = "mycompany.com Site Error"
mail.Body = Request.Path & " " & Server.GetLastError().ToString
mail.IsBodyHtml = True
Dim smtp As New SmtpClient
smtp.Send(mail)
End Sub


The statement that generates the error is the firs one - the dim Message
as String.

The error is:

"HTTPException was unhandled by user code"
"Request is not available in this context"

If I do a quickwatch on the Server.GetLastError().Message, it returns:

"Exception from HRESULT: 0x800A0035 (CTL_E_FILENOTFOUND)"

The error appears to occur when my web app looks at the server (the www
external name), on which we have challenge/response set on, for a
graphic that I use on the page. I've stepped thru the code on the page,
and it only goes to the Application_error step in Global.asax when the
page tries to display the first of the two graphics that are on the www
external name. It doesn't occur anywhere else.

This code has been functioning on 1.1 framework & Visual Studio 2003 for
several years without a hitch, and had previously been tested by me on
this box and another one without a problem.

What gives with this new message? Why is it picking this error to give
me a problem with?

Any ideas, suggestions appreciated.

BC
 
Ad

Advertisements

G

Guest

I'm trying to convert a 1.1 app to 2.0, and keep finding one thing after
another that either Framework 2.0 or Visual Studio 2005 doesn't like.

Now this -

In the global.asax, code that has been running for nearly 4 years now is
giving me a problem. The code is supposed to give the user a "clean"
page with a login link on it and send an email to me when an app blows
up. It also is supposed to write to the event log too.

This is the code:

Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
Dim Message As String = "\n\nURL:\nhttp://localhost/" &
Request.Path _
& "\n\nMESSAGE:\n "
& Server.GetLastError().Message _
& "\n\nSTACK
TRACE:\n" & Server.GetLastError().StackTrace

' Create event log if it does not exist
'Message = Server.GetLastError().ToString
Dim LogName As String = "Application"
If (Not EventLog.SourceExists(LogName)) Then
EventLog.CreateEventSource(LogName, LogName)
End If

' Insert into event log
Dim Log As New EventLog
Log.Source = LogName
Log.WriteEntry(Message, EventLogEntryType.Error)

Dim mail As New MailMessage
Dim sTemp As String = Replace(Session("UserName"), " ", ".")
sTemp = sTemp & "@mycompany.com"
mail.From = New MailAddress(sTemp)
mail.To.Add("(e-mail address removed)")
mail.Subject = "mycompany.com Site Error"
mail.Body = Request.Path & " " & Server.GetLastError().ToString
mail.IsBodyHtml = True
Dim smtp As New SmtpClient
smtp.Send(mail)
End Sub

The statement that generates the error is the firs one - the dim Message
as String.

The error is:

"HTTPException was unhandled by user code"
"Request is not available in this context"

If I do a quickwatch on the Server.GetLastError().Message, it returns:

"Exception from HRESULT: 0x800A0035 (CTL_E_FILENOTFOUND)"

The error appears to occur when my web app looks at the server (the www
external name), on which we have challenge/response set on, for a
graphic that I use on the page. I've stepped thru the code on the page,
and it only goes to the Application_error step in Global.asax when the
page tries to display the first of the two graphics that are on the www
external name. It doesn't occur anywhere else.

This code has been functioning on 1.1 framework & Visual Studio 2003 for
several years without a hitch, and had previously been tested by me on
this box and another one without a problem.

What gives with this new message? Why is it picking this error to give
me a problem with?

Any ideas, suggestions appreciated.

BC

Hi, if I understand you correct, the original problem is not this
code. The "Request is not available in this context" message means
that the Request was not yet initialized when the error occurred and
you cannot use the Request.Path. Try to add

If Not Request Is Nothing Then

or

IIF(Request Is Nothing, "", Request.Path)
 
B

Blasting Cap

Alexy -

I did as you suggested, adding the IIF statement in the global.asax.

It didn't like that any better, and now produces an error in the task list:

Error 50 Type 'ASP.global_asax' is not defined.
C:\Inetpub\wwwroot\test\Sales\faavailability.aspx 1 1
http://localhost/test/
 
G

Guest

Blasting Cap said:
Alexy -

I did as you suggested, adding the IIF statement in the global.asax.

It didn't like that any better, and now produces an error in the task
list:

Error 50 Type 'ASP.global_asax' is not defined.
C:\Inetpub\wwwroot\test\Sales\faavailability.aspx 1 1
http://localhost/test/

Okay, you see - the problem is different, probably because the conversion
hadn't finished properly

How is your global.asax looks like?

Should be similar to the following:
<%@ Application Codebehind="Global.asax.vb" Inherits="ASP.Global_asax"
Language="vb" %>

(ASP is your namespace)

How the Page Directive in the faavailability.aspx looks like?

If you think that everything is correct, try to rename the "wrong" page,
create a new one using VS.NET 2005 and copy your functions to the newly
created file. Maybe this can solve the problem. (I hope)
 
B

Blasting Cap

I've done something similar to what you've suggested, and it seems to
have worked, although I still have some minor issues.

Wonder why this conversion process is so subject to these "odd" errors,
where renaming a page & creating a new one seems to "fix" a problem that
you can't fix any other way?

BC
 
J

Juan T. Llibre

Hi, Mr. Cap. May I call you Blasting ?

:)

The heart of what you point out is that no conversion program can possibly
cover all the syntax quirks between the different .Net Framework versions.

You might want to look at a dedicated tool, like a code refactoring app, to get better results.

Refactor! for .NET is a good tool for VB.NET...and it's free:
http://www.devexpress.com/Products/NET/IDETools/VBRefactor/

Refactor for ASP.NET is quite useful, too...and it's also free:
http://www.devexpress.com/Products/NET/IDETools/RefactorASP/

They also have a C# version...but you have to pay for it:
http://www.devexpress.com/Products/NET/Refactor/

It does much more than the free versions, though.

Refactor covers a lot of ground, and can save you a few headaches.
 
Ad

Advertisements

G

Guest

I've done something similar to what you've suggested, and it seems to
have worked, although I still have some minor issues.

Wonder why this conversion process is so subject to these "odd" errors,
where renaming a page & creating a new one seems to "fix" a problem that
you can't fix any other way?

BC











- Show quoted text -

Check out the following two links regarding issues with migrating:

Step-by-Step Guide to Converting Web Projects from Visual Studio .NET
2002/2003 to Visual Studio 2005
http://msdn2.microsoft.com/en-us/library/aa479567.aspx

Common ASP.NET 2.0 Conversion Issues and Solutions
http://msdn2.microsoft.com/en-us/library/aa479312.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top