C# IsAppInstalled error: Could not find package

Hello.

I have this class in C# :

 public class AppInstallVerification
        {

            //Creating instance for Appium driver
            AppiumDriver<AndroidElement> driverCheck;

            CapDeviceConfig cap = new CapDeviceConfig();

            EnrollmentTests enrollmentTests = new EnrollmentTests();

            InstallApp install = new InstallApp();

            public void IsAppInstalled()
            {

                cap.CapDeviceConfigOptions();
                driverCheck = new AndroidDriver<AndroidElement>(new Uri("http://127.0.0.1:4723/wd/hub"), cap.CapDeviceConfigOptions());
                
                if (driverCheck.IsAppInstalled("com.android.MyApp"))
                {
                    Console.WriteLine("App is installed!");
                    enrollmentTests.CodeApplied();
                }
                else
                {
                    Console.WriteLine("App is not installed!");
                    install.InstallingApp();
                }            
            }
        } 

When my device has the app installed, everything works fine. However, when my device does not have the app installed, the system gives me this error message:

"Message: Test method MYAPP.Main.RunTest.RunAllTests threw exception: 
System.InvalidOperationException: An unknown server-side error occurred while processing the command. Original error: Could not find package com.android.MyApp on the device"

How to use and declare the IsAppInstalled?

My Capabilities:

public class CapDeviceConfig
    {

        public DesiredCapabilities CapDeviceConfigOptions()
        {
            //set the capabilities (https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/caps.md)
            
            DesiredCapabilities cap = new DesiredCapabilities();
            cap.SetCapability("automationName", "Appium"); // Which automation engine to use

            cap.SetCapability("platformName", "Android"); // Which mobile OS platform to use

            cap.SetCapability("platformVersion", "8.0.0"); // Mobile OS version

            cap.SetCapability("deviceName", "starlte"); // The kind of mobile device or emulator to use // S9

            cap.SetCapability("udid", "2270048324037ece"); // Unique device identifier of the connected physical device

            cap.SetCapability("appPackage", "com.android.MyApp");

            cap.SetCapability("appActivity", "md5ab6683a3e3c3f0bd6864e3305b4e45c6.SplashScreenActivity");
                        
            cap.SetCapability("noReset", "True"); // Don't reset app state before this session.

            cap.SetCapability("printPageSourceOnFindFailure", "True"); // When a find operation fails, print the current page source.

            return cap;

        }
    }

I’m using VS 2017 Community, C#, and a Samsung S9 (real device).