By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,281 Members | 2,268 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,281 IT Pros & Developers. It's quick & easy.

System.UnauthorizedAccessException on deserialization

P: n/a
This is also posted in the security newsgroup. Sorry for cross-posting, but
I'm desperate.

I have a Winforms application in VB.NET with a SQL Server (MSDE) backend. In
the root application directory I have an XML file, LicXML.XML which holds
licensing info for the app.

On one group of machines where the users have restricted privileges, the
deserialization of this file trips an error as follows (excuse mispellings
from my client):

My Client Writes:

An error box with a "5" in the left end of the blue top bar appears,
"System.UnauthorizedAccessException: Access to the path
"C:\QMMC\LicXML.xml 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, Boolian bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode)
at QMMC2.modQMMC.DeserializeLicXML()

If my client logs in as Administrator he doesn't get this message and all
works fine.
Can some one help me here. I have shipped this app to hundreds of people
successfully, and this is the first case for this error.
Operating system is XP (Pro, I think) on new machines with Celeron
Processors.

Thanks in advance
Burton Roberts
Nov 11 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
This app is locally installed. NOT running on the web. The code fot
DeserializeLicXML is as follows:
Public Function DeserializeLicXML() As cLicXML
Dim moLicXML As cLicXML
Try
Dim fi As FileInfo = New FileInfo(GetLicXMLFileName)
Dim sz As XmlSerializer
Dim tr As XmlTextReader
Dim fs As FileStream
If fi.Exists Then
fs = New FileStream(GetLicXMLFileName, FileMode.Open)
sz = New XmlSerializer(GetType(cLicXML))
tr = New XmlTextReader(fs)
moLicXML = CType(sz.Deserialize(tr), cLicXML)
fs.Close()
Else
moLicXML = New cLicXML(iPlusDays:=-1)
moLicXML.SerializeMe()
End If
Return moLicXML
Catch ex As Exception
MessageBox.Show(ex.ToString, Err.Number)
End Try
End Function

Public Function GetLicXMLFileName() As String
Dim sb As StringBuilder = New StringBuilder(Application.StartupPath)
sb.Append("\LicXML.xml")
Return sb.ToString
End Function

Thanks in advance
Burton Roberts

"Christoph Schittko [MVP]" <ch********************@austin.rr.com> wrote in
message news:uC**************@TK2MSFTNGP12.phx.gbl...
How are you deserializing and how is the app running? Is it locally
installed or running via the web ?

Christoph

"Burton Roberts" <bh*******@adelphia.net> wrote in message
news:#t**************@tk2msftngp13.phx.gbl...
This is also posted in the security newsgroup. Sorry for cross-posting, but
I'm desperate.

I have a Winforms application in VB.NET with a SQL Server (MSDE) backend. In
the root application directory I have an XML file, LicXML.XML which

holds licensing info for the app.

On one group of machines where the users have restricted privileges, the
deserialization of this file trips an error as follows (excuse mispellings from my client):

My Client Writes:

An error box with a "5" in the left end of the blue top bar appears,
"System.UnauthorizedAccessException: Access to the path
"C:\QMMC\LicXML.xml 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, Boolian bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode)
at QMMC2.modQMMC.DeserializeLicXML()

If my client logs in as Administrator he doesn't get this message and all works fine.
Can some one help me here. I have shipped this app to hundreds of people
successfully, and this is the first case for this error.
Operating system is XP (Pro, I think) on new machines with Celeron
Processors.

Thanks in advance
Burton Roberts


Nov 11 '05 #2

P: n/a
Burton,

When you look at the stack trace in the exception you see that the
XmlSerializer has nothing to so with this. The exception is already
happening in the constructor of the FileStream.

I have a few more questions maybe we can figure it out.

* Are you sure the environment where you application is running in actually
grants users of .NET applications privileges to read from the C drive? Can
you ask the client to open the .NET Framework 1.x Configuration app, right
click Runtime Security Police, select Evaluate Assembly and check what
Permission Sets active for the app and the details of the File IO
permissions in particular?

