Request for permission type failed

A

anthony.gilliam

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
 
N

Nicholas Paldino [.NET/C# MVP]

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]
- (e-mail address removed)

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
 
A

anthony.gilliam

On Jul 10, 1:44 pm, "Nicholas Paldino [.NET/C# MVP]"

Ok, I've gone to .NET Framework 2.0 Configuration tool on just my
computer and have set all of the code groups to full trust. They read
as follows:

Enterprise -
Code group grants all code full trust and forms the root of the code
group tree.

Assembly evidence must match this membership condition to belong to
the code group: All code.

Assemblies matching the membership condition are granted this
permission set at the current policy level: FullTrust.

Permission Set Description:
Allows full access to all resources

Machine -
Code group grants no permissions and forms the root of the code group
tree.

Assembly evidence must match this membership condition to belong to
the code group: All code.

Assemblies matching the membership condition are granted this
permission set at the current policy level: FullTrust.

Permission Set Description:
Allows full access to all resources

User -
Code group grants all code full trust and forms the root of the code
group tree.

Assembly evidence must match this membership condition to belong to
the code group: All code.

Assemblies matching the membership condition are granted this
permission set at the current policy level: FullTrust.

Permission Set Description:
Allows full access to all resources

I've added this permmision to my code:

FileIOPermission f1 = new
FileIOPermission(PermissionState.Unrestricted);

Still, no change. Do I have to configure something on the destination
computer?
 
N

Nicholas Paldino [.NET/C# MVP]

You should make a specific code group that corresponds to the assembly
itself, not change all the existing code groups. You can identify your code
group by the assemblies strong name.
 
A

anthony.gilliam

Thanks Nicholas,

I found out what was wrong yesterday. A: the computer I was trying to
target wasn't on My domain, so I could not simply past a shortcut to
my .exe up their; I had to put the entire file on the computer. B:
the .xml addy that I was using was a local address and not a network
address (missing \\server). C: Their was a security issue, the
calling comp. didn't have permission to write to my .xlm. Thanks for
your advice. Now that I figured out the problem, I can retighten the
security through .NET.

Take care,
Anthony
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top