Have you built a new Windows Server 2012 or Windows 8 computer or virtual machine only to find out that the Microsoft Dynamics CRM 2011 SDK managed code samples no longer compile? You may get build errors similar to the following:
'Microsoft.IdentityModel.Protocols.WSTrust.RequestSecurityTokenResponse' does not contain a definition for... Could not resolve this reference. Could not locate the assembly "Microsoft.IdentityModel"
At run time, you would see this error:
System.IO.FileNotFoundException was unhandled by user code HResult=-2147024894 Message=Could not load file or assembly 'Microsoft.IdentityModel, ...
This is a known problem and has to do with changes in Windows Identity Foundation (WIF). When Microsoft updated WIF 3.5 to the latest WIF 4.5 there was a change in the identity namespace name, and various method changes that are used by the Dynamics CRM SDK samples.
The good news is that there are easy fixes you can apply to build the SDK samples. On your Windows Server 2012 or Windows 8 computer, run a Command Prompt window or PowerShell window as administrator. Next, enter the following command to enable WIF 3.5.
dism /online /enable-feature:windows-identity-foundation
Similarly, you can disable WIF 3.5 using the following command.
dism /online /disable-feature:windows-identity-foundation
Notice that you are not downloading and installing the WIF 3.5 SDK as was documented in the 2011 SDK. Those instructions do not apply to Windows Server 2012 and Windows 8.
After you do this, most of the managed code samples in the SDK should compile and run.
However, the Windows Azure code samples located in the SampleCode\CS|VB\Azure folder of the SDK download need a little attention of their own. After you install the required Azure SDK 1.8 or later on your computer or VM as instructed by the SDK documentation, you must remove and re-add the Microsoft.ServiceBus.dll assembly reference in each listener application's project. The Windows Azure samples should now build. The QueuedListener sample will compile with warnings because it uses the now obsolete .NET classes. The provided PersistentQueueListener sample is an updated version of that same sample.
If you want to read about the changes in the identity namespace from WIF 3.5 to WIF 4.5 and the identity coding changes that will be required to move your Dynamics CRM SDK-based application code to .NET 4.5 at some future time, see Guidelines for Migrating an Application Built Using WIF 3.5 to WIF 4.5.
Microsoft Dynamics CRM SDK team