App_Code class not working

M

mark.irwin

Need help.

I create a vb file in my app_code folder. Here is the code:

Imports Microsoft.VisualBasic
Imports System.Net.Mail


Public Class email_error

Public Function Send_Error(ByVal str_Page As String, ByVal str_Message
As String, _
ByVal str_SQL As String, ByVal str_StackTrace As String, _
ByVal str_ExString As String) As String

Dim str_Error As String = ""
Dim str_eMail As String = "XXXXXXXXX"

Dim mail As New MailMessage(str_eMail, str_eMail)

mail.IsBodyHtml = True

mail.Subject = "Outside Web Error " & str_Page

str_Error = "<b>Page:</b><br>" & str_Page & "<br><br>" _
& "<b>Message:</b><br>" & str_Message & "<br><br>" _
& "<b>SQL String:</b><br>" & str_SQL & "<br><br>" _
& "<b>Everything:</b><br>" & str_ExString & "<br><br>" _
& "<br><b>StackTrace:</b>:<br>" & str_StackTrace

mail.Body = str_Error

Dim instance As New SmtpClient("XXXXXX")

instance.Send(mail)

Return str_Error

End Function
End Class


Then I call this code like this:

Dim myEmail As New email_error

myEmail.Send_Error(Request.ServerVariables("Path_Info"), ex.Message,
strSQL, ex.StackTrace.ToString, ex.ToString)

All of this works just fine UNLESS the folder that the file with this
code is an application in IIS. If I remove the application it works
but everything else starts blowing up.

The error I get when I have the application created is this:

Description: An error occurred during the compilation of a resource
required to service this request. Please review the following specific
error details and modify your source code appropriately.

Compiler Error Message: BC30002: Type 'email_error' is not defined.

With this line highlighted:

Dim myEmail As New email_error

Does anyone have any ideas?

Thanks in advance.
 
C

Christopher Reed

Are you saying that it doesn't work when the app_code directory is marked as
an application in IIS?
 
M

mark.irwin

No, it doesnt work when the folder that the code calling the class is
in is marked as an application.
 
M

mark.irwin

Well all the code works fine if i remove the application in IIS from
the folder holding my web code (i.e. Page in folder "web_pages" called
"test_email", if i remove the IIS application from "web_pages"
everything works great with calling the class in "App_Code", once I
re-apply the application I get the "Type 'email_error' is not defined."
 
C

Christopher Reed

The App_Code subdirectory shouldn't be marked as an application. It is
strictly dependent on the main website application.

If this isn't what is happening, then please elaborate further.
 
M

mark.irwin

the App_Code directory is not marked as an application, just the
directory with all my aspx files in it. And thats what is not working.
folder "web_pages" contains all my aspx files. Some of those files
are calling a class in the App_Code folder. Intellisense knows about
the class in the .vb file in the App_Code folder and the functions in
that class. So that all works, and building the website shows no
errors. But when I hit the web page I get the "Type is not defined"
error.
 
M

mark.irwin

yes i am using them thru web.config

<namespaces>
<add namespace="System"/>
<add namespace="System.Configuration"/>
<add namespace="System.Web"/>
<add namespace="System.Web.UI"/>
<add namespace="System.Web.UI.WebControls"/>
<add namespace="System.Web.UI.WebControls.Image"/>
<add namespace="System.Web.UI.HTMLControls"/>
<add namespace="System.Collections"/>
<add namespace="System.Text.RegularExpressions"/>
<add namespace="System.Math"/>
<add namespace="Microsoft.VisualBasic"/>
<add namespace="System.Configuration"/>
<add namespace="System.Data"/>
<add namespace="System.Data.SqlClient"/>
<add namespace="System.Net.Mail"/>
</namespaces>
 

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

Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,708
Latest member
SherleneF1

Latest Threads

Top