MaterialDesignInXamlToolkit icon indicating copy to clipboard operation
MaterialDesignInXamlToolkit copied to clipboard

DialogHost: XamlObjectWriterException - Unresolved reference 'ContentCoverBorder'

Open MichelMichels opened this issue 10 months ago • 14 comments

Bug explanation

When running a Window with nothing else but a DialogHost, following exception gets thrown: System.Xaml.XamlObjectWriterException in System.Xaml.dll Additional text: Unresolved reference 'ContentCoverBorder.

It has something to do with this PR: https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit/commit/bfe348fed9334ea36eebe97f0897ef01c96afb15

When I revert this change, the issue goes away but the binding error shows up again.

Version

5.0.0

MichelMichels avatar Apr 11 '24 09:04 MichelMichels

Additional context:

Above sources seem to indicate that the use of x:Reference is discouraged or even prohibited?

MichelMichels avatar Apr 11 '24 09:04 MichelMichels

I am experiencing the same issue with my app when I try to debug it.

alexachso avatar Apr 29 '24 15:04 alexachso

I have attempted to reproduce the issue on a new project but the problem does not occur.

Hadramet avatar May 17 '24 23:05 Hadramet

@MichelMichels @alexachso Can any of you provide a small sample that reproduces this? I am unable to reproduce it in a simple WPF app with a Window including just a DialogHost in it. I have tried with an empty DialogHost and also with actual content, but it works in both cases for me.

I am using the latest code (i.e. project reference rather than nuget package). I also tried with the official nuget packages, and still cannot repro the issue.

nicolaihenriksen avatar Jun 10 '24 13:06 nicolaihenriksen

HI @nicolaihenriksen, I cannot reproduce either. I remember seeing it and then I commented on this issue on 29th of April. If I checkout the commits I did that day of my app and run the app, the binding failure is no longer present. Maybe it is worth mentioning that I run Visual Studio preview. Since I checkout the exact commit that I remember I had the binding failure, the problem should reproduce, but the only thing different from then and now is that since then I updated the visual studio preview version. I don't remember on which version on Visual studio preview I was on 29th of April. :( I'll keep an eye on this, and if I re-encounter it I'll let you know.

alexachso avatar Jun 17 '24 12:06 alexachso

@nicolaihenriksen @alexachso this could be the answer. I also run the Microsoft Visual Studio preview edition. I'll update to latest version and check if the issue still occurs.

MichelMichels avatar Jun 17 '24 12:06 MichelMichels

Hi @MichelMichels do you still see this binding failure today? If so, maybe it is worth noting the version of you Visual studio preview you are on before updating it :)

alexachso avatar Jun 17 '24 12:06 alexachso

@alexachso sorry, I saw your comment too late. I've already updated my Visual Studio.

But even after updating, I see following behavior:

  • Non-preview version: no exception
  • Preview version: System.Xaml.XamlObjectWriterException

The demo I'm running uses following xaml in MainWindow:

<Window
    x:Class="MDIX.TestApp.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:local="clr-namespace:MDIX.TestApp"
    xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    Title="MainWindow"
    Width="800"
    Height="450"
    Style="{StaticResource MaterialDesignWindow}"
    mc:Ignorable="d">
    <Grid>
        <materialDesign:DialogHost />
    </Grid>
</Window>

So, the problem seems localized entirely in the preview version.

MichelMichels avatar Jun 17 '24 13:06 MichelMichels

Ok, I reproduced it.

  1. New WPF project (basic)
  2. Installed the MaterialDesignThemes nugget Version 5.0.0.
  3. Added exact same Window as @MichelMichels showed in the comment above
  4. (Forgot I did this! Probably on the 29th of April I enabled the "Enable Just My Code" option in Debugging->General). Enabling this ceased to Throw the exception when I was debugging. Now I disabled it, And sure enough the exception is still there: image image

Here is a zip file with a basic project that does it: MDIXDialogHostTest.zip

So do not forget, in order to have this exception appear, the "System.Xaml.XamlObjectWriterException" option must be enabled in the Exception Setting and also the option "Enable Just My Code" must be disabled.

I also tested with MDIX version 5.0.1-ci662 and it does the same. The version of the VIsual Studio preview I am using now is: Version 17.11.0 Preview 2.0

alexachso avatar Jun 17 '24 14:06 alexachso

@alexachso @MichelMichels Awesome work guys! I will try to reproduce it with this info, and see if I can find some sort of fix that does not reintroduce the binding error.

nicolaihenriksen avatar Jun 17 '24 14:06 nicolaihenriksen

@alexachso @MichelMichels I can now reproduce the issue 👍 Now comes the tough part, finding a valid solution 😄

nicolaihenriksen avatar Jun 18 '24 18:06 nicolaihenriksen

It is strange that it only occurs in the preview version. Could it be that preview version is running a newer runtime?

MichelMichels avatar Jun 18 '24 19:06 MichelMichels

@MichelMichels I am seeing some really weird things happening. I can repro the issue, then I change one small thing and the issue is gone. Then I change it back and the issue is still gone. Sometimes if I do a full clean (´git clean -xdf`) I can then reproduce it again, but not every time. That makes it rather difficult to know when/if you have a working fix for it...

I have seen it in both the preview and the non-preview versions, but not consistently.

nicolaihenriksen avatar Jun 18 '24 19:06 nicolaihenriksen

@MichelMichels As it stands right now (on my PC), simply reverting bfe348fed9334ea36eebe97f0897ef01c96afb15 ensures the exception is not thrown, but it does not re-introduce the binding errors that was the original issue. Very confusing...

nicolaihenriksen avatar Jun 18 '24 19:06 nicolaihenriksen