tabs ↹ over ␣ ␣ ␣ spaces

by Jiří {x2} Činčura

Error “Could not load type ’System.Runtime.CompilerServices.ExtensionAttribute’ from assembly ’mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089’." on .NET 4.0/.NET 4.5

23 Nov 2012 1 mins .NET, Firebird

This error isn’t related only to FirebirdClient only, but any .NET application that is targeting multiple .NET Framework versions, but I spotted it first during FirebirdClient development.

The error message Could not load type 'System.Runtime.CompilerServices.ExtensionAttribute' from assembly 'mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089'. is little bit cryptic. Let me explain how all this mess happened. The .NET 4.5 is in-place update of .NET 4.0. So a lot of stuff looks like it’s .NET 4.0, but it’s not. It’s .NET 4.5. One change Microsoft did in .NET 4.5 was moving the ExtensionAttribute into mscorlib (so they can use extension methods in mscorlib). So if you build application targeting .NET 4.5 and it uses just plain .NET 4.0 (or even older) it runs fine. You’re fine, user is fine. Until it hits some extension method. Then it tries to locate the above mentioned attribute, but from mscorlib. On .NET 4.0 it’s not there. Even if the version says Yeah, in-place update.

Problem is, that users (even some developers) are not aware of these minor changes. And because the application runs – at least a while – it’s confusing. 😕 The bottom line is – always download/use exact .NET Framework version version of the application/library.

Profile Picture Jiří Činčura is .NET, C# and Firebird expert. He focuses on data and business layers, language constructs, parallelism, databases and performance. For almost two decades he contributes to open-source, i.e. FirebirdClient. He works as a senior software engineer for Microsoft. Frequent speaker and blogger at