SecurityException

Hi,

I got the security exception in underlined code:

string sAppProgID = "Excel.Application";

object oExcel = null;

try

{

oExcel = Marshal.GetActiveObject(sAppProgID);

}

catch(Exception ex)

{

MessageBox.Show(ex.StackTrace);

try

{

Type tExcelObj = Type.GetTypeFromProgID(sAppProgID);

oExcel = Activator.CreateInstance(tExcelObj);

}

catch(Exception ex2)

{

MessageBox.Show(ex2.StackTrace);

return;

}

}

Why is it happened and how can I solve it

Thank's
Alexei




Answer this question

SecurityException

  • ALFKI

    Hi,

    I am getting error System.Security.Permissions.SecurityPermission, mscorlib,
    Version=1.0.5000.0, Culture=neutral

    How to solve it

    Thank's
    Alexei



  • Jamie Thomson

    Alexei_shk wrote:

    Hi,

    I know. I give to it but get the error that it can't find the object.

    Thank's
    Alexei

    What object exactly are you referring to



  • A__alex10

    Hi,

    Excel.Application

    Thank's
    Alexei



  • J Tatta

    Hi,

    The type of oExcel object is Object and I can't take the exist object of Excel or create new object of Excel. It tells me security exception. If I add it to security permissions I get error with no reference to object Excel.Application.

    Thank's
    Alexei



  • Morrissey99

    Rather than just displaying the StackTrace, try putting more of the SecurityException in your message box with MessageBox.Show (ex). I don't know all the properties SecurityException.ToString() includes in the message but it should provide more details on the security error that occurred. For even more data you could either show all the SecurityException properties or more quickly just examine ex with the debugger.


  • Lamon

    Alexei_shk wrote:

    Hi,

    Excel.Application

    Thank's
    Alexei

    I assume that Excel is running Also what is the type of your oExcel



  • 0xDEADBEEF

    Hi,

    I know. I give to it but get the error that it can't find the object.

    Thank's
    Alexei



  • Wasif235288

    Your code needs the permission to call unmanaged code.

  • SecurityException