I’ve been working on converting our Windows Phone 7 app to use the Windows Phone 8 SDK for the past 1.5 months, and it’s been quite the struggle. No matter what I did, I couldn’t get any Windows Phone 8 projects to compile! They all returned the same error:
“Cannot resolve reference assemblies. Please check the reference assemblies. Could not load file or assembly ‘System.Core, Version=22.214.171.124, Culture=neutral, PublicKeyToken=7cec85d7bea7798e’ or one of its dependencies. The located assembly’s manifest definition does not match the assembly reference.”
It was quite the connundrum. So I cracked out my pipe, put on my tweed jacket and ruminated as to what might be happening here. The first clue I had was that the XAML files were looking for a reference of the System.Core.dll with the version 126.96.36.199. System.Core is the base .NET assembly which is expected, but what is off is the version number. Windows Phone 8 is built off some derivation of the .NET 4.0 framework, so the System.Core file it should expect to use should have a version of 4.0.x or something.
Assembly binding errors are the bane of any .NET developer’s existence and once again I was confronted by it.
I checked the Global Assembly Cache to see what version of System.Core was registered and I only had the .NET 4.0.x version. I checked the XAML file to ensure there wasn’t any errant references to the older System.Core assembly. The XAML looked like this:
<!–LayoutRoot is the root grid where all page content is placed–>
<Grid x:Name="LayoutRoot" Background="Transparent">
<!– ApplicationBar –>
<shell:ApplicationBar IsVisible="True" IsMenuEnabled="True" Mode="Minimized">
<shell:ApplicationBarIconButton IconUri="/Assets/AppBar/appbar.back.rest.png" IsEnabled="True" Text="back" Click="BackApplicationBar_Click"/>
<shell:ApplicationBarIconButton IconUri="/Assets/AppBar/appbar.next.rest.png" IsEnabled="True" Text="forward" Click="ForwardApplicationBar_Click"/>
<shell:ApplicationBarMenuItem Text="home" Click="HomeMenuItem_Click" />
It’s clean, no errant references.
Still stumped, I decided it was time to take the gloves off and start building my project at the command line. So I opened up the Visual Studio 2012 Command Line, and ran a MSBuild.exe with this command:
MSBuild.exe HTMLPhoneApp1.csproj /v:diagnostic /fl1
This gave me a full verbose dump of every step in the compilation process. Buried in the middle of this log I found the error being thrown during the build step with the name “ValidateXAML”. I inspected the Microsoft.WindowsPhone.Common.targets file under “C:Program Files (x86)MSBuildMicrosoftWindowsPhonev8.0”, but that all looked fine.
Then I remembered what a Winston Churchil had said to me in a dream I had many years ago:
“Son, when life gives you XAML validation errors, turn off XAML validation.”
Brilliant! So I cracked open the .csproj file in a XML editor and edited the ValidateXaml property to ‘false’.
And voila! Everything compiled and I was off. I’ve now built and debugged my old app in Windows Phone 8 and everything is working on the device and emulator. Now, this isn’t a real solution to the root cause, but it’s a workaround to get you moving again if you are stuck like I was.
If your Windows Phone 8 project fails during XAML compilation due to incorrect assembly references, turn off XAML validation in the .csproj file to get around the issue.
Get the latest from the Blue Label Labs' blog in your inbox.
More in Development
DesignRush’s Top App Design and Development Company
We don’t like to brag, but we are going to anyway. This…
What is Dogfooding & Why You Should Hire an Agency That Does It
“There’s an app for that!” And we can’t stop using it. Everyone…
How to Work With App Developers and Upgrade Your E-POS System
Cash is a thing of the past. Credit cards are becoming old…