Fixing an unhandled exception about StructureMap configuration failing (messed up assembly bindings)

Obama congratulates you on your broken apps

So, you’re running a console program, but while you try running it, you get an error like this: “StructureMap.Exceptions.StructureMapConfigurationException”, with a message like this: “Unable to find the exported Type’s in assembly” (the typo done by Microsoft, not me). There’s a number of reasons for this error, but for a fair share of the time that’s just your assembly bindings being messed up. Luckily, that’s another easy fix! 

Problem

When running the executable (probably an .exe), or after scheduling a task, or possibly after running an Azure webjob, you discover an error like this from the log files, or get it in your console, or log stream:

It’s also possible to get errors in your task scheduler, something like this:

“0xE0434352” apparently refers to unknown software errors – so that’s not useful 🙂 However, this error might be a symptom of incorrect assembly rebinding configuration. This configuration is typically done in the .config -file accompanying the executable – so probably in a file named something like <yourexecutable>.exe.config.

Solution: remove incorrect bindings

Take a backup of the file first, then open it, browse to <runtime> -section, and remove the whole <assemblyBinding xmlns=”urn:schemas-microsoft-com:asm.v1″> -node and everything inside it.

So instead of looking like a bloated mess like this:

NuGet Package Manager has messed up the bindings of the project - just look at this nonsense in the app.config -file!

NuGet Package Manager has messed up the bindings of the project – just look at this nonsense in the app.config -file!

It should look lean and beautiful like this:

"App.config

And the same examples in text – the messed up version:

And the cleaned up version of the file:

In this example, the bindings for the Microsoft.IdentityModel.Clients.ActiveDirectory was actually needed, and everything else was nonsense. See more about this particular assembly here:

Then try running the executable again.

Please note: Even though NuGet package updates make your assembly binding configuration into a whole mess, as they add these bindings automatically, and there’s a good chance they are not actually required, you MIGHT also have them for a reason 🙂 In that case, you’ll be getting another error after clearing the bindings from configuration. Only this time the error will be about incorrect assembly version – that’s usually at least a bit useful! In this case, you can just restore the bindings for that particular assembly from the backup you took earlier.

The following two tabs change content below.
Antti Koskela is a proud digital native nomadic millenial full stack developer (is that enough funny buzzwords? That's definitely enough funny buzzwords!), who works as a Solutions Architect for Valo Intranet, the product that will make you fall in love with your intranet. Working with the global partner network, he's responsible for the success of Valo deployments happening all around the world. He's been a developer from 2004 (starting with PHP and Java), and he's been bending and twisting SharePoint into different shapes since MOSS. Nowadays he's not only working on SharePoint, but also on .NET projects, Azure, Office 365 and a lot of other stuff.This is his personal professional (professional, but definitely personal) blog.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.