We have an existing application that makes use of the System.IO.Packaging.Package class for reading in a significant amount of structured data. Our application works fine in all scenarios except when attempting to open a Package from a read-only source such as a CD or DVD.
The following line is the point where our application throws an exception if the PackagePath is on a read-only media:
_ourPackage = Package.Open(PackagePath, FileAccess.Read);
When the data is stored on a CD the above line throws an UnauthorizedAccessException. We are unsure why this is occuring. We have attempted to run as Administrator and it has no effect.
As indicated above we are specifying only Read access as this particular process only needs to read in data and it will be a common scenario for us to distribute our packaged data via a medium such as CD or DVD.
Any ideas why we may be experiencing this?
You don’t specify the FileMode, the default is FileMode.OpenOrCreate. Not sure how much Windows like this when you do this on a CD-Rom. Use the overload that let’s you specify FileMode.Open. Next step is to try to find out why Windows doesn’t like you.