.NET logo

How to get the Description for a property in ASP.NET MVC 5?

This post describes the easiest way to show description texts for properties in ASP.NET MVC 5. Sounds simple, right? We can use something like @Html.DescriptionFor(x => x.Property), right? Alas, it’s not that straightforward. A bit surprisingly, there’s no ready-made helper function for this. I’m saying “surprisingly”, because I feel like MVC 5 really already has all the bells and whistles – AND the kitchen sink. But no, it does not have a helper for getting a description of a property :) You can, however, define…Continue reading How to get the Description for a property in ASP.NET MVC 5?

Miina (@minepupper) is fixing them bugs

EF Core returns null for a Navigation property

This article describes how to fix a situation, where you can’t use any of the navigation properties of your Entity Framework Core entities, since they are all null, despite data being in the database for sure. So, another day, another error. This time I can’t blame SharePoint, since I just messed up with ASP.NET Core and Entity Framework Core. :) Symptoms No matter what I’d do, I was getting null values for my navigation properties on my entities. They’d would always be null during runtime…Continue reading EF Core returns null for a Navigation property

.NET Core fundamentals in one picture.

How to fix Microsoft.AspNetCore.Mvc.TagHelpers not being rendered!

Ha – another one, that ended up being a simple fix, but since nobody actually explains it well, took me an hour to figure out. This post ended up being another example of my “I’m going to document every single fix, that took me more than 10 minutes to figure out, since that’ll help me (and others) the next time the same issue arises.” blogging strategy. Snappy name, right? Never was my strongest suit! Anyway, I ended up banging my head to the wall. Hopefully…Continue reading How to fix Microsoft.AspNetCore.Mvc.TagHelpers not being rendered!

.NET logo

How to get current user in ASP.NET Core?

This post describes how to get the currently logged in user using ASP.NET Core. This is compared with how it’s done in .NET Framework. Background In .NET Core, a lot of things are done a bit differently. That’s what I’ve been learning building more and more stuff with it, instead of good old .NET Framework. The learning curve is definitely there, but it’s not that bad – most of the things work in a similar fashion, but a huge number of details are different. In…Continue reading How to get current user in ASP.NET Core?

The following functions are in error... And that's about it.

Fixing “The following functions are in error: Object reference not set to an instance of an object.” error in Azure Functions

Let me start this article, by reminding everyone that Azure Functions are awesome, and you should use them despite some hiccups. Having said that, let’s fix some errors! In the beginning of September 2018, Microsoft started pushing out breaking changes to Azure Functions 2.x. They had announced this a full month in advance, so they expected everyone in the world to update their Azure Functions to avoid the functions from breaking. I guess, however, that in real life, a month is not that much. Me,…Continue reading Fixing “The following functions are in error: Object reference not set to an instance of an object.” error in Azure Functions

Azure Functions SDK 2.0 settings in accessed in C# code

How to access Azure Function App’s settings from C#?

This post describes, how you can access the function’s Application/Environmental settings/variables from your C# code. Different versions of Azure Functions have different ways to access the Azure Function settings. This has been another little thing, that I always forget – so better document it somewhere! How to get application settings in different runtime versions of Azure Functions? This has changed between different versions of Azure Functions runtime – so I’m describing what works for your functions using v1 runtime, what works for v2, and of…Continue reading How to access Azure Function App’s settings from C#?

Mock Function call to force loading an assembly - how elegant!

New version of Microsoft.IdentityModel.Clients.ActiveDirectory (ADAL.NET) is out – good time to update!

There’s now a new version of the assembly Microsoft.IdentityModel.Clients.ActiveDirectory available – plenty of reasons to update right away! Let me offer you one hot take on the matter since the earlier 3.x -versions of the package had some issues. Why bother updating? In an earlier post I described an issue I had with Microsoft.IdentityModel.Clients.ActiveDirectory.Platform not getting copied during the build in a referencing project. In 3.17.0, which the developers published this month, they fixed the issue! The new package actually contains separate DLLs for different platforms. In…Continue reading New version of Microsoft.IdentityModel.Clients.ActiveDirectory (ADAL.NET) is out – good time to update!

Mock Function call to force loading an assembly - how elegant!

A quick (and handy!) hack to force referenced assembly to getting copied to a project

Visual Studio failing to copy a referenced assembly to a project in build might lead to surprising runtime errors. This post will explain one method of fixing these issues, using Microsoft.IdentityModel.Clients.ActiveDirectory as the example – as earlier versions of that assembly had this issue! Problem After build, you might get this kind of error: Could not load file or assembly ‘Microsoft.IdentityModel.Clients.ActiveDirectory.Platform, Version=3.13.1.846, Culture=neutral, PublicKeyToken=31bf3856ad364e35’ or one of its dependencies. The system cannot find the file specified. System.IO.FileNotFoundException at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint,…Continue reading A quick (and handy!) hack to force referenced assembly to getting copied to a project

Sequence contains more than one element

Easiest way to debug Seed-method in Code-first migrations in Entity Framework

This post describes the easiest way to debug the issues that may stop your Seed-method in Configuration.cs from going through. This problem concerns typically your ASP.NET MVC projects, either on .NET Framework or .NET Core – the same basic idea should work for both situations. 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: How to launch the visual studio debugger from code/) Description Entity Framework’s…Continue reading Easiest way to debug Seed-method in Code-first migrations in Entity Framework

