This causes, surprise!, the file to be read-only. Once created, right-click the file, select Properties, and enable the Read-only checkbox. Before writing code, I'll create a text file named c:\temp\readonly.txt. Let's create a small program to provoke and catch this error. Let's dig in! Handling the errorĬatching the exception is straightforward. The exception is typically caused by an IO error, but other issues like security restrictions are also known to utilize this error. Today, I want to introduce you to System.UnauthorizedAccessException. It's time for another post in our series about Debugging common.