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

Reading Time: 3 minutes. 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, and a bunch of other people on the internet, ran into some issues with our […]

Azure Functions SDK 2.0 settings in accessed in C# code

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

Reading Time: 4 minutes. Different versions of Azure Functions have different ways to access the Azure Function settings. This is another little thing, that I always forget – so better document it somewhere! So, this post describes, how you can access the function’s Application/Environmental settings/variables from your C# code. Posts Related to “How to access Azure Function App’s settings from C#?”:SharePoint Localization – a (somewhat) comprehensive how-to!Privacy PolicyFixing an unhandled exception about StructureMap configuration failing (messed up assembly bindings)

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!

Reading Time: 2 minutes. 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 essence this means, that from C#/.NET -developer’s standing point, the team has assimilated the Microsoft.IdentityModel.Clients.ActiveDirectory.Platform assembly, […]

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

Reading Time: 3 minutes. 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, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, […]

Sequence contains more than one element

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

Reading Time: 5 minutes. 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 […]

Visual Studio logo

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

Reading Time: 2 minutes. 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.  Problem Especially while installing a new dev machine, and building your project for the first time, you may end up getting the following exception: Could not load file or assembly ‘<assemblyname>’ or one of its dependencies. An attempt was made to load a program with an incorrect format. No fear, though, as this is usually easily fixed. In quite a few cases, it’s simply a mismatch between architectures […]

Sequence contains more than one element

Launching a new debugger instance from code in Visual Studio

Reading Time: 2 minutes. This post describes a quick solution to launching a new Visual Studio instance for debugging the code. Where I’ve found this exceptionally useful, has been in debugging code-first migration’s (one of the ways for database initialiation in .NET) 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 -verbose to get more information. However, if you actually want to see what is happening in the code, here’s the solution. Posts Related to […]

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'”

Reading Time: 2 minutes. 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 […]

System.InvalidOperationException'

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

Reading Time: 3 minutes. Quick tip: 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 error like this: An unhandled exception of type ‘System.InvalidOperationException’ occurred in WindowsBase.dll   […]

Spatial SQL types

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

Reading Time: 3 minutes. 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 […]

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.”

Reading Time: 2 minutes. 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 something like this: CreateIndex(“dbo.Areas”, new[] { “AreaId”, “EstateId” }, name: “OfficialIds”); Okay, nice. Don’t have to create the indexes myself either, so […]

Duplicate String values

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

Reading Time: 2 minutes. 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 […]

Update-Database error

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

Reading Time: 6 minutes. 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 "An exception of type ‘System.Data.Entity.Infrastructure.DbUpdateException’ occurred in EntityFramework.dll but was not handled in user code." I’ve encountered this error in 2 different situations. Either while inserting new entries into the database (in […]

Stock photo from pixabay.com

Simplest way to create a thread on SharePoint

Reading Time: 2 minutes. 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”:Programmatically creating readable internal names for new SharePoint fieldsSharePoint Localization – a (somewhat) comprehensive how-to!Fixing an unhandled exception about StructureMap configuration failing (messed […]

SharePoint2013

How to properly use SPWeb.AllowUnsafeUpdates?

Reading Time: 1 minute. At times you may need to allow unsafe updates to SPWeb objects to get your code to run. This, in SharePoint C# code-behind is done by setting SPWeb.AllowUnsafeUpdates to true. However, as this is an exception to security settings, and should generally not be done, it’s a good practice to limit the change to as small a scope as possible – even though the setting is only persisted for the duration of the request (unless the SPWeb object was gotten from SPSite.GetWeb() or SPSite.Webs[]). What to do? I’ve found the easiest way to temporarily allow unsafe updates in a safe […]

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

Reading Time: 4 minutes. 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 new field in SharePoint, SharePoint accepts the following syntax: string internalName = list.Fields.Add("Field name – […]