Hello,
Couple of things
(I did watch the video ,the longer one)
And the short answer is this is a Windows or anti-virus permission issue which I talk about below
- When creating a project with Visual Studio I suggest (doesn't have to be exactly this) using C:\DotNet following creating a VS solution under this path e.g. C:\DotNet\LowsesImporter. When creating C:\DotNet via Windows Explorer you should not need admin rights and if that is the case this is the first flag, insufficient permissions and if no admin rights great.
- From the video, I noticed in release mode from Windows Explorer after double clicking the app didn't start which leads me to believe this is a Windows permission issue (and yeah it should do the same in debug configuration).
What I did (as an admin on my box) in release mode
Copied C:\OED\Dotnetland\VS2019\QuestionsSolution\SpreadSheetLight1\bin\Release*.* to C:\Users\paynek\SpreadSheetLight_KP, ran, success.
Can you try this using a similar folder under C:\Users... (and when creating the folder did you need admin rights?), run by double clicking, if it doesn't run try again via right click on the .exe, select run as admin, what happens? If this also failed look at either Windows Defender or any other anti-virus software installed, in either case look at creating an exclusion rule to indicate your .exe is safe to run.
Try an app manifest
Add an app manifest, replace contents with the following, build run, answer Yes, what happens?
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
</application>
</compatibility>
</assembly>
Bottom line
To be honest I never use release mode as all my applications are setup to write debug information (similar to this class project) on runtime exception where with release mode some information is not available. I have seen this before where there were about 30 users and a handful had the same error as you even in debug configuration were our engineers had to adjust active directory rules.
My conclusion is
Windows Active Directory is denying access (yeah it should also happen in debug mode too) or ant-virus app denying access, nothing to do with Visual Studio.
Revised source
Main difference is console vs windows form app and used Path.Combine to create the path/file name to create the excel file.
using System;
using System.IO;
using SpreadsheetLight;
namespace SpreadSheetLight1
{
class Program
{
static void Main(string[] args)
{
try
{
using (var doc = new SLDocument())
{
Console.WriteLine($"Create {ExcelFileName}");
doc.SaveAs(ExcelFileName);
Console.WriteLine("Excel file created");
}
}
catch (UnauthorizedAccessException)
{
Console.WriteLine($"Access denied to: {ExcelFileName}");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Console.ReadLine();
}
static string ExcelFileName =>
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
"Excel1.xlsx");
}
}