Newbie Question: System.Security.SecurityException?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ben

    Newbie Question: System.Security.SecurityException?

    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.Securit y.SecurityExcep tion'
    occurred in MyApplication.e xe

    Request for the permission of type
    'System.Web.Asp NetHostingPermi ssion, System, Version=2.0.0.0 ,
    Culture=neutral , PublicKeyToken= b77a5c561934e08 9' 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.EventArg s) Handles SendMail.Click
    Call SendMailSub(Str MailTo.Text, StrMailSub.Text ,
    StrMailBody.Tex t)
    MsgBox("Your Messege Has Been Sent", MsgBoxStyle.Inf ormation,
    "Messege Sent")
    End Sub

    Can anyone please help with this error?

    Many thanks

    Ben
  • Patrice

    #2
    Re: Newbie Question: System.Security .SecurityExcept ion?

    And the exact line is ? I assume it would be rather inside "SendMailSu b".
    The weird thing is that this is AspNetHostingPe rmission 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.Mail Message this is obsoleted. You may want to
    try using System.Net.Mail instead as the comiler should have warned you...

    --
    Patrice


    "Ben" <bjblackmore@ho tmail.coma écrit dans le message de groupe de
    discussion :
    53b857ab-11b7-444d-9b73-dae40bc37067...l egroups.com...
    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.Securit y.SecurityExcep tion'
    occurred in MyApplication.e xe
    >
    Request for the permission of type
    'System.Web.Asp NetHostingPermi ssion, System, Version=2.0.0.0 ,
    Culture=neutral , PublicKeyToken= b77a5c561934e08 9' 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.EventArg s) Handles SendMail.Click
    Call SendMailSub(Str MailTo.Text, StrMailSub.Text ,
    StrMailBody.Tex t)
    MsgBox("Your Messege Has Been Sent", MsgBoxStyle.Inf ormation,
    "Messege Sent")
    End Sub
    >
    Can anyone please help with this error?
    >
    Many thanks
    >
    Ben

    Comment

    • Phill W.

      #3
      Re: Newbie Question: System.Security .SecurityExcept ion?

      Ben wrote:
      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.Securit y.SecurityExcep tion'
      occurred in MyApplication.e xe
      >
      Request for the permission of type
      'System.Web.Asp NetHostingPermi ssion, System, Version=2.0.0.0 ,
      Culture=neutral , PublicKeyToken= b77a5c561934e08 9' 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.EventArg s _
      ) Handles SendMail.Click
      Try

      SendMailSub(Str MailTo.Text, StrMailSub.Text , StrMailBody.Tex t)

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

      Catch( ex as Exception )

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

      End Try
      End Sub

      HTH,
      Phill W.

      Comment

      • Ben

        #4
        Re: Newbie Question: System.Security .SecurityExcept ion?

        On 26 Jun, 12:30, "Patrice" <http://www.chez.com/scribe/wrote:
        And the exact line is ? I assume it would be rather inside "SendMailSu b".
        The weird thing is that this is AspNetHostingPe rmission 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.Mail Message this is obsoleted. You may want to
        try using System.Net.Mail instead as the comiler should have warned you....
        >
        --
        Patrice
        >
        "Ben" <bjblackm...@ho tmail.coma écrit dans le message de groupe de
        discussion :
        53b857ab-11b7-444d-9b73-dae40bc37...@k3 7g2000hsf.googl egroups.com...
        >
        >
        >
        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.Securit y.SecurityExcep tion'
        occurred in MyApplication.e xe
        >
        Request for the permission of type
        'System.Web.Asp NetHostingPermi ssion, System, Version=2.0.0.0 ,
        Culture=neutral , PublicKeyToken= b77a5c561934e08 9' 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.EventArg s) Handles SendMail.Click
               Call SendMailSub(Str MailTo.Text, StrMailSub.Text ,
        StrMailBody.Tex t)
               MsgBox("Your Messege Has Been Sent", MsgBoxStyle.Inf ormation,
        "Messege Sent")
           End Sub
        >
        Can anyone please help with this error?
        >
        Many thanks
        >
        Ben- Hide quoted text -
        >
        - Show quoted text -
        Hi Patrice,

        Thanks for the reply.

        The code that was erroring was the call function line: Call
        SendMailSub(Str MailTo.Text, StrMailSub.Text ,
        StrMailBody.Tex t)

        Strangely the compiler didn't say that System.Web.Mail Message 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

        Comment

        Working...