Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XAML editor complains "Object does not match target type" for SharedResourceDictionary.Source

We use SharedResourceDictionary in our project. The dictionary is constructed from several posts here on SO. But I have reduced it to this:

public class SharedResourceDictionary : ResourceDictionary
{
    public new Uri Source
    {
        get { return base.Source; }
        set { base.Source = value; }
    }
}

In new VS2015 the XAML designed cannot load the styles and complains

1. The resource "..." could not be resolved.
2. Object does not match target type.
3. The resource "..." could not be resolved.
4. The resource "..." could not be resolved.
5. The resource "..." could not be resolved.

in the following markup (underscored text is where it complains):

<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             Style="_1_{StaticResource ...}__"
             ...
             >
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <utils:SharedResourceDictionary _2_Source="pack://application:,,,/.../Styles.xaml"__ />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>

    <StackPanel Style="_3_{StaticResource ...}__">

the resources and controls are in different assemblies.

Have you maybe experience the same or do know the solution?

Update: In fact, replacing the utils:SharedResourceDictionary with just the ResourceDictionary makes it work without error.

Update2: This issue is not because of Styles.xaml - I've created almost empty resource file:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <SolidColorBrush x:Key="Test" Color="#FFFFFF" />
</ResourceDictionary>

and Visual Studio Design editor just complains exactly the same. And it works if I just replace utils:SharedResourceDictionary with ResourceDictionary.

Update3: SharedResourceDictionary is minimalistic now but XAML editor still complains.

like image 759
Alex Netkachov Avatar asked Oct 30 '22 22:10

Alex Netkachov


1 Answers

It might be very well an issue of VS2015; I've had issues with the XAML editor of it myself, giving errors for XAML files I've written in VS2013 and were tested and working. Try opening the project in VS2013, it might solve the issue. No promises on this one.

like image 146
Kanadaj Avatar answered Nov 15 '22 06:11

Kanadaj