• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 846
  • Last Modified:

Easy Question Re: FileIOPermission

I am writing a very simple C# application to help with my kids' reading.  The app consists of a form with a button that brings up randomly one of a hundred words stored in an array and the play button plays me reading that word stored in an individual .wav file.  The program plays fine on my computer but when I run it on their computer I get the following error message:

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.Directory.GetCurrentDirectory()
   at TopWords.Form1.button2_Click_1(Object sender, EventArgs e)
   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.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
The Zone of the assembly that failed was:
Internet

My first version of the code did not have the Directory.GetCurrentDirectory() method and looked for the .wav files in a set place.  I modified it this morning and now get the message as above.  Here is the code from the button click method:  
private void button2_Click_1(object sender, EventArgs e)
        {
        if (label1.Text != "          ")
        {
           
            FileIOPermission f = new FileIOPermission(PermissionState.None);
            f.AllLocalFiles = FileIOPermissionAccess.AllAccess;
            string currentDirectory = Directory.GetCurrentDirectory();
            System.Media.SoundPlayer myPlayer = new System.Media.SoundPlayer();
            string FileName;
            FileName = currentDirectory +"\\"+label1.Text+".wav";
            myPlayer.SoundLocation = @FileName;
            myPlayer.Play();
         
        }
        }

Any help would be appreciated...I am very novice with C# and .Net.
Thanks,
Doug.
0
djma
Asked:
djma
  • 2
  • 2
1 Solution
 
Bob LearnedCommented:
Doug,

It sounds like you are running the application on one machine from a folder on your development machine.  There are zones in the .NET security framework.  My Computer gets full trust by default, but anything else is considered a partially trusted environment.

The term is "Code Access Security", and has a pretty large footprint.

Understanding .NET Code Access Security
http://www.codeproject.com/KB/security/UB_CAS_NET.aspx
0
 
djmaAuthor Commented:
No, I am running as a standalone application from a desktop machine loading the file from my server.  It is funny, the application (this is my first c# app) took me half an hour to write and this error has taken me hours to track down.  .NET is extremely complicated for a middle aged newbie.

I am looking through the Code Access Security link which co-incidentally I came across when doing my first pass through for a solution.  Although I will try and code this myself if you could tell my which namespace I need and how to call for FullTrust...it would be appreciated.
Thanks,
Doug.
0
 
Bob LearnedCommented:
One way to solve this is to make sure that the computer has My Computer zone set to Full Trust.


Start Menu | Administrative Tools | Microsoft .NET Framework 2.0 Configuration | Configure Code Access Security Policy | Adjust Zone Security

Make changes to this computer
My Computer is selected by default
Slider needs to be at the top (Full Trust)
0
 
grayeCommented:
Be aware that you kid's PC might not have the control panel applet installed.
Take a look at the following article that provides a technique installing the missing applet (and for adjusting CAS without the control panel appet):  http://home.hot.rr.com/graye/Articles/CodeAccessSecurity.htm
0
 
djmaAuthor Commented:
Thanks everyone for your help.  I was able to fix it by adjusting the Intranet zone in Internet Explorer and adding my server drive to the list.  Nevertheless, this seems extremely complicated for an old fart like me who only wanted to write a quick app for his kids.  Anyway, I guess I should be using a less sophisticated (and complicated) tool.  I could have done the whole thing in a few minutes using FoxPro but I thought it would be fun to use c#.  Anyway, I am now wiser.  Thanks again.
Doug.
0
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.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now