WinRT storage throwing UnauthorizedAccessException

I’ve been programming in .Net for many years now, but this one threw me off just because I was treating the WinRT api differently to standard .Net classes.

I was opening streams, writing to a file, calling .FlushAsync(), then later trying to open the same file again. I would continuously get an UnauthorizedAccessException. The answer was a simple “you forgot to dispose of the stream”, yes it is obvious in hindsight.

The solution is to simply call .Dispose() on your stream once you are finished with it, or surround it with a using statement.

By David Burela


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s