I removed a dynamic filter from OnModelCreating and the related NuGet package, EntityFramework.DynamicFilters, from my application as it is no longer required. As soon as I did this I started seeing Exceptions being thrown in the Output Window.
First when I run my application (C# with WPF and EF) I get:
Exception thrown: 'System.TypeLoadException' in mscorlib.dll
Then when I access my Data (Entity Framework) I get a whole bunch of exceptions when my code reaches this statement:
public List<T> GetAll() => Table.ToList();
The errors include:
Exception thrown: 'System.Data.SqlClient.SqlException' in System.Data.dll
Exception thrown: 'System.Data.SqlClient.SqlException' in EntityFramework.dll
Exception thrown: 'System.Data.Entity.Core.EntityCommandExecutionException' in EntityFramework.dll
Exception thrown: 'System.Data.Entity.Core.EntityCommandExecutionException' in EntityFramework.SqlServer.dll
The odd thing is that data is returned as expected and the application appears to be working, however, my gut tells me not to simply ignore them and hope for the best.
Taking advice from other posts I deleted the content of the Debug folder, Cleaned Solution and Rebuilt solution with no improvement.
Following other advice I uninstalled and re-installed Microsoft.Net Core and Microsoft.Net Framework, also with no improvement. My application is targeting .Net Framework 4.8
I removed and repaired the Entity Framework NuGet package, still no help.
To make 100% sure it was not a bug in my code I cloned the application to a different machine and it ran perfectly first time. (Edit: for clarity I also created a new folder on problematic machine and cloned to that with same problem) This tells me it must be something in my environment, but what?
I am all out of ideas, short of formatting by hard drive and re-installing Windows which I actually seriously considered a few time in the last 24 hours.
Reading https://learn.microsoft.com/en-us/visualstudio/debugger/just-my-code?view=vs-2019 prompted me to compare the debug settings on the two machines. Turns out that the problematic machine had Enable Just My Code unchecked. Checking it makes my problem "go away". The question now I suppose is whether it is safe to simply ignore exception which are "not in my code"?