Solving Azure Web Application’s first load perfomance issues

Microsoft Azure logo

Is your Azure Web Application suffering from absolutely horrible load times every time someone accesses it for the first time every 15 minutes or so? Mine was. It was pitiful.

I was developing a web-based service using EF6 and ASP.NET MVC 5, where all the assets were hosted in the Azure. Even though the app was reasonably lightweight and usually responded very fast, the first time someone accessed it in a while it took 20-60 seconds to load AND sometimes even timed out (especially with mobile clients). Load testing revealed only the what I already knew: initial load times were horrendous, but after that everything worked fine. I did eventually find the solution, though!

Continue reading

Easiest way to debug Seed-method in EF Code-first migrations in Configuration.cs when running Update-Database

Sequence contains more than one element

This post describes the easiest way to debug the issues that may stop your Seed-method in Configuration.cs from going through. The solution here shows you, how you can get a little bit more information out of the process, without attaching the debugger (there’s another blog post for that!)

Description

Entity Framework’s code-first migration’s are a beautiful and easy way of managing database schema changes and populating some preliminary data there. Personally I also sometimes use the method for adding some enrichment to data or or custom property values mapping that would otherwise require an additional/external console program.

Problem: running the Seed-method is by default undebuggable

Okay – so seeding data is cool. That’s fine and dandy, but debugging the issues in the function while running Update-Database is NOT so cool. You only get the stacktrace and exception message – and that’s pretty ugly.

Continue reading

Fixing error “No Entity Framework provider found for the ADO.NET provider with invariant name ‘System.Data.SqlClient'”

No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlClient'

This post describes the fix to error “No Entity Framework provider found for the ADO.NET provider with invariant name ‘System.Data.SqlClient'”, which Visual Studio throws at your face when you try to run an application on any Windows-based system (or which you’ve dug out of event logs). Also, you’re probably using Entity Framework in your project.

Error

When debugging/running your code you get an error like this:

An exception of type 'System.InvalidOperationException' occurred in EntityFramework.dll but was not handled in user code

Additional information: No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlClient'. Make sure the provider is registered in the 'entityFramework' section of the application config file. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.

The running of the program is stopped there, and removing and readding the nuget packages and/or other references to dlls does not help. I, at least, tried also making all kinds of changes to my web.config and ran iisreset a couple of times, but nothing seemed to help. There’s a simple fix available, though!

Continue reading

Solving the “Spatial types and functions are not available …” -problem

Spatial SQL types

This page describes mutiple ways on how to fix the exception ‘Spatial types and functions are not available for this provider because the assembly ‘Microsoft.SqlServer.Types’ version 10 or higher could not be found.‘ which comes up during debugging or publishing your program, app or service using DbGeography.

Symptoms

While running a console program or perhaps installing an ASP.NET MVC website on a machine, where SQL Server (apart from the one that comes with the Visual Studio) has not been installed, you may encounter the following error:

Spatial types and functions are not available for this provider because the assembly ‘Microsoft.SqlServer.Types’ version 10 or higher could not be found.

At least for me, this was baffling as that assembly was included in the project, and would compile and run flawlessly on other machines, just not on this one. I’m documenting here all the possible fixes to the issue I am aware of.

Problem / Reason

For me, the actual reason was that even though the DLL was loaded and included in the project as a nuget package, the actual native assemblies for this dll were not loaded to memory, as this needs to be done in the runtime. This issue was made worse by the fact that I first created this solution on a machine, where SQL Server was installed, so I was very much oblivious of the issue until it hit me on the face while trying to run my program on this particular machine, which did not have SQL Server.

Continue reading

Duplicate object values in ASP.NET MVC Display Templates? Easy fix!

Duplicate String values

Are you getting duplicate object values (or whatever those Objects output in .ToString())? Eh, so was I, after I edited the display template for String. Found a fix, though.

Description

Okay – I just ran into one of my more stupid mistakes since.. Well, since forever.

I had made some quick and simple edits in String.cshtml display template (among quite a few other edits before building again and seeing what happened), as I added support for Enum values there. After that I started getting duplicate values for String-typed properties. 

Apparently, mistakes were made.

Solution

Luckily, this was easy to fix (but probably still worth documenting):

I had added the code for handling Enum-values, and also changed “@model String” -declaration to awful “@Model object” -one. Changing the type was supposed to happen, but capitalizing the model messed up my DisplayTemplate. Instead of casting the model to object, I was simply calling Model at the start of the template (basically, that was a shorthand for Model.ToString()), hence the “String object String”-kind of duplicate values on the display template.

Continue reading

Fixing “An error occurred while updating the entries” while running code-first migrations in MVC 5 app

Update-Database error

This post describes an issue with EF’s code-first migrations, when mapping between DB’s DateTime and C#’s DateTime kind of fails, and results in Update-Database cmdlet failing. It’s more or less a prime example of a situation, where the error itself tells very little about the actual issue, and since debugging code-first migrations is kind of difficult (see the best tips for that here!), it’s cumbersome to investigate.

Symptoms

While running Update-Database in a code-first ASP.NET MVC5 + EF6 -project, you get a following (or similar) error:

An error occurred while updating the entries. See the inner exception for details.

The whole, pretty terrifying error message is the following:

Continue reading

“Server Error in ‘/’ Application” or “Parser Error” – it’s actually a malformed web.config killing your ASP.NET-application or SharePoint

Malformed web.config causing a Parser Error

This post describes how to resolve a kind of cryptic and oddly misdescriptive error message about Parser Error on your ASP.NET application or (On-Premises) SharePoint site. I ran into this after deploying wsp-packages to a SharePoint farm, but you can apparently get this on ASP.NET MVC sites, too.

Symptoms: Parser Error from a random-looking location

Once you navigate to your web- or SharePoint site, you only get an error like this:

Server Error in ‘/’ Application.

Parser Error

Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

Parser Error Message: Index was outside the bounds of the array.

The next few rows (the actual source of the error) seem to vary wildly. The exact source depends on what went wrong in the parsing or latest deployments. In any case, they’re usually something like this:

Parser Error
Line 3: <WebControls:XmlUrlDataSource runat="server" AuthType="None" HttpMethod="GET"> 
Line 4:  <DataFileParameters> 
Line 5:   <WebPartPages:DataFormParameter Name="RequestUrl" ParameterKey="RequestUrl" PropertyName="ParameterValues"/> 
Line 6:  </DataFileParameters> 
Line 7: </WebControls:XmlUrlDataSource>

Okay, that doesn’t tell us that much! So how to get rid of it?

Continue reading