My project targets .NET 4.5. It does not use any new methods 4.5, so in fact it works fine on a computer with .NET 4.0 installed.
This is all good, until I added some extension methods and reflections. Then, when I ran this .NET 4.5 program on machine 4.0, it failed with "System.TypeLoadException: Failed to load type" System.Runtime.CompilerServices.ExtensionAttribute "from the mscorlib assembly." The famous ExtensionAttribute program, which has been well documented here .
Another quick way to check this is to add the following line. Then the program will throw an exception when launched only on .NET 4.0.
Console.WriteLine(typeof(System.Runtime.CompilerServices.ExtensionAttribute).Assembly.FullName);
I am wondering if there is a way around this. For example, ILMerge (when using the correct / targetplatform option, as indicated in the link) actually changes the ExtensionAttribute from mscorlib to System.Core if the project targets .NET 4.0 (with 4.5 installed). But it does not work in a project oriented to .NET 4.5.
I know this is a long shot. But I just want to see if anyone has any other ideas, since it was so close.
Thanks.
source share