Home All Groups Group Topic Archive Search About

why i get UnauthorizedAccess Exception?

Author
7 Mar 2005 7:41 PM
may mana via .NET 247
I get some marvelous error from my c# program again & again, i guess it is a security exception error, so i disable security with caspol -s off, give it full trust, copy it to hard drive, copy it to cd drive, sign it with public/private key, in all these cases i got the same exception, i use framework 1.1.4322. and just want to read the file, not write to it, also i am admin of my computer! and it is in the same directory. why i got this error?
below you can see the exception text.
access to the path "g:\saving document6.cad" is denied
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.UnauthorizedAccessException: Access to the path "G:\saving document6.cad" is denied.
   at System.IO.__Error.WinIOError(Int32 errorCode, String str)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath, Boolean bFromProxy)
   at System.IO.FileStream..ctor(String path, FileMode mode)
   at wordtraining.main.lessonup()
   at wordtraining.main.lbxLesson_DoubleClick(Object sender, EventArgs e)
   at System.Windows.Forms.Control.OnDoubleClick(EventArgs e)
   at System.Windows.Forms.ListBox.WndProc(Message& m)
   at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Loaded Assemblies **************
mscorlib
    Assembly Version: 1.0.5000.0
    Win32 Version: 1.1.4322.573
    CodeBase: file:///c:/winnt/microsoft.net/framework/v1.1.4322/mscorlib.dll
----------------------------------------
wordtraining
    Assembly Version: 1.0.1249.40111
    Win32 Version: 1.0.1249.40111
    CodeBase: file:///C:/Program%20Files/Rayan/wordtraining/wordtraining.exe
----------------------------------------
System.Windows.Forms
    Assembly Version: 1.0.5000.0
    Win32 Version: 1.1.4322.573
    CodeBase: file:///c:/winnt/assembly/gac/system.windows.forms/1.0.5000.0__b77a5c561934e089/system.windows.forms.dll
----------------------------------------
System
    Assembly Version: 1.0.5000.0
    Win32 Version: 1.1.4322.573
    CodeBase: file:///c:/winnt/assembly/gac/system/1.0.5000.0__b77a5c561934e089/system.dll
----------------------------------------
System.Management
    Assembly Version: 1.0.5000.0
    Win32 Version: 1.1.4322.573
    CodeBase: file:///c:/winnt/assembly/gac/system.management/1.0.5000.0__b03f5f7f11d50a3a/system.management.dll
----------------------------------------
System.Drawing
    Assembly Version: 1.0.5000.0
    Win32 Version: 1.1.4322.573
    CodeBase: file:///c:/winnt/assembly/gac/system.drawing/1.0.5000.0__b03f5f7f11d50a3a/system.drawing.dll
----------------------------------------
AxMP3PLib
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///C:/Program%20Files/Rayan/wordtraining/AxMP3PLib.DLL
----------------------------------------
MP3PLib
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///C:/Program%20Files/Rayan/wordtraining/MP3PLib.DLL
----------------------------------------
Accessibility
    Assembly Version: 1.0.5000.0
    Win32 Version: 1.1.4322.573
    CodeBase: file:///c:/winnt/assembly/gac/accessibility/1.0.5000.0__b03f5f7f11d50a3a/accessibility.dll
----------------------------------------

************** JIT Debugging **************
To enable just in time (JIT) debugging, the config file for this
application or machine (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

<configuration>
    <system.windows.forms jitDebugging="true" />
</configuration>

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the machine
rather than being handled by this dialog.



From: mmmobahser

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>7N75u9Y/hEyqfiD4tgUBiQ==</Id>

Author
7 Mar 2005 8:13 PM
Nicole Calinoiu
Just guessing here, but is the file marked as read-only or is it already on
CD when you attempt to open it?  If so, you should specify that you only
need read access.  e.g.:

yourStream = new FileStream(filePath, FileMode.Open, FileAccess.Read)

BTW, disabling CAS won't help you here since the exception almost certainly
has nothing to do with either CAS or the .NET Framework.



"may mana via .NET 247" <anonym***@dotnet247.com> wrote in message
news:epaTj20IFHA.3696@tk2msftngp13.phx.gbl...
I get some marvelous error from my c# program again & again, i guess it is a
security exception error, so i disable security with caspol -s off, give it
full trust, copy it to hard drive, copy it to cd drive, sign it with
public/private key, in all these cases i got the same exception, i use
framework 1.1.4322. and just want to read the file, not write to it, also i
am admin of my computer! and it is in the same directory. why i got this
error?
below you can see the exception text.
access to the path "g:\saving document6.cad" is denied
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.UnauthorizedAccessException: Access to the path "G:\saving
document6.cad" is denied.
   at System.IO.__Error.WinIOError(Int32 errorCode, String str)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess
access, FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath,
Boolean bFromProxy)
   at System.IO.FileStream..ctor(String path, FileMode mode)
   at wordtraining.main.lessonup()
   at wordtraining.main.lbxLesson_DoubleClick(Object sender, EventArgs e)
   at System.Windows.Forms.Control.OnDoubleClick(EventArgs e)
   at System.Windows.Forms.ListBox.WndProc(Message& m)
   at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)


************** Loaded Assemblies **************
mscorlib
    Assembly Version: 1.0.5000.0
    Win32 Version: 1.1.4322.573
    CodeBase:
file:///c:/winnt/microsoft.net/framework/v1.1.4322/mscorlib.dll
----------------------------------------
wordtraining
    Assembly Version: 1.0.1249.40111
    Win32 Version: 1.0.1249.40111
    CodeBase: file:///C:/Program%20Files/Rayan/wordtraining/wordtraining.exe
----------------------------------------
System.Windows.Forms
    Assembly Version: 1.0.5000.0
    Win32 Version: 1.1.4322.573
    CodeBase:
file:///c:/winnt/assembly/gac/system.windows.forms/1.0.5000.0__b77a5c561934e089/system.windows.forms.dll
----------------------------------------
System
    Assembly Version: 1.0.5000.0
    Win32 Version: 1.1.4322.573
    CodeBase:
file:///c:/winnt/assembly/gac/system/1.0.5000.0__b77a5c561934e089/system.dll
----------------------------------------
System.Management
    Assembly Version: 1.0.5000.0
    Win32 Version: 1.1.4322.573
    CodeBase:
file:///c:/winnt/assembly/gac/system.management/1.0.5000.0__b03f5f7f11d50a3a/system.management.dll
----------------------------------------
System.Drawing
    Assembly Version: 1.0.5000.0
    Win32 Version: 1.1.4322.573
    CodeBase:
file:///c:/winnt/assembly/gac/system.drawing/1.0.5000.0__b03f5f7f11d50a3a/system.drawing.dll
----------------------------------------
AxMP3PLib
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///C:/Program%20Files/Rayan/wordtraining/AxMP3PLib.DLL
----------------------------------------
MP3PLib
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///C:/Program%20Files/Rayan/wordtraining/MP3PLib.DLL
----------------------------------------
Accessibility
    Assembly Version: 1.0.5000.0
    Win32 Version: 1.1.4322.573
    CodeBase:
file:///c:/winnt/assembly/gac/accessibility/1.0.5000.0__b03f5f7f11d50a3a/accessibility.dll
----------------------------------------

************** JIT Debugging **************
To enable just in time (JIT) debugging, the config file for this
application or machine (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

<configuration>
    <system.windows.forms jitDebugging="true" />
</configuration>

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the machine
rather than being handled by this dialog.



From: mmmobahser

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>7N75u9Y/hEyqfiD4tgUBiQ==</Id>