I'm trying to load the build, which is in the project debug folder

var asm = Assembly.Load(File.ReadAllBytes(path)); 

gives out

System.UnauthorizedAccessException

How can I download the assembly from this folder?

  • one
    You load everything correctly, you read the file into an array of bytes and already from it you are trying to load the assembly. And your mistake, with a probability of 90%, is due to the fact that there are no access rights to this folder where the assembly lies, or to the assembly itself. - BlackWitcher

1 answer 1

  var path = Path.Combine(relPath, partialName); FileSecurity fSecurity = File.GetAccessControl(path); var account = Environment.UserDomainName + "\\" + Environment.UserName; fSecurity.AddAccessRule(new FileSystemAccessRule(account, FileSystemRights.ReadAndExecute, AccessControlType.Allow)); var asm = Assembly.Load(File.ReadAllBytes(path)); 

Sorry, overlooked the path to the file as the path to the directory, and to unlock the file, this code is suitable