SecurityException Permission denied

Posted on 2006-04-06
Last Modified: 2008-01-09
I have a C# windows application written using VS .NET 2005.  In my application I am referencing a COM dll that has a procedure named SendToDDC.  When my code calls this procedure, I am getting an unhandled SecurityException 'Permission denied'.  I call this procedure mulitple times in my code.  The first call always works successfully, but any subsequent calls receive the exception.  I do not need to know how to handle the exception, but I would like to know what I need to do to avoid it.  I need to call this procedure or my application is useless.

Question by:afg1976
    LVL 11

    Expert Comment

    Hard to say without knowing what the com dll does, perhaps it's like the CDONTS mail object and needs to be destroyed and recreated each time you use it?
    LVL 2

    Author Comment

    The dll sends data to an ERP system over TCP and then gets a response and sends it back to my application.  The dll has no procedures for destroying the object.  I do have line: ddc = null;  

    Is there a better way to do what you are indicating?  I have included my code that calls the Procedure SendToDDC below.  I also have the details of the exception below that.  

    using System;
    using System.Collections.Generic;
    using System.Configuration;
    using System.Text;

    namespace PowerTAP
        class cDDCManager
            private string DDC_DELIMETER = ConfigurationSettings.AppSettings["DDCDelimeter"].ToString();
            private string DDC_HOSTIP = ConfigurationSettings.AppSettings["DDCHostIP"].ToString();
            private int DDC_PORT = Convert.ToInt16(ConfigurationSettings.AppSettings["DDCPort"]);
            private int DDC_TIMEOUT = Convert.ToInt16(ConfigurationSettings.AppSettings["DDCTimeout"]);
            private bool DDC_LOOPBACK = Convert.ToBoolean(ConfigurationSettings.AppSettings["LoopBack"]);
            private string DDC_LOGFILE = ConfigurationSettings.AppSettings["LogFile"].ToString();
            private int DDC_SESSIONID = Convert.ToInt16(ConfigurationSettings.AppSettings["DDCSessionId"]);
            public int errorCount = 0;
            public enum ddcFunction

            private string[] p_returnValues;

            public string returnValue(int idx)
                    return p_returnValues[idx];
                    return "0";

            public string callDDC(ddcFunction function, string[] ddcParams)
                string defaultServer = "tihrac863m000";
                DisusDDC.DDCcom ddc = new DisusDDC.DDCcom();
                ddc.DDCDelimiter = DDC_DELIMETER;
                ddc.DDCHostIP = DDC_HOSTIP;
                ddc.DDCPort = DDC_PORT;
                ddc.DDCSessionId = DDC_SESSIONID;
                ddc.DDCTimeout = DDC_TIMEOUT;
                ddc.LoopBack = DDC_LOOPBACK;
                ddc.LogFile = DDC_LOGFILE;


                ddc.DDCServer = defaultServer;
                ddc.DDCFunction = function.ToString();

                for (int i = 0; i <= ddcParams.GetUpperBound(0); i++)
                    ddc.SetDDCParam(ref ddcParams[i]);

                if (ddc.SendToDDC())
                    p_returnValues = new string[ddc.ResponseCount];
                    for (int i = 0; i < ddc.ResponseCount; i++)
                        p_returnValues[i] = ddc.GetResponse(i+1);
                    return "Success";
                    errorCount = ddc.ErrorCount;
                    p_returnValues = new string[errorCount];
                    for (int i = 0; i < errorCount; i++)
                        p_returnValues[i] = ddc.GetError(i+1);
                    return "Error";
                ddc = null;

    Also, here is the Exception details:
    System.Security.SecurityException was unhandled
      Message="Permission denied"
           at DDC.DDCcomClass.SendToDDC()
           at PowerTAP.cDDCManager.callDDC(ddcFunction function, String[] ddcParams) in C:\Documents and Settings\andrew\My Documents\Visual Studio 2005\Projects\PowerTAP\PowerTAP\cDDCManager.cs:line 68
           at PowerTAP.EmployeeAction.btnTimeIn_Click(Object sender, EventArgs e) in C:\Documents and Settings\andrew\My Documents\Visual Studio 2005\Projects\PowerTAP\PowerTAP\EmployeeAction.cs:line 108
           at System.Windows.Forms.Control.OnClick(EventArgs e)
           at System.Windows.Forms.Button.OnClick(EventArgs e)
           at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
           at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
           at System.Windows.Forms.Control.WndProc(Message& m)
           at System.Windows.Forms.ButtonBase.WndProc(Message& m)
           at System.Windows.Forms.Button.WndProc(Message& m)
           at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
           at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
           at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
           at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
           at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
           at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
           at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
           at System.Windows.Forms.Application.Run(Form mainForm)
           at PowerTAP.Program.Main() in C:\Documents and Settings\andrew\My Documents\Visual Studio 2005\Projects\PowerTAP\PowerTAP\Program.cs:line 17
           at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
           at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel)
           at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()
           at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)
           at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext)
           at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
           at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
           at System.Threading.ExecutionContext.runTryCode(Object userData)
           at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
           at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           at System.Threading.ThreadHelper.ThreadStart()
    LVL 11

    Accepted Solution

    Mmmm, personal folders have security restrictions on them by default (so another non admin user logging on cannot see your docs etc.) try changing the projects folder to allow full control to everyone, the com dll might be trying to write to the local directory and does not have the same sort of disk permissions the calling .net app has.
    LVL 2

    Author Comment

    Yes, thank you.  There is a Log file the dll is trying to write.  It could not access the directory for the log file.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Article by: Najam
    Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
    Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now