WinForms: How to check if another form is open

If you’re working on a Windows Forms project and need to know which forms are open, use: This gives you an IEnumerable collection of form objects that are currently open. You can lookup a form by name, by type, or loop through the list. Example scenarios There are many scenarios where you’d want to know … Read more WinForms: How to check if another form is open

SqlTypeException: SqlDateTime overflow

Problem I am executing a SQL query and trying to set a datetime column to DateTime.MinValue. I’m getting the following exception: System.Data.SqlTypes.SqlTypeException: ‘SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.’ The problem is that DateTime.MinValue is 1/1/0001 12:00:00 AM and the SQL Server DateTime minimum value is 1/1/1753 12:00 AM. Solution … Read more SqlTypeException: SqlDateTime overflow

Visual Studio 2019 – All references say referenced component could not be found

Problem When I open a C# project in Visual Studio 2019, none of the references are loading. In the error list it says: The referenced component could not be found This usually means you need to restore the Nuget Package. In this case, it’s even showing this for .NET Framework references – such as System.Core. … Read more Visual Studio 2019 – All references say referenced component could not be found

‘CREATE/ALTER PROCEDURE’ must be the first statement in a query batch

Problem You have a SQL query like this: While executing this you get the following error: ‘CREATE/ALTER PROCEDURE’ must be the first statement in a query batch Solution The error message says it all: the CREATE PROCEDURE statement cannot be executed after other queries in the same batch of queries. The solution is to execute … Read more ‘CREATE/ALTER PROCEDURE’ must be the first statement in a query batch

OpenQA.Selenium.DriverServiceNotFoundException: The chromedriver.exe file does not exist in the current directory

Problem I’m trying to use Selenium with the ChromeDriver and I’m running into the following exception: Unhandled Exception: OpenQA.Selenium.DriverServiceNotFoundException: The chromedriver.exe file does not exist in the current directory or in a directory on the PATH environment variable. The driver can be downloaded at http://chromedriver.storage.googleapis.com/index.html Solution The simplest solution is to install the Selenium.Chrome.WebDriver nuget … Read more OpenQA.Selenium.DriverServiceNotFoundException: The chromedriver.exe file does not exist in the current directory

OpenQA.Selenium.WebDriverException: Element is not clickable. Other element would receive click.

Problem I am using Selenium to automate navigating a website. I’m trying to click a button: When I try to click the button it’s throwing the following exception: OpenQA.Selenium.WebDriverException: Element is not clickable. Other element would receive click. The reason this is happening is because Selenium is trying to click the button by its coordinates, … Read more OpenQA.Selenium.WebDriverException: Element is not clickable. Other element would receive click.

How to update UI from another thread

I often need to be able to run multiple threads and update the UI based on the results. For example, I may need to execute GET requests to 10 different endpoints concurrently, and then report their results in a datagrid as they come back. The problem is you can’t just update the UI from any … Read more How to update UI from another thread

C# – Attribute constructor parameter is not a valid attribute parameter type

Problem I have created a custom attribute class and I am trying to pass in a value. It looks like this: I’m getting the following error message: Attribute constructor parameter has type Color which is not a valid attribute parameter type I have also gotten this error message, which has the same underlying cause: An … Read more C# – Attribute constructor parameter is not a valid attribute parameter type

System.InvalidOperationException: Objects added to a BindingSource’s list must all be of the same type.

Problem I am building a report using ReportViewer RDLC and I’m trying to bind the data. When I try to add my BindingList to the BindingSource I get the following exception: System.InvalidOperationException: “Objects added to a BindingSource’s list must all be of the same type.” Here’s the code causing this: Solution Set the BindingSource.DataSource to … Read more System.InvalidOperationException: Objects added to a BindingSource’s list must all be of the same type.