* Is there a chance that another user or another application already have
that file open and locked it?

* Since it doesn't appear that you actually need the file for writing, can
you open it with FileAccess.Read?

* Does SerializeMe() work when the file is not already present?

HTH,
Christoph Schittko
Software Architect, .NET Mentor
MS MVP XML .NET

"Burton Roberts" <bh*******@adelphia.net> wrote in message
news:O$**************@TK2MSFTNGP09.phx.gbl...
This app is locally installed. NOT running on the web. The code fot
DeserializeLicXML is as follows:
Public Function DeserializeLicXML() As cLicXML
Dim moLicXML As cLicXML
Try
Dim fi As FileInfo = New FileInfo(GetLicXMLFileName)
Dim sz As XmlSerializer
Dim tr As XmlTextReader
Dim fs As FileStream
If fi.Exists Then
fs = New FileStream(GetLicXMLFileName, FileMode.Open)
sz = New XmlSerializer(GetType(cLicXML))
tr = New XmlTextReader(fs)
moLicXML = CType(sz.Deserialize(tr), cLicXML)
fs.Close()
Else
moLicXML = New cLicXML(iPlusDays:=-1)
moLicXML.SerializeMe()
End If
Return moLicXML
Catch ex As Exception
MessageBox.Show(ex.ToString, Err.Number)
End Try
End Function

Public Function GetLicXMLFileName() As String
Dim sb As StringBuilder = New StringBuilder(Application.StartupPath)
sb.Append("\LicXML.xml")
Return sb.ToString
End Function

Thanks in advance
Burton Roberts

"Christoph Schittko [MVP]" <ch********************@austin.rr.com> wrote in
message news:uC**************@TK2MSFTNGP12.phx.gbl...
How are you deserializing and how is the app running? Is it locally
installed or running via the web ?

Christoph

"Burton Roberts" <bh*******@adelphia.net> wrote in message
news:#t**************@tk2msftngp13.phx.gbl...
This is also posted in the security newsgroup. Sorry for cross-posting,
but
I'm desperate.

I have a Winforms application in VB.NET with a SQL Server (MSDE) backend.
In
the root application directory I have an XML file, LicXML.XML which

holds licensing info for the app.

On one group of machines where the users have restricted privileges,
the deserialization of this file trips an error as follows (excuse

mispellings from my client):

My Client Writes:

An error box with a "5" in the left end of the blue top bar appears,
"System.UnauthorizedAccessException: Access to the path
"C:\QMMC\LicXML.xml 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, Boolian bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode)
at QMMC2.modQMMC.DeserializeLicXML()

If my client logs in as Administrator he doesn't get this message and all works fine.
Can some one help me here. I have shipped this app to hundreds of people successfully, and this is the first case for this error.
Operating system is XP (Pro, I think) on new machines with Celeron
Processors.

Thanks in advance
Burton Roberts



Nov 11 '05 #3

P: n/a
I had my user open the Configuration App and check runtime security policy
for the executable file.

For All levels, permissions Granted to this assembly = Unrestricted.

I didn't konw how to check for the File IO permissions in particular.
Burton Roberts

"Christoph Schittko [MVP]" <ch********************@austin.rr.com> wrote in
message news:%2****************@TK2MSFTNGP10.phx.gbl...
Burton,

When you look at the stack trace in the exception you see that the
XmlSerializer has nothing to so with this. The exception is already
happening in the constructor of the FileStream.

I have a few more questions maybe we can figure it out.

* Are you sure the environment where you application is running in actually grants users of .NET applications privileges to read from the C drive? Can
you ask the client to open the .NET Framework 1.x Configuration app, right
click Runtime Security Police, select Evaluate Assembly and check what
Permission Sets active for the app and the details of the File IO
permissions in particular?

* Is there a chance that another user or another application already have
that file open and locked it?

* Since it doesn't appear that you actually need the file for writing, can
you open it with FileAccess.Read?

* Does SerializeMe() work when the file is not already present?

HTH,
Christoph Schittko
Software Architect, .NET Mentor
MS MVP XML .NET

