SecurityException Permission denied

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.

Who is Participating?
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.
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?
afg1976Author Commented:
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()
afg1976Author Commented:
Yes, thank you.  There is a Log file the dll is trying to write.  It could not access the directory for the log file.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.