2
votes

I updated one UWP App to a newer SDK and set target version to 16299 and Min Version to 15063.

Then I'm using the Windows.Foundation.UniversalApiContract Namespace to use features of the new SDK if available. Example:

xmlns:contract5NotPresent="http://schemas.microsoft.com/winfx/2006/xaml/presentation?IsApiContractNotPresent(Windows.Foundation.UniversalApiContract,5)"
xmlns:contract5Present="http://schemas.microsoft.com/winfx/2006/xaml/presentation?IsApiContractPresent(Windows.Foundation.UniversalApiContract,5)"

<contract5Present:NavigationView x:Name="NavView" ...

The build failed with no error message displayed. But when I set build log to detailed it seems that it won't find the assemblies:

Could not resolve this reference. Could not locate the assembly "Windows.Foundation.FoundationContract, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.

The Folder and files exist on C:\Program Files (x86)\Windows Kits\10\References**10.0.16299.0**\Windows.Foundation.FoundationContract\3.0.0.0 AND C:\Program Files (x86)\Windows Kits\10\References**10.0.15063.0**\Windows.Foundation.FoundationContract\3.0.0.0

Update 1: It seems it has to to with my resource disctionary and the acrylic brushes. If I copy my resource dictionary to a blank app the same error occurs. If I remove the contract thing and all acrylic brushes from the resource disctionary the build succeeded. So what am I missing here?

Update 2: I finally found where the issue occurs (maybe you can reproduce, just start with an blank app (Target: Fall Creators, Min Version: Creators Update), create a ResourceDictionary and copy this into it):

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                xmlns:local="using:App6"
                xmlns:contract5NotPresent="http://schemas.microsoft.com/winfx/2006/xaml/presentation?IsApiContractNotPresent(Windows.Foundation.UniversalApiContract,5)"
                xmlns:contract5Present="http://schemas.microsoft.com/winfx/2006/xaml/presentation?IsApiContractPresent(Windows.Foundation.UniversalApiContract,5)"
                >

<Thickness x:Key="HeaderMargin">20,41,0,0</Thickness>

<ResourceDictionary.ThemeDictionaries>
    <ResourceDictionary x:Key="Light">
        <Color x:Key="BrandColor">#D1D1D1</Color>
        <contract5Present:AcrylicBrush x:Key="OptionsPaneBackground" BackgroundSource="Backdrop" TintColor="{StaticResource BrandColor}" TintOpacity="0.2" FallbackColor="#D1D1D1" />
    </ResourceDictionary>

    <ResourceDictionary x:Key="Dark">
        <Color x:Key="BrandColor">#3F3F46</Color>
        <contract5Present:AcrylicBrush x:Key="OptionsPaneBackground" BackgroundSource="Backdrop" TintColor="{StaticResource BrandColor}" TintOpacity="0.6" FallbackColor="#3F3F46" />
    </ResourceDictionary>

</ResourceDictionary.ThemeDictionaries>
</ResourceDictionary>

If I remove the first line (thickness) from the dictionary the Build succeed. My system runs on April 2018 Update, but I have the same issue on another machine with the Fall Creators Update.

Solution: I've splitted ThemeResources and Styles into two seperate ResourceDictionaries and now the build succeeded in my main project. But I do not understand why this is happening and why no exact error message appears. I've spent about 8 hours (my project has >70000 lines of code) to find the issue and I'm a little bit angry about it :)

1

1 Answers

4
votes

It seems there are some issue with your 16299 and 15063 SDK file, you can try to open the file explorer and go to the corresponding file location to see whether the SDK is existed.

The path should be: C:\Program Files (x86)\Windows Kits\10\References\10.0.15063.0(10.0.16299.0)\Windows.Foundation.FoundationContract\3.0.0.0\

Otherwise, you can try to download and install the SDK version again from the Windows SDK and emulator archive.

If this still can not work, please also try to update the Microsoft.NETCore.UniversalWindowsPlatform Nuget to the latest version then restart your VS, clean and rebuild your app again. By the way, please also provide your device OS version and OS build to help me look into this issue.

---Update---

Another workaround is that you can declare the contents of the ResourceDictionary after the <ResourceDictionary.ThemeDictionaries></ResourceDictionary.ThemeDictionaries> tag pair. This will prevent the crash from triggering.