Multi-targeting hell..Windows Identity Foundation
Funny period :-)
I know that someone will laugh up his sleeve after reading this post :-)
You have a perfectly running solution (a web solution) that utilizes Windows Identity Foundation (WS-Federation) to authenticate users, everything runs fine until you install Visual Studio 2012…
As soon as you install Visual Studio 2012 the perfectly running solution stops working with an interesting error:
Unable to cast type ClaimsIdentity to type ClaimsIdentity.
This is not the real error but the concept is clear…what the hell is going on?
What has happened?
Well…it is a bit subtle…let’s see it in the details:
- The solution targets the .Net Framework 4.0;
- The solution depends on the Windows Identity Foundation SDK;
- Visual Studio 2012 installs the .Net Framework 4.5 that is an in place upgrade of the .Net Framework 4.0;
- The .Net Framework 4.5 has its own implementation of the Windows Identity Foundation (e.g. solutions based on 4.5 does not need the WIF SDK anymore);
- When the application runs the identity token received from the Identity Provider is handled by the .Net Framework 4.5 even if the application targets the 4.0…thus the application receives an instance of ClaimsIdentity (and ClaimsPrincipal) from the System.Security.Claim namespace that lives in the mscorlib.dll of the .Net Framework 4.5 and not the expected Microsoft.IdentityModel.Claims counterpart…
If you deploy the solution to a machine running .Net Framework 4.0 everything works fine, on a machine running .Net Framework 4.5 it fails…but the most painful problem is that installing Visual Studio 2012 breaks the application in a way that is really hard to fix.
A pain in the ass… :-/