"Burton Roberts" <bh*******@adelphia.net> wrote in message
news:O$**************@TK2MSFTNGP09.phx.gbl...
This app is locally installed. NOT running on the web. The code fot
DeserializeLicXML is as follows:
Public Function DeserializeLicXML() As cLicXML
Dim moLicXML As cLicXML
Try
Dim fi As FileInfo = New FileInfo(GetLicXMLFileName)
Dim sz As XmlSerializer
Dim tr As XmlTextReader
Dim fs As FileStream
If fi.Exists Then
fs = New FileStream(GetLicXMLFileName, FileMode.Open)
sz = New XmlSerializer(GetType(cLicXML))
tr = New XmlTextReader(fs)
moLicXML = CType(sz.Deserialize(tr), cLicXML)
fs.Close()
Else
moLicXML = New cLicXML(iPlusDays:=-1)
moLicXML.SerializeMe()
End If
Return moLicXML
Catch ex As Exception
MessageBox.Show(ex.ToString, Err.Number)
End Try
End Function

Public Function GetLicXMLFileName() As String
Dim sb As StringBuilder = New StringBuilder(Application.StartupPath)
sb.Append("\LicXML.xml")
Return sb.ToString
End Function

Thanks in advance
Burton Roberts

"Christoph Schittko [MVP]" <ch********************@austin.rr.com> wrote in
message news:uC**************@TK2MSFTNGP12.phx.gbl...
How are you deserializing and how is the app running? Is it locally
installed or running via the web ?

Christoph

"Burton Roberts" <bh*******@adelphia.net> wrote in message
news:#t**************@tk2msftngp13.phx.gbl...
> This is also posted in the security newsgroup. Sorry for cross-posting, but
> I'm desperate.
>
> I have a Winforms application in VB.NET with a SQL Server (MSDE)

backend.
In
> the root application directory I have an XML file, LicXML.XML which

holds
> licensing info for the app.
>
> On one group of machines where the users have restricted privileges, the > deserialization of this file trips an error as follows (excuse

mispellings
> from my client):
>
> My Client Writes:
>
> An error box with a "5" in the left end of the blue top bar appears,
> "System.UnauthorizedAccessException: Access to the path
> "C:\QMMC\LicXML.xml 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, Boolian bFromProxy)
> at System.IO.FileStream..ctor(String path, FileMode mode)
> at QMMC2.modQMMC.DeserializeLicXML()
>
> If my client logs in as Administrator he doesn't get this message
and all
> works fine.
> Can some one help me here. I have shipped this app to hundreds of

people > successfully, and this is the first case for this error.
> Operating system is XP (Pro, I think) on new machines with Celeron
> Processors.
>
> Thanks in advance
> Burton Roberts
>
>



Nov 11 '05 #4

P: n/a
You can select "View code groups that grant permissions to the assembly".

then go to that code group and check the permissions included in that code
groupt clicking, selecting properties and then going to the "Permission Set"
tab. Locate "File IO" and see what's going on. It sounds pretty unlikely
that this is it because you've said the assembly has unrestricted
permissions.

VERY STRANGE...
Christoph

"Burton Roberts" <bh*******@adelphia.net> wrote in message
news:OQ**************@TK2MSFTNGP12.phx.gbl...
I had my user open the Configuration App and check runtime security policy
for the executable file.

For All levels, permissions Granted to this assembly = Unrestricted.

I didn't konw how to check for the File IO permissions in particular.
Burton Roberts

"Christoph Schittko [MVP]" <ch********************@austin.rr.com> wrote in
message news:%2****************@TK2MSFTNGP10.phx.gbl...
Burton,

When you look at the stack trace in the exception you see that the
XmlSerializer has nothing to so with this. The exception is already
happening in the constructor of the FileStream.

I have a few more questions maybe we can figure it out.

* Are you sure the environment where you application is running in actually
grants users of .NET applications privileges to read from the C drive? Can
you ask the client to open the .NET Framework 1.x Configuration app, right click Runtime Security Police, select Evaluate Assembly and check what
Permission Sets active for the app and the details of the File IO
permissions in particular?

