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!

 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.

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 came out this month, the issue is fixed! 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, among other platform DLLs, into Microsoft.IdentityModel.Clients.ActiveDirectory package itself. Hence, you’ll need no more funky hacks to ensure the DLLs get copied! 🙂

What’s new with Microsoft.IdentityModel.Clients.ActiveDirectory 3.17?

Continue reading

A quick but unknown hack to force referenced assembly to getting copied to a project

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

Referenced assembly not getting copied to a project in build might lead to surprising runtime errors. This post will explain one method of fixing these issues.

Problem

After build, you might get this kind of error:

In my case, I had referenced both of these DLLs in my “class library project”, which provided my console program a lot of functionality:

  • Microsoft.IdentityModel.Clients.ActiveDirectory.Platform
  • Microsoft.IdentityModel.Clients.ActiveDirectory

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 the “Could not load file or assembly … or one of its dependencies” error

Visual Studio logo

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:

No fear, though, as this is usually easily fixed. In quite a few cases, it’s simply a mismatch between architectures and easily changed.

Continue reading

Launching a new debugger instance from code in Visual Studio

Sequence contains more than one element

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.

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:

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 tried also making all kinds of changes to my web.config, but nothing seemed to help. There’s a simple fix available, though!

Continue reading

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

System.InvalidOperationException'

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 here), 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:

Luckily, there’s a quick workaround available. Read on!

Cue the Dispatcher

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:

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

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

entity-framework-logo

While using Entity Framework and code-first migrations, EF creates the indexes for you – but what if you need to create a custom one? Usually, it’s easy – you just add the following annotation to the columns you’ll be using:

(example stripped of extra code and other columns for clarity)

And after adding the migration (Add-Migration…) you get something like this:

But what if, when running Update-Database, you get an error like:

There’s a quick and simple solution.

Continue reading

Duplicate object values in ASP.NET MVC DisplayTemplates? Easy fix.

Duplicate String values

Are you getting duplicate object values (or whatever those Objects output in ToString())? Eh, so was I. 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 displaytemplate (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 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 DisplayTemplate.

Continue reading