Posts

Showing posts from 2018

Unable to debug web project due to wrong DLL version ... pulled from dependent project

After re-organizing the projects of a solution, the web app failed to start in the debugger with an error that it could not load Newtonsoft.Json.dll. The error indicated that it could a file of that name, but it was not the expected version. Sure enough the file version of the DLL was 6. But, the project was setup to pull version 10 via nuget. Further, if I deleted the DLL from the bin dir and built (F6), the file version was 10. But, when I started the debugger, that version was overwritten with version 6. That was frustrating. The build was doing different things based on how I invoked it. After some hunting around and finding different possible causes and solutions, I discovered that one of them matched what was happening to me. Version 6 of the DLL was pulled in by a dependent project - called Common. That version then made its way into the Web project when it built ... with the intent to debug. So, the fix was to setup Common for version 10. After that, I could debug the web pro...

Preventing deadlock while logging via Entity Framework

tech: C#, Web App, Web API, Entity Framework, database We were getting database deadlock errors alot -- not all the time -- but alot. We tracked it down to logging each webapi call that occurs for a web app operation. One operation, like search, results in multiple webapi calls. The calls were being executed at the same time and therefore being logged at the same time. These simultaneous operations were contending with each other -- causing deadlock. The log code was innocent enough: Context.ActivityAudits.Add(model); Context.SaveChanges(); And the resulting SQL that Entity Framework generated and executed was not too surprising: exec sp_executesql N'INSERT [dbo].[ActivityAudit]([RequestId], [Method], [Path], [IpAddress], [Date], [StatusCode], [Error], [UserName]) VALUES (@0, @1, @2, @3, @4, @5, NULL, @6) SELECT [Id] FROM [dbo].[ActivityAudit] WHERE @@ROWCOUNT > 0 AND [Id] = scope_identity()' Well, the INSERT is totally expected. And, when you think about h...