none
Unhandled Exception: System.Security.SecurityException:

    Question

  • I made a console application in Visual Studio that reads a flat file from our customer and updates the oracle database depending on the received data.

    I use streamreader / writer to read and write some files.

    When I run my exe file locally everthing works fine.  When this exe is run on the application server this gives following error message :

     

    Unhandled Exception: System.Security.SecurityException: Request for the permiss
    on of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0
    0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
       at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlM
    rk& stackMark, Boolean isPermSet)
       at System.Security.CodeAccessPermission.Demand()
       at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access,
    nt32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions
    ptions, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
       at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access,
    FileShare share, Int32 bufferSize, FileOptions options)
       at System.IO.StreamWriter.CreateFile(String path, Boolean append)
       at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encodi
    g, Int32 bufferSize)
       at System.IO.StreamWriter..ctor(String path)
       at COD_ITB.App_main_process.main()
    The action that failed was:
    Demand
    The type of the first permission that failed was:
    System.Security.Permissions.FileIOPermission
    The first permission that failed was:
    <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Ver
    ion=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
    version="1"
    Write="\\GBN66W\GROUP\PROLOGS\SCRIPTS\BAT\DB52\TABAC\ITB\COD_ITB\LOG\LOG_ERROR"
    >

    The demand was for:
    <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Ver
    ion=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
    version="1"
    Write="\\GBN66W\GROUP\PROLOGS\SCRIPTS\BAT\DB52\TABAC\ITB\COD_ITB\LOG\LOG_ERROR"
    >

    The granted set of the failing assembly was:
    <PermissionSet class="System.Security.PermissionSet"
    version="1">
    <IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib
     Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
    version="1"
    Read="USERNAME"/>
    <IPermission class="System.Security.Permissions.FileDialogPermission, mscorlib,
    Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
    version="1"
    Unrestricted="true"/>
    <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Ver
    ion=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
    version="1"
    Read="P:\BAT\DB52\TABAC\ITB\COD_ITB\"
    PathDiscovery="P:\BAT\DB52\TABAC\ITB\COD_ITB\"/>
    <IPermission class="System.Security.Permissions.IsolatedStorageFilePermission,
    scorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
    version="1"
    Allowed="AssemblyIsolationByUser"
    UserQuota="9223372036854775807"
    Expiry="9223372036854775807"
    Permanent="True"/>
    <IPermission class="System.Security.Permissions.ReflectionPermission, mscorlib,
    Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
    version="1"
    Flags="ReflectionEmit"/>
    <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, V
    rsion=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
    version="1"
    Flags="Assertion, Execution, BindingRedirects"/>
    <IPermission class="System.Security.Permissions.UIPermission, mscorlib, Version
    2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
    version="1"
    Unrestricted="true"/>
    <IPermission class="System.Security.Permissions.UrlIdentityPermission, mscorlib
     Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
    version="1"
    Url="file:///P:/BAT/DB52/TABAC/ITB/COD_ITB/COD_ITB.exe"/>
    <IPermission class="System.Security.Permissions.ZoneIdentityPermission, mscorli
    , Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
    version="1"
    Zone="Intranet"/>
    <IPermission class="System.Net.DnsPermission, System, Version=2.0.0.0, Culture=
    eutral, PublicKeyToken=b77a5c561934e089"
    version="1"
    Unrestricted="true"/>
    <IPermission class="System.Drawing.Printing.PrintingPermission, System.Drawing,
    Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
    version="1"
    Level="DefaultPrinting"/>
    </PermissionSet>

    The assembly or AppDomain that failed was:
    COD_ITB, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
    The method that caused the failure was:
    Void main()
    The Zone of the assembly that failed was:
    Intranet
    The Url of the assembly that failed was:
    file:///P:/BAT/DB52/TABAC/ITB/COD_ITB/COD_ITB.exe

    Can someone help me with this issue.

    I am pretty unexperienced in developing VB applications

    Thursday, April 05, 2007 2:42 PM

Answers

  • I too had the same problem

     

    My Error msg is ::..        Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

    Then i placed one new attribute like this

    [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Assert, Unrestricted = true)]

    private void ........... .... ... ... ...

     

    Its working for me

     

    Moorthy A

    Friday, April 13, 2007 7:06 PM
  •   Please view the attribute location:

    using System;
      namespace ConsoleApplication
      {
         [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")]

       class Program
          {
              static void Main(string[] args)
              {
                   ...
              } 
          }
      }

     

     

    Tuesday, April 17, 2007 2:38 AM
  • change following :  

    <System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Assert, Unrestricted = True)> _

    to :

    <System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Assert, Unrestricted:=True)> _

    Tuesday, July 01, 2008 7:23 AM

