While deleting my .dll file System.UnauthorizedAccessException was thrown.
System.IO.File.Delete("file name here.dll");
Error message is as follows:
System.UnauthorizedAccessException: Access to the path ‘E:\Projeler\Spa Anahtar Üretici\ConsoleApplication2\bin\Debug\AutoGen.dll’ is denied.
How to solve this problem?
Try opening the file using File.Open method and enclose it in try-catch with exception IOException.
If the file is in use , the code flow reaches the exception part and hence don’t delete the file, Otherwise you can safely delete.