locked
Can not define dependencyproperty of type "byte"? RRS feed

  • Question

  • I want to define a byte type dp in a windows store app project, but got a runtime error like this:

    An exception of type 'Windows.UI.Xaml.Markup.XamlParseException' occurred in App6.exe but was not handled in user code

    WinRT information: Cannot deserialize XBF metadata property list as 'Id' was not found in type 'null'. [Line: 0 "text-decoration:underline;">Additional information: The text associated with this error code could not be found.

    (I am using vs2013 and WinRT8.1)

    Here is the source code:

    [MainPage.cs]

    namespace App1
    {
        public sealed class MyClass2
        {
            public byte Id { get; set; }
        }
    
        public sealed class MyClass: DependencyObject
        {
            public byte Id
            {
                get { return (byte)GetValue(IdProperty); }
                set { SetValue(IdProperty, value); }
            }
            public static readonly DependencyProperty IdProperty =
                DependencyProperty.Register("Id", typeof(byte), typeof(MyClass), new PropertyMetadata(0));
        }
    
        public sealed partial class MainPage : Page
        {
            public MainPage()
            {
                this.InitializeComponent();
            }
        }
    }

    [MainPage.xaml]

    <Page
        x:Class="App1.MainPage"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="using:App6"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d">
        <Page.Resources>
            <local:MyClass2 x:Key="MyObj2" />
            <local:MyClass x:Key="MyObj"
                           Id="{Binding Id, Source={StaticResource MyObj2}}"/>
        </Page.Resources>
        <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    
        </Grid>
    </Page>



    Saturday, November 2, 2013 10:31 AM

Answers

  • The way the dp is declared looks correct within the class. If you look in the VS Error List tab does it say: Could not find Windows Runtime type 'Windows.Foundation.UInt8'?

    Saturday, November 2, 2013 5:57 PM

All replies

  • The way the dp is declared looks correct within the class. If you look in the VS Error List tab does it say: Could not find Windows Runtime type 'Windows.Foundation.UInt8'?

    Saturday, November 2, 2013 5:57 PM
  • Hi, Ben, I doesn't find the error as you said. All I got is this:

    A first chance exception of type 'Windows.UI.Xaml.Markup.XamlParseException' occurred in App1.exe
    WinRT information: Cannot deserialize XBF metadata property list as 'Id' was not found in type 'null'. [Line: 0 "text-decoration:underline;">An exception of type 'Windows.UI.Xaml.Markup.XamlParseException' occurred in App1.exe but was not handled in user code
    WinRT information: Cannot deserialize XBF metadata property list as 'Id' was not found in type 'null'. [Line: 0 "text-decoration:underline;">Additional information: The text associated with this error code could not be found.

    Cannot deserialize XBF metadata property list as 'Id' was not found in type 'null'. [Line: 0 Position: 0]


    This  error info is kind of misleading. In fact, it cost me almost a whole day to figure out what just happed(I am working on a quite big project which contains more than 20 xaml files). When I changed the type from "byte" to "int", the bug was gone, everything became ok. Oh, my, I have to say the error info is too misleading!

    Sunday, November 3, 2013 3:50 AM
  • The way the dp is declared looks correct within the class. If you look in the VS Error List tab does it say: Could not find Windows Runtime type 'Windows.Foundation.UInt8'?

    We were working on making a custom control that needed a Byte based property and ran into the same issue with this error.  After additional testing we found that WinRT is broken in terms of using Byte or SByte as dependency property return types.  All other standard .NET numeric types work as expected.

    We just submitted a Connect issue here:

    https://connect.microsoft.com/VisualStudio/feedback/details/860903/winrt-dependency-properties-have-fatal-errors-when-property-type-is-byte-or-sbyte

    We uploaded an attachment sample that easily reproduces the problem, but it sometimes takes a bit for attached files to show up in Connect.  Please help by upvoting the Connect bug so that we can get this fixed and working properly.


    actiprosoftware.com - Professional WPF, WinRT, Silverlight, and WinForms UI controls and components

    Friday, April 25, 2014 2:56 PM
  • I am pretty sure I found a similar bug. When a dependency property registers an attached property of type MediaCapture to be bound to a CaptureElement source, the error message is similar:

    WinRT information: Cannot deserialize XBF metadata property list as '%1' was not found in type '%0'.

    Wednesday, May 28, 2014 10:52 PM