Search code examples
c#wpfxamlcontrolsattached-properties

XAML parse exception - can find attached property in the debug version of the app, but not in release/installed version


I got an attached property like:

namespace Project.Controls.MyControl
{
    public static class Transform
    {
        public static readonly DependencyProperty RelativeOffsetXProperty = DependencyProperty.RegisterAttached(
            "RelativeOffsetX",
            typeof(double),
            typeof(Transform),
            new PropertyMetadata(
                default(double),
                OnRelativeOffsetXChanged));

        // ...
    }
}

which is used like:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:local="clr-namespace:Project.Controls.MyControl">
    <Style TargetType="{x:Type local:MyControl}">
        <Style.Resources>
            <ResourceDictionary>
                <ResourceDictionary.MergedDictionaries>
                    <ResourceDictionary Source="pack://application:,,,/Controls/MyControl/IndexItemStyle.xaml" />
                    <ResourceDictionary Source="pack://application:,,,/Controls/MyControl/ArrowButtonStyle.xaml" />
                    <ResourceDictionary Source="pack://application:,,,/Controls/MyControl/MyControlTemplate.xaml" />
                </ResourceDictionary.MergedDictionaries>
            </ResourceDictionary>
        </Style.Resources>
        
        <!--  more code -->

        <Setter Property="IncreaseInAnimation">
            <Setter.Value>
                <Storyboard>
                    <!-- more code -->
                    <DoubleAnimation BeginTime="0:0:0"
                                     FillBehavior="HoldEnd"
                                     Storyboard.TargetProperty="(local:Transform.RelativeOffsetX)"
                                     From="1"
                                     To="0"
                                     Duration="0:0:0.3" />
                </Storyboard>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>

This works great in debug no issues. But when installing the production version of the app, it crashes at startup with the following exception:

Type reference cannot find type named '{clr-namespace:Project.Controls.MyControl;assembly=Project, Version=X.X.X.0, Culture=neutral, PublicKeyToken=XXXX}Transform'

Does anyone have any idea what causes this or some tips on how to debug it? This error makes absolutely no sense, especially that everything works just fine in debug.

NOTE: Everything is in the same assembly.


Solution

  • Turns out this issue has nothing to do with WPF. The obfuscator we use simply optimized this class out. The solution was to exclude this file from obfuscation.