Newbie Question: System.Security.SecurityException?

B

Ben

Hi,

I'm new to VB.Net programming, and am trying to learn VB using the new
Visual Studeio 2008 Express Edition. I've decided just to jump
straight in and try to program a simple mail form with 3 fields, 'to',
'subject' & 'body'. Running through the debugger, most of the code
seems to work, however I keep getting the following security error,
even though I have set the application as a full trusted application.

A first chance exception of type 'System.Security.SecurityException'
occurred in MyApplication.exe

Request for the permission of type
'System.Web.AspNetHostingPermission, System, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

The code that this happens on is the line below with the Call function
in.

Private Sub SendMail_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles SendMail.Click
Call SendMailSub(StrMailTo.Text, StrMailSub.Text,
StrMailBody.Text)
MsgBox("Your Messege Has Been Sent", MsgBoxStyle.Information,
"Messege Sent")
End Sub

Can anyone please help with this error?

Many thanks

Ben
 
P

Phill W.

Ben said:
I'm new to VB.Net programming, and am trying to learn VB using the new
Visual Studeio 2008 Express Edition. I've decided just to jump
straight in and try to program a simple mail form with 3 fields, 'to',
'subject' & 'body'. Running through the debugger, most of the code
seems to work, however I keep getting the following security error,
even though I have set the application as a full trusted application.

A first chance exception of type 'System.Security.SecurityException'
occurred in MyApplication.exe

Request for the permission of type
'System.Web.AspNetHostingPermission, System, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

What /sort/ of application is this?
".exe" implies a Windows Forms or Console application, but ASPnet
[usually] brings the "Web" stuff into play.
The code that this happens on is the line below with the Call function
in.

I would say that was unlikely. There's nothing in that line to suggest
any need for additional security permissions.

Have you tried catching the Exception and displaying its StackTrace,
which will tell which routine actually failed?
That would give you a little more to work on:

Private Sub SendMail_Click( _
ByVal sender As System.Object _
, ByVal e As System.EventArgs _
) Handles SendMail.Click
Try

SendMailSub(StrMailTo.Text, StrMailSub.Text, StrMailBody.Text)

MsgBox("Your Message Has Been Sent" _
, MsgBoxStyle.Information _
, "Message Sent" _
)

Catch( ex as Exception )

MsgBox( ex.GetType().ToString() )
MsgBox( ex.Message )
MsgBox( ex.StackTrace )
MsgBox( ex.ToString() ) ' the best for last...

End Try
End Sub

HTH,
Phill W.
 
B

Ben

And the exact line is ? I assume it would be rather inside "SendMailSub".
The weird thing is that this is AspNetHostingPermission which should likely
be used in ASP.NET application. This is a Windows application ? What are you
using in the System.Web namespace ?

If you are using System.Web.MailMessage this is obsoleted. You may want to
try using System.Net.Mail instead as the comiler should have warned you....

--
Patrice

"Ben" <[email protected]> a écrit dans le message de groupe de
discussion :
(e-mail address removed)...












- Show quoted text -

Hi Patrice,

Thanks for the reply.

The code that was erroring was the call function line: Call
SendMailSub(StrMailTo.Text, StrMailSub.Text,
StrMailBody.Text)

Strangely the compiler didn't say that System.Web.MailMessage was
obsoleted until I decided to create a new project, and copied the
existing code into it, then it flagged it up, and suggested
System.Net.Mail. I just finished changing it over to use
System.Net.Mail, and it works. Yay! My first VB.NET application :)

Thanks for the help!

Ben
 

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