My brief story which lead me to look to an unlikely culprit of what was causing a bug in my .NET Core application.
The application is a simple in that it has a data provider service supported by dependency injection, which uses a SQL connection to call a stored procedure to return data back into a model, which gets loaded into a view that contains a grid (ie. <table>) on the webpage. Data is loaded based on the user that is logged into the application - different users will see different data in the grid. Identity server is managing the user logins.
Easy, right? Local testing looks good, everything is returning what it should. The SQL connection is returning data from the stored procedure. I am seeing the data being properly passed into the grid.
Let's deploy this to QA.
The background
This is a 3-tier application (front-end, business logic and data access layers) built in .NET Core. The application itself is actually a .NET Framework application that I am converting to .NET Core. I am converting this application not only for future support, but for performance improvements.
If you haven't been on the bandwagon, .NET Framework isn't moving past version 4.8. As mentioned in the Microsoft blog, .NET Core will continue to get new features at a faster rate, and will be the preferred framework to build new apps moving forward.
Easy, right? Local testing looks good, everything is returning what it should. The SQL connection is returning data from the stored procedure. I am seeing the data being properly passed into the grid.
Let's deploy this to QA.
QA doesn't work
Nothing is showing up in the grid on the webpage. Hm, that is odd. Okay - what could be the problem here? I first check to see if the values are being passed correctly into the stored procedure, as that is the first place I tend to look. My reasoning behind this is maybe the user information that the stored procedure needs is somehow not getting set properly.
I add some logging like seen here within my controller and redeploy to QA. In my logging I see that the stored procedure is getting values from the user's identity, so that doesn't seem to be the problem.
I next compare the stored procedure between my local copy and on QA, as it is possible that the procedure is different between environments and it was a fluke that my local environment returned proper data. Luckily, VS Code allows us to quickly and easily compare files.
I open up a new tab with ctrl/cmd + n and paste in the stored procedure in question. I saved the file and repeated the process with the stored procedure in the other environment. Holding ctrl/cmd + shift + p I typed "compare" and chose Files: Compare Active File With... and chose the other file.
Compare active file dialog |
The files are the same.
Running out of ideas
I go back to my QA url since my application is a web app and bring up the console by clicking f12 (in Chrome, or you can right-click and choose Inspect Element) and see if there are any errors. I do not see any errors.
What about the Content Security Policy - could that be causing any errors? The CSP's purpose is to prevent XSS (Cross-site scripting) and if you don't have the CSP configured properly, you can prevent CSS or JS from loading on your site. Could the CSP be preventing the grid from loading data on our QA server (barring everything else is set up correctly)? Unlikely. CSP errors are shown in the console, and we would have seen the CSP error locally if it were to be happening.
Stuck
After exhausting all of my obvious options, what else could be causing this bug? Let's take a deeper look into the view and at our environment tag helpers we have in _Layout.cshtml. We have code that is similar to this:
Our code in _Layout.cshtml |
My code looks normal enough, we are loading css in non-bundled files in the Development environment and in non-Development environments we are loading one bundled file. Besides being a recommended best-practice to bundle resource files on web pages, I don't see anything wrong.
I happen to double-check the bundleconfig.json and immediately see the problem. I did not configure the bundling correctly:
This is wrong! |
I modify this bundleconfig.json file to include the other files I need:
This is correct! |
and lo-and-behold, after deploying to QA I see data on the webpage! It turns out that because my css was missing, I wasn't seeing any data on my webpage! What I learned, and I hope you do too, is that you should consider checking your bundleconfig.json and any <environment> tags when diagnosing problems in .NET Core web apps.
I was diagnosed as HEPATITIS B carrier in 2013 with fibrosis of the
ReplyDeleteliver already present. I started on antiviral medications which
reduced the viral load initially. After a couple of years the virus
became resistant. I started on HEPATITIS B Herbal treatment from
ULTIMATE LIFE CLINIC (www.ultimatelifeclinic.com) in March, 2020. Their
treatment totally reversed the virus. I did another blood test after
the 6 months long treatment and tested negative to the virus. Amazing
treatment! This treatment is a breakthrough for all HBV carriers.