Entity not found issue with geckodriver

I am trying to run selenium test and here is code which fails

public virtual void Init()
    {

        try
        {

            WebDriver = new FirefoxDriver();

        }
        catch (WebDriverException e1)
        {
            Console.WriteLine($"1st attempt failed {e1.Message}");
            var ffPath = @"C:\Program Files\Mozilla Firefox\firefox.exe";
            if (File.Exists(ffPath))
            {
                try
                {
                    var service = FirefoxDriverService.CreateDefaultService();
                    service.FirefoxBinaryPath = ffPath;
                    WebDriver = new FirefoxDriver(service);
                }
                catch (WebDriverException e2)
                {
                    Console.WriteLine($"2ND attempt failed {e2.Message}");
                    try
                    {

                        WebDriver = new ChromeDriver();

                    }
                    catch (Exception e3)
                    {
                        Console.WriteLine($"3rd attempt failed {e3.Message}");
                        Assert.Fail(e3.Message);
                    }
                }
            }
            else
            {
                throw new Exception("Nothing working");
            }
        }

        WebDriver.Manage().Window.Maximize();

    }

I get Entity not found error This happens only one time when code is deployed through CI CD called appveyor. If i rerun the deployment then test runs just fine. So basically inline deployment fails.