Can Of Code

ASP Core 8 EF crashing when deploying to a specific database

I was getting a production crash having just pushed an update that rolled out an upgrade from .NET 7 to .NET 8. The project uses EF core with an Azure MS SQL server. The crash never showed up during testing on an testing environment which was near identical to the production. What was going wrong and how did we miss it?

The exception that was coming from EF was:

Exception thrown: 'Microsoft.Data.SqlClient.SqlException' in System.Private.CoreLib.dll
Incorrect syntax near '$'.

Not that helpful but at least is communicating that the SQL might be the cause. I was able to hunt down the generated SQL that was the cause:

...
WHERE [b].[IsDelete] = CAST(0 AS bit) AND [t0].[IsConfirmed] = CAST(1 AS bit) AND [s].[Id] = @__session_Id_0 AND [t1].[Id] IN (
    SELECT [p0].[value]
    FROM OPENJSON(@__pupilIds_1) WITH ([value] int '$') AS [p0]
)

OPENJSON looks new here and it turns out that EF8 has a breaking change around the use of OPENJSON referenced here: https://learn.microsoft.com/en-us/ef/core/what-is-new/ef-core-8.0/breaking-changes

But why did this not fail during testing? Why only once it has gone to production, and not only that but it failed on only one database and worked perfectly on others on the same server and environment.

What I was unaware of was that one of the databases I was using was running an older compatibility_level then the other databases. This resulted in the error only coming to light when using this specific database.

You can run the following SQL to compare compatibility levels:

SELECT compatibility_level, name
FROM sys.databases

When I did this, most of the databases were set to 150 however the problem database was set to 110. Its easy enough to change the compatibility but its worth reading the docs for breaking changes. If you need to change a database’s compatibility level you can then use:

ALTER DATABASE "database-name-goes-here" SET COMPATIBILITY_LEVEL = 150

For more information about the compatibility levels see here: https://learn.microsoft.com/en-us/sql/t-sql/statements/alter-database-transact-sql-compatibility-level?view=sql-server-ver16.

My understanding is that Azure SQL is always running the newest engine but the compatibility level of each database stays the at the same value it was initially set to. Its therefore your job to keep the compatibility level in sync. Another mistake to learn from is to review the docs when upgrading .NET versions or EF Core versions for any breaking changes.

Posted in Uncategorised | Tagged , , |

Removing FontAwesome CSS from footer when using WPBakery

On a recent project I had already included FontAwesome using their Kit setup where the css / webfonts are loaded by their script. The issue I faced was that because I was using WPBakery I was then including FontAwesome twice.

To remove the enqueued FontAwesome css files I added the following to the themes functions.php


add_action('wp_enqueue_scripts', 'canofcode_dequeue_font_awesome_style', 11);
function canofcode_dequeue_font_awesome_style() {
    wp_deregister_style( 'vc_font_awesome_5_shims' );
    wp_dequeue_style( 'vc_font_awesome_5_shims' );
    wp_deregister_style( 'vc_font_awesome_5' );
    wp_dequeue_style( 'vc_font_awesome_5' );
}

 

I found that it doesn’t effect the loading of FontAwesome when editing the page in the backend editor. I struggled to find something like this when Googling so hope it helps.

Posted in WordPress | Tagged |

Fixed Crashing of ATI Radeon 5600xt drivers on Windows

I’ve been lucky enough to look at replacing my now 5-6 year old laptop which has become to churn at that thought of Photoshop or Visual Studio. I have not built a PC in a long time and was a little daunted at first but not too much has changed. So I order everything I needed and got set on putting it all together.

  • Processor: Ryzen 7 3800X
  • MSI Radeon RX5600XT
  • 32 GB (2 x 16gb) 2666 DDR4 RAM
  • MSI Tomahawk Motherboard

All went well everything clicked into place, installed Windows, installed some games, updates and all the software I need. Then when I got into playing a game, the screen would go blank, then a handy little message would inform me that the Graphic drivers had gone wobbly and you should tell someone about it.

Some of the errors I was getting:

  • Event viewer would show: LiveKernelEvent 141 Error
  • the errors related to: LKD_0x141_Tdr:6_IMAGE_amdkmdag.sys.
ATI Radeon RX5600XT wasn't the problem

The internet will know!

I headed to Google to find a significant number of forum posts of people having the same issue with the same graphics card and lots of people were pointing to the drivers being the issue. Following the advice I tried the following:

  • Propped up the graphics card with some Lego! (Some were suggesting the card was so heavy it was sliding out the PCIe connector.
  • Installed many different combinations of Drivers from the latest to one from months ago
  • Swapping around the power cables
  • Questioning everything I bought, assuming I got something wrong somewhere.
  • Ran a memory test, passed with flying colours.

I was starting to get disheartened now, perhaps I should have stuck with a laptop and let the experts make the computers. Did I just buy a bad graphics card? However I found it just too hard to give up debugging this so I decided to just take one of the sticks of RAM out on a whim really.

BINGO!

No more crashes. Why RAM was causing the display drivers to crash I just didn’t understand. I wasn’t happy with this diagnoses because maybe it was just a coincidence? so I took out all the RAM and then put in the crashing stick and the crashing was back.

Must be the crashing stick! I was hoping that MemTest86 will tell me for certain but after running it over 4 passes there were no errors.  So its still sort of a mystery whenever that stick of RAM is in the PC, it will continually crash in games. I have returned the RAM and hoping that the replacement will be fine (It was although I went for a different brand and a faster speed 3200). Hopefully this will be useful for someone having trouble with the blank / black screen when playing games with the 5600XT. If anyone has any theories on how the RAM could pass Memory Tests but still be faulty let me know! And for that matter, why bad RAM crashes the graphics drivers exclusively?

Posted in Gaming | Tagged , |