I saw that UnauthorizedAccessException
exception occurs especially when open files and not disposing them, but in my case it is different.
I have a very simple code and as I think this code is correct.
I am displaying a message dialog and it works fine but it may get UnauthorizedAccessException
, I will explain it how.
My message dialog is in a Search charm method which searches for an address in bing maps, if the address was not found, then the dialog will be shown.
So this is the code (no need for the whole code, it's not affecting):
MessageDialog msg = new MessageDialog("No results found.");
await msg.ShowAsync();
If I call it once, everything is ok, but if I do the next thing, I get UnauthorizedAccessException:
- Open the search charm.
Search for an address that does not exists (for example: sadasdasdasd).
So now the message dialog will be shown with the cancel button. Now I dont press cancel, I just press again the search (with the same value).
Now I get an exception while getting to this line:
await msg.ShowAsync();
System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
Am I doing something wrong? How can I handle it?
I just want my application to be resistant to crashes.