All replies

  • See http://blogs.msdn.com/shawnfa/archive/2003/06/20/57023.aspx for a
    description of the problem and some approaches to resolving the issue.
    Since you're using .NET 2.0, you also have the additional option of
    deploying as a ClickOnce application that requests additional CAS
    permissions.  If you're interested in
    learning about ClickOnce,
    http://msdn2.microsoft.com/en-us/vbasic/ms789088.aspx might be a good place
    to start.  For more in-depth information, see
    http://msdn2.microsoft.com/en-us/library/t71a733d.aspx.
    Thursday, April 05, 2007 5:45 PM
  • I too had the same problem

     

    My Error msg is ::..        Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

    Then i placed one new attribute like this

    [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Assert, Unrestricted = true)]

    private void ........... .... ... ... ...

     

    Its working for me

     

    Moorthy A

    Friday, April 13, 2007 7:06 PM
  • Please try adding the attribute:

    [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")]
      class ConsoleProgram

    {

       ...

    }

    Monday, April 16, 2007 10:55 AM
  • Martin.

    Hit the same issue.  NOt sure where best to add the attribute you have outlined....

     

    Thanks..

     

    Ray

    • Proposed as answer by Lerun Be Friday, January 17, 2014 9:29 PM
    Monday, April 16, 2007 6:18 PM
  •   Please view the attribute location:

    using System;
      namespace ConsoleApplication
      {
         [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")]

       class Program
          {
              static void Main(string[] args)
              {
                   ...
              } 
          }
      }

     

     

    Tuesday, April 17, 2007 2:38 AM
  • I was getting the same error (trying to run a .NET exec from a network share).  I added the attribute but now I get this error - how do I modify the granted permissions to that they're granted upon demand?

     

    The action that failed was:
    Demand
    The type of the first permission that failed was:
    System.Security.PermissionSet
    The demand was for:
    <PermissionSet class="System.Security.PermissionSet"
    version="1"
    Unrestricted="true"/>

    The granted set of the failing assembly was:
    <PermissionSet class="System.Security.PermissionSet"
    version="1">
    <IPermission class="System.Security.Permissions.FileDialogPermission, mscorlib,
    Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
    version="1"
    Access="Open"/>
    <IPermission class="System.Security.Permissions.IsolatedStorageFilePermission, m
    scorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
    version="1"
    Allowed="ApplicationIsolationByUser"
    UserQuota="512000"/>
    <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Ve
    rsion=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
    version="1"
    Flags="Execution"/>
    <IPermission class="System.Security.Permissions.UIPermission, mscorlib, Version=
    2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
    version="1"
    Window="SafeTopLevelWindows"
    Clipboard="OwnClipboard"/>
    <IPermission class="System.Security.Permissions.UrlIdentityPermission, mscorlib,
     Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
    version="1"
    Url="y:\tools\ascmd.exe"/
    >
    <IPermission class="System.Security.Permissions.ZoneIdentityPermission, mscorlib
    , Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
    version="1"
    Zone="Internet"/>
    <IPermission class="System.Drawing.Printing.PrintingPermission, System.Drawing,
    Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
    version="1"
    Level="SafePrinting"/>
    </PermissionSet>

    Thursday, April 26, 2007 7:36 PM
  • Any idea.. same problem here....

    - Message: Request for the permission of type 'System.Security.Permissions.UIPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
    Source: Check
    Version: mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

    at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)
       at System.Security.CodeAccessPermission.Demand()
       at System.Windows.Forms.Control.FromHandle(IntPtr handle)
       at Infragistics.Win.UltraWinToolbars.UltraToolbarsManager.HookProc(Int32 ncode, IntPtr wParam, IntPtr lParam)
       at System.Windows.Forms.UnsafeNativeMethods.IntCreateWindowEx(Int32 dwExStyle, String lpszClassName, String lpszWindowName, Int32 style, Int32 x, Int32 y, Int32 width, Int32 height, HandleRef hWndParent, HandleRef hMenu, HandleRef hInst, Object pvParam)
       at System.Windows.Forms.UnsafeNativeMethods.CreateWindowEx(Int32 dwExStyle, String lpszClassName, String lpszWindowName, Int32 style, Int32 x, Int32 y, Int32 width, Int32 height, HandleRef hWndParent, HandleRef hMenu, HandleRef hInst, Object pvParam)
       at System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
       at System.Windows.Forms.Control.CreateHandle()
       at System.Windows.Forms.Form.CreateHandle()
       at System.Windows.Forms.Control.get_Handle()
       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.Form.ShowDialog(IWin32Window owner)
       at FFDT.Vegas.Client.MainForm.ShowException(Exception ex)
       at FFDT.Framework.Plugins.PluginForm.ShowException(Exception ex)
       at FFDT.ControlMessages.GUI.ControlForm.ControlForm_TextChanged(Object sender, EventArgs e)
       at System.EventHandler.Invoke(Object sender, EventArgs e)
       at System.Windows.Forms.Control.OnTextChanged(EventArgs e)
       at System.Windows.Forms.Form.OnTextChanged(EventArgs e)
       at System.Windows.Forms.Control.set_Text(String value)
       at System.Windows.Forms.Form.set_Text(String value)
       at FFDT.Vegas.Client.MainForm.StartControlMessages(PluginForm controlPlug)



    Tuesday, May 08, 2007 11:37 PM
  •  

    I got the same error. I have web shared a windows application. The application uses some files which are in same webshare but different folder. when i open the application from browser and click button to fetch files it throwed me the same error...   its a vb .net application.....  help me how to resolve this issue.....

     

    Error :

    System.Security.SecurityException: Request for the permission of type System.Security.Permissions.ReflectionPermission, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 failed.

    Friday, September 28, 2007 6:18 PM
  •  

    Were did you post

     

    [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Assert, Unrestricted = true)]?

     

    Can you walk me thru how to do this step by step?

    Monday, October 22, 2007 11:01 PM
  • I too have a problem with a console application.  It runs fine in the debugger mode.  When I put the compiled executable on the shared network drive I get the same security error.  I have put your line of code in as suggested, however, when I compile it gives me an error Bracketed identifier is missing closing ']'  I don't understand what is wrong.

     

    Option Explicit On

    Imports System

    Imports System.IO

    Imports System.Security

    Imports System.Security.Permissions

    Imports System.Collections

    [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Assert, Unrestricted = true)]

    Module Module1

    Dim sw As StreamWriter, sr As StreamReader, OutFile As String

    Sub Main()

    '*** Get file name and parameters from the console ***

    Console.WriteLine(System.Environment.CurrentDirectory)

    Dim Usage As String

        Usage = Chr(10) + "MISSING PARAMETERS - TEXT2PDF USAGE IS AS FOLLOWS:" _

        + Chr(10) + Chr(10) + "TEXT2PDF S:\SHARED\PATH\FILENAME"

    Dim cmdArg1 As String

        cmdArg1 = ""

    Try

        cmdArg1 = Environment.GetCommandLineArgs(1)

    Catch NoArg As Exception

        cmdArg1 = ""

    End Try

    Wednesday, March 19, 2008 9:45 PM
  • In my vb module I put:

     

    <System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Assert, Unrestricted = True)> _

    Private Sub test5()

      ' some code'

    End Sub

     

    (Note the underscore at the end of the System... line)

     

    The word "Unrestricted" is underlined and hovering over it says "Name Unrestricted is not declared".

     

    Saturday, May 10, 2008 11:19 PM
  • change following :  

    <System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Assert, Unrestricted = True)> _

    to :

    <System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Assert, Unrestricted:=True)> _

    Tuesday, July 01, 2008 7:23 AM
  • Thanks
    Friday, August 22, 2008 2:44 PM
  • Hi All -

    I am still getting the same error...
    This is what i have in my Module:

    =============================================================================================
    Option Explicit On
    Imports
    System
    Imports System.IO
    Imports System.Security
    Imports System.Security.Permissions
    Imports System.Collections
    <System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Assert, Unrestricted:=
    True)> _
    Module Module1
    Public Sub StoreSettings()
    Dim fs As New FileStream("C:\NetEmail.ini", FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite)
    Dim s As New StreamWriter(fs)
    s.WriteLine(PbsNetEmail.txtMyOutGoingEmail.Text)
    s.Close()
    MsgBox(
    "Settings Saved...", MsgBoxStyle.Information)
    End Sub
    End
    Module
    =============================================================================================

    I am running the exe from a mapped drive on another machine.
    storing the ini file on my local drive.
    If i Run locally, no problems.
    Also, when i run the exe from the network - i get a "Microsoft.Net Security Warning"

    I would appreciate any help!

    thanks.
    Poy
    • Proposed as answer by Anaue Monday, November 16, 2009 5:32 PM
    Thursday, October 09, 2008 12:45 AM
  • Hi,

    I faced the same problem here and solved it by enabling ClickOne Settings.

    Using  VS2008.
    On Project > ... Properties...
    On tab Security, check the "Enable ClickOne Settings". And choose the rigth kind of permissions for your application

    i hope this help.

    Anaue
    Monday, November 16, 2009 5:53 PM
  • <System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Assert, Unrestricted:=True)> _

    solution  fixed my problem :)
    Wednesday, February 17, 2010 4:57 PM
  • Hi mfyuce,

    I'm using C#.Net class library and facing the same problem.

    "[System.Security.Permissions.

    PermissionSet(System.Security.Permissions.SecurityAction.Assert, Unrestricted = true)]"

    This didn't help me to solve the problem. Can you suggest the solution. Thanks in advance

     

    Wednesday, May 26, 2010 12:30 PM
  • Hi Anaue,

    I'm using C#.Net class library and facing the same problem. In Properties window, I didn't find Security tab. where I can change the permission settings. Thanks in advance.

    Wednesday, May 26, 2010 12:32 PM
  • Hi 

    i am getting the same error except version 4.0.

    i would like to know where exactly we insert

    ''

    [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Assert, Unrestricted = true)]

    ''

    Thursday, August 01, 2013 12:12 AM