Re: Notifying the user of what action to take when a SecurityException was unhandled

From: Nicole Calinoiu (calinoiu)
Date: 10/09/05

  • Next message: Nicole Calinoiu: "Re: enumerate runtime permissions"
    Date: Sun, 9 Oct 2005 09:08:17 -0400
    
    

    You'll be able to catch the exception if you wrap the call to the new
    "DoMainStuff" method in a try...catch block. In order to ensure that the
    new method isn't inlined when compiled with optimizations (which is usually
    the case when compiling in release mode), you can add a MethodImplAttribute
    as shown below:

    private static void Main(string[] args)
    {
        try
        {
            DoMainStuff(args);
        }
        catch (SecurityException ex)
        {
            // Display your preferred message for a security exception.
        }
        catch (Exception ex)
        {
            // Display your preferred message for a non-security exception.
        }
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    private static void DoMainStuff(string[] args)
    {
        // Everything that used to be in your Main method goes here
        // (including any exception handling that you already had in place).
    }

    "Jim Meyer" <jimmeyer@email.dk> wrote in message
    news:eScbvAMzFHA.3408@TK2MSFTNGP09.phx.gbl...
    > Thanks a lot for your help guys.
    >
    > I use some of the the Marshal methods for global memory which have Link
    > Demands according to the documentation. What is the best way to handle
    > this so I can catch the security exception?
    >
    > "Nicole Calinoiu" <calinoiu REMOVETHIS AT gmail DOT com> wrote in message
    > news:OF499u0yFHA.1264@tk2msftngp13.phx.gbl...
    >> In addition to the possibilities already raised by Dominick, does your
    >> Main method perhaps include a call into a type or member protected by a
    >> link demand for a CAS permission? (Link demands are processed at
    >> JIT-time, so failing a link demand in your Main method would prevent any
    >> of your code from running.) If you're not sure whether or not your Main
    >> method contains such a call, you can easily test it (at least in debug
    >> mode, where your code won't be subject to inlining) by splitting out the
    >> contents of your Main method into a separate method. e.g.:
    >>
    >> private static void Main(string[] args)
    >> {
    >> DoMainStuff(args);
    >> }
    >>
    >> private static void DoMainStuff(string[] args)
    >> {
    >> // Everything that used to be in your Main method goes here.
    >> }
    >>
    >>
    >>
    >> "Jim" <jim.work@newsgroups.nospam> wrote in message
    >> news:OVWubakyFHA.3892@TK2MSFTNGP12.phx.gbl...
    >>> I've looked at the article and the suggestions here, but the problem
    >>> persists: an exception is thrown before any of my code has had a chance
    >>> to execute. This means that I'm unable to attach exception handlers
    >>> because the first line of my static main is never reached.
    >>>
    >>> I should note that I'm using VS 2005 Beta 2 and the 2.0 Framework (Build
    >>> 50.50215).
    >>>
    >>> Jeffrey Tan[MSFT] wrote:
    >>>> Hi Jim,
    >>>>
    >>>> Thanks for your post.
    >>>>
    >>>> In addtion to Nick Hertl's reply, there is an article talked about how
    >>>> to handle unhandled exception in .Net, for your information:
    >>>> "Unexpected Errors in Managed Applications"
    >>>> http://msdn.microsoft.com/msdnmag/issues/04/06/NET/
    >>>>
    >>>> Hope this helps
    >>>>
    >>>> Best regards,
    >>>> Jeffrey Tan
    >>>> Microsoft Online Partner Support
    >>>> Get Secure! - www.microsoft.com/security
    >>>> This posting is provided "as is" with no warranties and confers no
    >>>> rights.
    >>>>
    >>
    >>
    >
    >


  • Next message: Nicole Calinoiu: "Re: enumerate runtime permissions"

    Relevant Pages

    • RE: Biztalk 2006 Tutorial 3
      ... Exception type: ServiceCreationException ... Microsoft.BizTalk.XLANGs.BTXEngine.BTXSession._createOrRehydrateRealService(Guid& instanceId, IBTMessage currMsg) ... md, Objectargs, Object server, Int32 methodPtr, Boolean fExecuteInContext, ...
      (microsoft.public.biztalk.general)
    • Re: COM DLL works fine in C# but not when using Remoting
      ... > Unhandled Exception: System.Runtime.InteropServices.COMException ... The server threw an exception. ... > mb, Objectargs, Object server, Int32 methodPtr, Boolean ...
      (microsoft.public.dotnet.framework.remoting)
    • RE: Biztalk 2006 Tutorial 3
      ... Exception type: ServiceCreationException ... Microsoft.BizTalk.XLANGs.BTXEngine.BTXSession._createOrRehydrateRealService(Guid& instanceId, IBTMessage ... md, Objectargs, Object server, Int32 methodPtr, Boolean fExecuteInContext, ...
      (microsoft.public.biztalk.general)
    • RE: Biztalk 2006 Tutorial 3
      ... Try stopping and restarting the biztalk service. ... Exception type: ServiceCreationException ... Microsoft.BizTalk.XLANGs.BTXEngine.BTXSession._createOrRehydrateRealService(Guid& instanceId, IBTMessage ... md, Objectargs, Object server, Int32 methodPtr, Boolean fExecuteInContext, ...
      (microsoft.public.biztalk.general)
    • RE: Biztalk 2006 Tutorial 3
      ... Below is the error message that appears in the event ... Exception type: ServiceCreationException ... Microsoft.BizTalk.XLANGs.BTXEngine.BTXSession._createOrRehydrateRealService(Guid& instanceId, IBTMessage currMsg) ... md, Objectargs, Object server, Int32 methodPtr, Boolean fExecuteInContext, ...
      (microsoft.public.biztalk.general)