Re: Request for permission type failed



Anthony,

This is a security issue. When run from a machine other than the local machine, .NET places restrictions on the program being run (the same is for assemblies run from the internet). In order to give your program the permissions you need, go to the .NET Administration applet (in Administrative Tools) and add a new permission set that corresponds to your application (the best thing to do here would be to key based on the strong name of your app).


--
- Nicholas Paldino [.NET/C# MVP]
- mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx

<anthony.gilliam@xxxxxxxxx> wrote in message news:1184088392.708301.150730@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi Programmer People,

I'm not an expert programmer, so please be understanding:

I've made a program that uses a DataGridView to display and edit a
DataSet. The DataSet is read from an .XML document. Changes on the
DataGridView are read and writen to the .XML using DataSet.ReadXml
and DataSet.WriteXml.

I've built and debuged the program on my computer and it works fine,
the XML file reads and writes properly. The problem I have is when I
try to open the program from a shortcut on another computer on my
local network. The .XML file will not load to the DataGridView. I
get this error:

************** Exception Text **************
System.Security.SecurityException: Request for the permission of type
'System.Security.Permissions.FileIOPermission, mscorlib,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
failed.
at System.Security.CodeAccessSecurityEngine.Check(Object demand,
StackCrawlMark& stackMark, Boolean isPermSet)
at System.Security.CodeAccessPermission.Demand()
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess
access, Int32 rights, Boolean useRights, FileShare share, Int32
bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String
msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode,
FileAccess access, FileShare share, Int32 bufferSize)
at System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials
credentials)
at System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String
role, Type ofObjectToReturn)
at System.Xml.XmlTextReaderImpl.OpenUrlDelegate(Object xmlResolver)
at System.Threading.CompressedStack.runTryCode(Object userData)
at
System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode
code, CleanupCode backoutCode, Object userData)
at System.Threading.CompressedStack.Run(CompressedStack
compressedStack, ContextCallback callback, Object state)
at System.Xml.XmlTextReaderImpl.OpenUrl()
at System.Xml.XmlTextReaderImpl.Read()
at System.Xml.XmlTextReader.Read()
at System.Xml.XmlReader.MoveToContent()
at System.Data.DataSet.ReadXml(XmlReader reader, Boolean
denyResolving)
at System.Data.DataSet.ReadXml(String fileName)
at TdsInventory.OverviewForm.OverviewForm_Load(Object sender,
EventArgs e)
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean
fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.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.Callback(IntPtr hWnd, Int32
msg, IntPtr wparam, IntPtr lparam)
The action that failed was:
Demand
The type of the first permission that failed was:
System.Security.Permissions.FileIOPermission

I've added these permissions to my code in the Main(string[] args)
function:

FileIOPermission f1 = new
FileIOPermission(PermissionState.None);
f1.AllLocalFiles = FileIOPermissionAccess.Read;

FileIOPermission f2 = new
FileIOPermission(FileIOPermissionAccess.Read,
@"C:\Projects\TdsInventory");

f2.AddPathList(FileIOPermissionAccess.Write |
FileIOPermissionAccess.Read,
@"C:\Projects\TdsInventory\PaperToner.xml");

I've also gone in the mscorcfg.msc .NET Configuration Tool under:

Runtime Security Policy->All_Code->LocalIntranet_Zone Code Group->Edit
Code Group Properties

And have made the following changes:

Membership Condition->Choose the condition type for this code group:
Zone
Membership Condition->Zone: Local Intranet
Permission Set->Permision set: FullTrust

Still, I compile the code and it runs fine on my computer, but will
load the .XML to the DataGridView on a Local Network computer. If
anyone knows what I need to do to make it work, I'd really appreciate
it!

TIA


.



Relevant Pages

  • Request for permission type failed
    ... DataGridView are read and writen to the .XML using DataSet.ReadXml ... StackCrawlMark& stackMark, Boolean isPermSet) ... access, Int32 rights, Boolean useRights, FileShare share, Int32 ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Unable to translate Unicode character u00E9 at index 5409 to specified code page.
    ... Int32 index) ... at System.Text.EncoderFallbackBuffer.InternalFallback(Char ch, Char*& chars) ... Int32 byteCount, Boolean flush, Int32& charsUsed, Int32& bytesUsed, Boolean& ... Are you perhaps trying to write out XML in an encoding like US-ASCII ...
    (microsoft.public.dotnet.xml)
  • Re: WEb Services Error
    ... XML document. ... The LoadXml method expects a string containing the string equivalent of a ... access, Int32 rights, Boolean useRights, FileShare share, Int32 ...
    (microsoft.public.dotnet.framework.aspnet)
  • cannot write file to network drive
    ... The process failed: System.Security.SecurityException: Request for the ... n of type 'System.Security.Permissions.FileIOPermission, mscorlib, ... rk& stackMark, Boolean isPermSet) ... The type of the first permission that failed was: ...
    (microsoft.public.dotnet.security)
  • RE: Move to vs2005 causes errors in external controls
    ... Okay, I tried again on the server, and managed to get the permission into ... element to the XML file you asked me to create. ... System.RuntimeTypeHandle._GetTypeByName(String name, Boolean ... Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark) +72 ...
    (microsoft.public.dotnet.framework.aspnet)