Visual Studio logo

Fixing the “Could not load file or assembly … or one of its dependencies” error

This post describes how to fix the “Could not load file or assembly ‘[assemblyname]’ or one of its dependencies. An attempt was made to load a program with an incorrect format.” error.  The solution described in this post shows you how to resolve the issue when you’re deploying from Visual Studio, but get the error “Could not load file or assembly or one of its dependencies” when deploying to IIS or when opening your website after the deployment. Problem Especially while installing a new dev…Continue reading Fixing the “Could not load file or assembly … or one of its dependencies” error

Sequence contains more than one element

Launching a new debugger instance from code in Visual Studio

This post describes a quick solution to launching a new Visual Studio instance for debugging the code. There’s a lot of applications for this, but where I’ve found it exceptionally useful, has been in debugging the Entity Framework’s code-first migration’s (one of the ways for database initialization) Seed-method. It is by default undebuggable, as when you are running Update-Database you can’t really use a -debug switch or anything, and there’s really no way to launch the debugger. Hence the best you can do is using…Continue reading Launching a new debugger instance from code in Visual Studio

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

Fixing error “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, your application is probably built on .NET Framework and Entity Framework. Let’s get into it! Error When debugging/running your code, somewhere in your code where you’re supposed to access the database using Entity Framework, you get an error like…Continue reading Fixing error “No Entity Framework provider found for the ADO.NET provider with invariant name ‘System.Data.SqlClient’”

System.InvalidOperationException'

Using Dispatcher to update values in GUI elements from a background thread

If you’re developing something like a WPF app and you’ll need to update values on the User Interface based on a long-running operation that runs in a background thread (like depicted in my other blog post right here – that post is for a full-trust SharePoint solution, but the basic principle is the same!), you’ll probably need to use Dispatcher, or otherwise you’ll run into issues with the GUI elements being owned by another thread, and therefore forbidding access to them. This can result in an…Continue reading Using Dispatcher to update values in GUI elements from a background thread

Spatial SQL types

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

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:…Continue reading Solving the “Spatial types and functions are not available …” -problem

entity-framework-logo

Fixing the error: “Column XX in table dbo.YY is of a type that is invalid for use as a key column in an index.”

While using Entity Framework and code-first migrations, Entity Framework (EF) creates the indexes for you – but what if you need to create a custom one, explicitly based on certain field / column? Then you’ll have to tell EF which one to use as a key column. Usually, it’s easy – you just add the following annotation to the columns you’ll be using: [Index(“OfficialIds”, 1)] public int AreaId { get; set; } [Index(“OfficialIds”, 2)] public string EstateId { get; set; } (example stripped of extra code and other columns for clarity) And after adding the migration (Add-Migration… commandlet) you get…Continue reading Fixing the error: “Column XX in table dbo.YY is of a type that is invalid for use as a key column in an index.”

Duplicate String values

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

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…Continue reading Duplicate object values in ASP.NET MVC Display Templates? Easy fix!

Entity Framework's Update-Database throwing an error

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

This post describes an issue with EF’s code-first migrations, when mapping between DB’s DateTime (datetime2) and C#’s DateTime simply fails, and results in the Update-Database cmdlet failing, too. 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 So what’s the error that we’re running into, exactly? Below, you can find the most…Continue reading Fixing “An error occurred while updating the entries” while running code-first migrations in MVC 5 app

Stock photo from pixabay.com

Simplest way to create a thread on SharePoint

This post describes the (probably) easiest and most straightforward way of creating a new Thread in your SharePoint (or any other .NET) server-side / desktop code. Solution: how to create a new Thread Let’s face it – one should not create new Threads lightly when developing SharePoint solutions, but sometimes it’s difficult to avoid. Or sometimes it’s just the simplest way to get around weird framework limitations. Posts Related to “Simplest way to create a thread on SharePoint”:5 ways to enable Custom Scripts for a…Continue reading Simplest way to create a thread on SharePoint

SharePoint2013

How to properly use SPWeb.AllowUnsafeUpdates?

At times you may need to allow unsafe updates for SPWeb objects to get your code to run. This, in SharePoint’s C# full-trust code, is done by setting SPWeb.AllowUnsafeUpdates to true. However, as this is an exception to security settings, you should generally avoid it. When you can’t, it’s a good practice to limit the change to as small a scope as possible. This is true even though the setting is only persisted for the duration of the request (unless the SPWeb object was gotten…Continue reading How to properly use SPWeb.AllowUnsafeUpdates?

SharePoint List Field Name creation dialog - the internal names for created fields are generated from the display name, and often end up being quite messy!

Programmatically creating readable internal names for new SharePoint fields

This post is about a small programmatic workaround to creating new SPFields for SPLists in SharePoint with human-readable internal names. This is mainly a usability improvement for your editors (and doesn’t change your life that much), but at the very least they will probably appreciate it! In short, I’ll show you how to avoid SharePoint’s dirty encoding (like replacing a space with “_x0020_”). This appliesto when you’re using server-side code to generate fields. Problem: non-readable internal names for SharePoint list fields When you create a…Continue reading Programmatically creating readable internal names for new SharePoint fields