locked
Bug: Object reference not set to an instance of an object compiling xaml

    Question

  • I have discovered a problem where compiling the following Xaml results not in an error identifiable to the actual Xaml file but a solution wide error:
    Xaml Internal Error error WMC9999: Object reference not set to an instance of an object.

    This is really bad, as there is no way of telling which file has caused it and it took me some time to figure it out.

    I'm trying to share as much code as I can with my other Silverlight and WPF platforms. Unfortunately WinRT makes this terribly difficult.  I'm using a preprocessor now to try and make life slightly simpler - it fixes up annoying differences between the xmlns statements (no idea why the WinRT compiler can't just accept the old style WPF xmlns statements, that would make my life so much better!).

    Anyway, so I had some code that was using the validation template for Silverlight and WPF, this is obviously not relevant to WinRt, but instead of ignoring it it gives this message when you have this binding:
    {Binding (Validation.Errors)[0].ErrorContent}

    PLEASE could this bug be fixed so that an identifiable error is produced, both in the Xaml editor, (which to its credit gives a slightly clearer error ("The text associated with this error code could not be found. Failed to assign to property 'Windows.UI.Xaml.Data.Binding.Path') although it isn't clear which path it is talking about) and even more importantly in the compiler.  Whilst WinRT may reject the particular binding syntax there is no way that it should have an error which gives you no way to identify the file or the problem.

    Thanks,
    Stefan

    Full xaml code to reproduce:

    <Page
        x:Class="winApp1.MainPage"
        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"
        mc:Ignorable="d">
        <Page.Resources>
            <ControlTemplate x:Key="ValidationToolTipTemplate">
                <TextBlock UseLayoutRounding="false" Text="{Binding (Validation.Errors)[0].ErrorContent}" TextWrapping="Wrap" Margin="8,4,8,4" MaxWidth="250" Foreground="White"/>
            </ControlTemplate>
        </Page.Resources>
    
    </Page>
    

    Saturday, May 3, 2014 7:12 AM

All replies

  • Can you explain why this is a bug and not a feature request?

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Monday, May 5, 2014 12:18 PM
    Moderator
  • Because there are absolutely zero circumstances under which the compiler should not tell you exactly what and where the error is.  That is the bug.  The support of particular binding syntax would be a feature request, that's not the point here (although just adds to my frustration that things are incompatible across all four Xaml platforms that I use).

    I could cope with it if the error told me which file, and which line, it was happening in, then I could go and find and fix the problem. I have hundreds of Xaml files in my project and it took an incredibly long time to figure out which particular one was causing the problem.

    So the bug is that the compiler should not be giving a solution wide error with no explanation as to which file and line has caused the problem.  I would have thought that by definition having: "Xaml Internal Error error WMC9999: Object reference not set to an instance of an object." was a bug. I shouldn't be encountering Xaml internal errors.

    Stefan

    Monday, May 5, 2014 8:02 PM
  • I can agree with this reasoning. Can you post a Connect bug?

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Tuesday, May 6, 2014 12:42 PM
    Moderator
  • Sure can. I have tried to go to the connect site and find out the correct product to put it under but can't figure that out. Is there a link you can give me to go to the right place please?
    Saturday, May 10, 2014 6:32 AM