Core: `dotnet build` fails to build XAML string resources

Created on 20 Oct 2018  路  7Comments  路  Source: dotnet/core

In a .NET Core (3.0.100-alpha1-009689) WPF project, the following XAML file builds fine with MSBuild but fails to build with dotnet build:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:system="clr-namespace:System;assembly=mscorlib">
    <system:String x:Key="StringResource">Foo</system:String>
</ResourceDictionary>

dotnet build gives this error:

error MC3061: The Element type 'System.String' does not have an associated TypeConverter to parse the string 'Foo'. Line 4 Position 43.
area-wpf

Most helpful comment

This has been fixed, and the change is in 10/27/18 and later builds. Please verify and close when you get a chance. Thanks.

Tested dotnet build and dotnet run on 3.0.100-alpha1-009708:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:system="clr-namespace:System;assembly=mscorlib">
    <system:String x:Key="StringResource">Foo</system:String>
</ResourceDictionary>
<Window x:Class="test3.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:test3"
        xmlns:system="clr-namespace:System;assembly=mscorlib"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">

    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="MyResourceDictionary.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Window.Resources>

    <TextBlock Text="{StaticResource StringResource}"/>
</Window>

All 7 comments

@ericstj @danmosemsft is that something in BCL or WPF?

Maybe one of the TypeConverter work items we already have. @ericstj

That doesn't sound right, I'll see about a repro.

Here's a repro:
rd.zip

Found the problem. XamlTypeMapper is comparing runtime type to reference type here:
https://referencesource.microsoft.com/#PresentationBuildTasks/Framework/System/Windows/Markup/BamlMapTable.cs,150

The passed in parameters will refer to the reference location but the probeType will come from an actual type object, and thus be runtime type (since PBT is running on .NETCore).

That doesn't work when the runtime type is in a different location. In this case the difference is that System.String reference is in System.Runtime.dll but runtime is in System.Private.CoreLib.dll.

It then falls back to try reflection to read a TypeConverter attribute, which won't be there, since this is the core assembly-far below TypeConverter, then fails.

This code would have been broken on desktop if we ever forwarded types. Its similar to the serializer case which uses "TypeForwadedFrom" in order to locate the assembly from which the type was forwarded from.

/cc @nguerrera @ryalanms @rladuca @vatsan-madhavan

This has been fixed, and the change is in 10/27/18 and later builds. Please verify and close when you get a chance. Thanks.

Tested dotnet build and dotnet run on 3.0.100-alpha1-009708:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:system="clr-namespace:System;assembly=mscorlib">
    <system:String x:Key="StringResource">Foo</system:String>
</ResourceDictionary>
<Window x:Class="test3.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:test3"
        xmlns:system="clr-namespace:System;assembly=mscorlib"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">

    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="MyResourceDictionary.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Window.Resources>

    <TextBlock Text="{StaticResource StringResource}"/>
</Window>

Closing as fixed for easier traffic. It can be reopened if the issue is not fully addressed.

I've confirmed this issue is fixed. Thanks @ryalanms!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ffes picture ffes  路  3Comments

Luis-DdlFG picture Luis-DdlFG  路  3Comments

omerlh picture omerlh  路  4Comments

rykr picture rykr  路  3Comments

Rand-Random picture Rand-Random  路  4Comments