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=184.108.40.206, 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 220.127.116.11. 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
My Picks for the Best Driving Enthusiast Apps
During the day, I’m the COO of Blue Label Labs, so I…
10 Top Rated Mobile App Mockup Tools
Functionality and aesthetics now cross realms more than ever. This is precisely…
How Much Does It Cost to Maintain an App?
Software is just anything you can possibly own – there is a…