1

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"?

TylerH
  • 20,799
  • 66
  • 75
  • 101
Tony
  • 89
  • 1
  • 12
  • Yeah, Excpetions are problems that should never be ignored: https://blogs.msdn.microsoft.com/ericlippert/2008/09/10/vexing-exceptions/ | https://www.codeproject.com/Articles/9538/Exception-Handling-Best-Practices-in-NET – Christopher Nov 16 '19 at 22:51
  • 2
    Please show us the code that throws this exception. In this rare case, it might be very usefull to have the messge of the Exception. – Christopher Nov 16 '19 at 22:53
  • 1
    Can you add full stack traces of those exceptions? Also, what actually triggers those exceptions, I mean which part of your code does it if everything seems to be working normally? Have you tried adding logging to your [dbContext.Database](https://stackoverflow.com/questions/23804783/log-queries-executed-by-entity-framework-dbcontext) to see the SQL that gets executed, if any? – Eugene Podskal Nov 16 '19 at 22:55
  • 1
    Well, if it works perfectly on another machine, have you tried to start with a clean folder, clone the repository from server and rebuild the application - it is pretty much possible that some remnant(.obj or config, or whatever) of DynamicFilters evaded even all those `deleted the content of the Debug folder, Cleaned Solution and Rebuilt solution` operations - been there, seen it. At least it is worth a try. – Eugene Podskal Nov 16 '19 at 23:00
  • Good Tip Eugene. I output the SQL to the Output Window, Initially I thought I saw the error but I was being stupid and too hasty. The exceptions are thrown prior to the connection opened and SQL statement executed. As to your second question, yes I did re-clone to new folder on problematic machine with same error. – Tony Nov 16 '19 at 23:33

1 Answers1

2

After much research, my problem turned out to be the Debug setting in Visual studio which was not set to "Enable Just My Code". (Tools -> Options -> Debugging Tab, Enable Just My Code). https://learn.microsoft.com/en-us/visualstudio/debugger/just-my-code?view=vs-2019

From what I can gather from Google, it is safe enough to ignore minor errors originating from external assemblies. Assuming they are not impacting your program logic that is. I am not 100% comfortable with ignoring exceptions, but be that as it may.

TylerH
  • 20,799
  • 66
  • 75
  • 101
Tony
  • 89
  • 1
  • 12