Failed to locate open application

I am using WinAppDriver with C# for windows applications and I can correctly test my mstest projects in the solution when doing it in visual studio. However, when I execute dotnet test “path to solution” in powershell I have the following error:

ClassInitialize threw exception. OpenQA.Selenium.WebDriverException: OpenQA.Selenium.WebDriverException: Failed to locate opened application window with appId “path to my app”. “path to my app/MyApp.exe” is not running.

My code is

protected static OpenQA.Selenium.Appium.Windows.WindowsDriver topLevelDriver;
protected static OpenQA.Selenium.Appium.Windows.WindowsDriver myDriver;

var processes = Process.GetProcesses();
bool exit = false;
string WindowHandle = string.Empty;
string ApplicationPath = “path to my AppTopLevel app”;
foreach (var process in processes)
{

string v = "";
try
{
	v = process.MainModule.FileName;
}
catch { }
if (v.ToUpper() == ApplicationPath.ToUpper())
{
	WindowHandle = process.MainWindowHandle.ToString("x");
	exit = true;
	break;
}

}
AppiumOptions topLevelApp = new AppiumOptions();
if (WindowHandle != string.Empty)
{
topLevelApp.AddAdditionalCapability(“appTopLevelWindow”, WindowHandle);
topLevelApp.AddAdditionalCapability(“deviceName”, “WindowsPC”);
topLevelApp.AddAdditionalCapability(“platformName”, “Windows”);

topLevelDriver = new WindowsDriver<WindowsElement>(new Uri("http://127.0.0.1:4723/wd/hub"), topLevelApp);
topLevelDriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(1.5);

}
if (myDriver == null)
{
OpenQA.Selenium.Appium.AppiumOptions appiumOptions = new AppiumOptions();

appiumOptions.AddAdditionalCapability("app", @"path to my app/MyApp.exe");
appiumOptions.AddAdditionalCapability("platformName", "Windows");
appiumOptions.AddAdditionalCapability("deviceName", "WindowsPC");
appiumOptions.AddAdditionalCapability("newCommandTimeout", 300);
appiumOptions.AcceptInsecureCertificates = true;
myDriver = new WindowsDriver<WindowsElement>(new Uri("http://127.0.0.1:4724/wd/hub"), appiumOptions);

myDriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(1.5);

}

AppTopLevel app is running.