* Is there a chance that another user or another application already have that file open and locked it?

* Since it doesn't appear that you actually need the file for writing, can you open it with FileAccess.Read?

* Does SerializeMe() work when the file is not already present?

HTH,
Christoph Schittko
Software Architect, .NET Mentor
MS MVP XML .NET

"Burton Roberts" <bh*******@adelphia.net> wrote in message
news:O$**************@TK2MSFTNGP09.phx.gbl...
This app is locally installed. NOT running on the web. The code fot
DeserializeLicXML is as follows:
Public Function DeserializeLicXML() As cLicXML
Dim moLicXML As cLicXML
Try
Dim fi As FileInfo = New FileInfo(GetLicXMLFileName)
Dim sz As XmlSerializer
Dim tr As XmlTextReader
Dim fs As FileStream
If fi.Exists Then
fs = New FileStream(GetLicXMLFileName, FileMode.Open)
sz = New XmlSerializer(GetType(cLicXML))
tr = New XmlTextReader(fs)
moLicXML = CType(sz.Deserialize(tr), cLicXML)
fs.Close()
Else
moLicXML = New cLicXML(iPlusDays:=-1)
moLicXML.SerializeMe()
End If
Return moLicXML
Catch ex As Exception
MessageBox.Show(ex.ToString, Err.Number)
End Try
End Function

Public Function GetLicXMLFileName() As String
Dim sb As StringBuilder = New StringBuilder(Application.StartupPath) sb.Append("\LicXML.xml")
Return sb.ToString
End Function

Thanks in advance
Burton Roberts

"Christoph Schittko [MVP]" <ch********************@austin.rr.com> wrote in message news:uC**************@TK2MSFTNGP12.phx.gbl...
> How are you deserializing and how is the app running? Is it locally
> installed or running via the web ?
>
> Christoph
>
> "Burton Roberts" <bh*******@adelphia.net> wrote in message
> news:#t**************@tk2msftngp13.phx.gbl...
> > This is also posted in the security newsgroup. Sorry for

cross-posting,
> but
> > I'm desperate.
> >
> > I have a Winforms application in VB.NET with a SQL Server (MSDE)
backend.
> In
> > the root application directory I have an XML file, LicXML.XML
which holds
> > licensing info for the app.
> >
> > On one group of machines where the users have restricted privileges,
the
> > deserialization of this file trips an error as follows (excuse
mispellings
> > from my client):
> >
> > My Client Writes:
> >
> > An error box with a "5" in the left end of the blue top bar

appears, > > "System.UnauthorizedAccessException: Access to the path
> > "C:\QMMC\LicXML.xml 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, Boolian bFromProxy)
> > at System.IO.FileStream..ctor(String path, FileMode mode)
> > at QMMC2.modQMMC.DeserializeLicXML()
> >
> > If my client logs in as Administrator he doesn't get this message

and all
> > works fine.
> > Can some one help me here. I have shipped this app to hundreds of

people
> > successfully, and this is the first case for this error.
> > Operating system is XP (Pro, I think) on new machines with Celeron
> > Processors.
> >
> > Thanks in advance
> > Burton Roberts
> >
> >
>
>



Nov 11 '05 #5

P: n/a
> I haven't used, nor was I aware of, the .NET Configuration App. When I
try
to open it on my development machine, it doesn't open. It does open on a my test client machine, however, so I can still walk my client through it. The other application, .NET Framework Wizards does open on both machines. Is
there anything noteworthy there?
No, the wizards are just a simplified UI to the some often used
functionality of the configuration tool.
SerializeMe() should work when when the file is not already present. You'll notice we test for the file's existence, if its not there we create a new
serializable class and serialize it making a license file that is

"expired".

but deserializing should also work ;)

I am asking to find out if your app has write permissions to the location of
you xml file.

Also, have you had a chance to deserialize the with a read-only stream ...

HTH,
Christoph Schittko
Software Architect, .NET Mentor
MVP XML
Nov 11 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.