microsoft / XamlBehaviorsWpf

Home for WPF XAML Behaviors on GitHub.
MIT License
852 stars 140 forks source link

Design Time Error (XamlObjectWriterException: Collection property 'System.Windows.Controls.TextBox'.'Triggers' is null) #70

Closed smittynusmc closed 1 year ago

smittynusmc commented 4 years ago

Describe the bug I am getting a design time error using Interaction.Triggers in a data grid (see code at bottom). When the program is run it doesn't have any issues. I just can't see the User Control window in Visual Studio (see screenshot below).

To Reproduce Steps to reproduce the behavior: Error occurs at Design Time but when I remove or comment out the triggers the error goes away. '''XAML </i:EventTrigger> </i:KeyTrigger> </i:Interaction.Triggers> ''' Expected behavior At design time I get the following error: XamlObjectWriterException: Collection property 'System.Windows.Controls.TextBox'.'Triggers' is null.

Stack Trace at System.Xaml.XamlObjectWriter.WriteGetObject() at System.Xaml.XamlWriter.WriteNode(XamlReader reader) at System.Windows.FrameworkTemplate.LoadTemplateXaml(XamlReader templateReader, XamlObjectWriter currentWriter)

InnerException:None

Screenshots If applicable, add screenshots to help explain your problem. Below is a screenshot of my preview window in Visual Studio. image

Desktop (please complete the following information):

I followed the steps on this website to setup triggers: https://devblogs.microsoft.com/dotnet/open-sourcing-xaml-behaviors-for-wpf/

**Here is a reproduction example:

https://github.com/smittynusmc/Trigger_Error_Sample.git**

Update:

The error goes away when I change the debug platform from x64 to Any CPU.

Update:

When renaming variables and removing code to get ready for git. When I changed this code: ''' <ItemsControl x:Name="Name here" ItemsSource="{Binding OriginalList, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" > Capture

'''

TO

''' <ItemsControl x:Name="Name here" ItemsSource="{Binding List, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" > Capture

'''

The error went away (variable names may be different). Basically when I changed the binding names to anything other than the name in View Model the error was gone.

Also, any ItemSource or DataContext in which I change the name of the Binding the error goes away

The error comes back after running the program once.

brianlagunas commented 4 years ago

Thank you for submitting your issue. However, if you do not provide the required working reproduction sample, this issue will be closed.

smittynusmc commented 4 years ago

I do not what is a reproduction sample is. What do need?

brianlagunas commented 4 years ago

A running application that can replicate the issue you are having that we can use to step through and debug.

smittynusmc commented 4 years ago

I can't give you a reproduction sample for security reasons.

brianlagunas commented 4 years ago

You can't create a small stand-alone application that reproduces this issue?

smittynusmc commented 4 years ago

I can try. I'm going to need a day or two to make a smaller standalone.

brianlagunas commented 4 years ago

either provide a link to the github repo, or just upload the zip

smittynusmc commented 4 years ago

Here is reproduction example:

https://github.com/smittynusmc/Trigger_Error_Sample.git

alphamax commented 4 years ago

(Same here, kind of a pain in Design: Blend of VS)

alphamax commented 4 years ago

Hi,

I have more info for you. Maybe it should help! I have prepared a small solution that you can see below.

My step to reproduce:

Until now, Blend designer and VS designer are working.

Then:

Change or create a solution platform x64 and move to it image

At this precise moment, and after one build, all designers are broken :/

Why am I using x64? Because our product is shipped as x64 program AND because I am embedding CEFSharp (Chromium engine) that only run/compile as x64. That's why I have this fixed target.

Any help is welcome!

Thanks

WpfApp2.zip

mgoertz-msft commented 4 years ago

@alphamax The full framework designer in Visual Studio uses an older architecture that does not fully support x64. If you have any of the 16.7 Previews installed (it safely installs side-by-side with the release channel version of VS) then you could try a preview of the new designer architecture for .NET Framework, which should fully support x64. From the 16.7 Preview Release Notes:

To get started, go to Options > Preview Features, select “New WPF XAML Designer for .NET Framework” and restart Visual Studio. This feature is only available in the Preview channel for early testing; its final release details have not yet been determined. We encourage all WPF .NET Framework customers to give this designer a try and report any issues you encounter through the VS Feedback Hub.

alphamax commented 4 years ago

Thanks for the tips but does not seems to work better :( image

Full stack : System.ArgumentNullException Value cannot be null. Parameter name: valueTypeId at Microsoft.VisualStudio.DesignTools.Markup.Metadata.DesignTimePropertyId..ctor(String propertyName, ITypeId valueTypeId, String defaultValue, ITypeId targetTypeId, DesignerSerializationVisibility serializationVisibility, Boolean isDocumentOnly, Boolean isDynamicDesignTime) at Microsoft.VisualStudio.DesignTools.Xaml.LanguageService.Platform.Common.ManagedXamlDesignTimeProperties.RegisterDynamicDesignTimeProperty(IProperty runtimeProperty) at Microsoft.VisualStudio.DesignTools.Markup.Metadata.XamlDesignTimeProperties.GetDynamicDesignTimeProperty(IProperty runtimeProperty) at Microsoft.VisualStudio.DesignTools.Xaml.LanguageService.Metadata.ManagedPlatformMetadata.GetDynamicDesignTimeProperty(IProperty runtimeProperty) at Microsoft.VisualStudio.DesignTools.Markup.XamlTypeHelper.GetPropertyKey(XamlParserContext parserContext, ITextLocation lineInformation, XmlNamespace xmlNamespace, String typeAndPropertyName, XmlNamespace targetTypeNamespace, IType targetTypeId, MemberType memberTypes, MemberType defaultType, Boolean allowProtectedPropertiesOnTargetType, Boolean isDynamicDesignTimeProperty) at Microsoft.VisualStudio.DesignTools.Markup.XamlParser.GetPropertyKey(XamlParserContext parserContext, XmlElementReference xmlElementReference, XmlElement xmlElement, XmlAttribute attribute, IType targetType, Boolean allowProtectedPropertiesOnTargetType, IProperty& propertyKey) at Microsoft.VisualStudio.DesignTools.Markup.XamlParser.AddPropertiesAndChildren(XamlParserContext parserContext, DocumentCompositeNodeReference nodeReference, XmlElementReference xmlElementReference, XmlElement xmlElement, Predicate`1 propertyFilter) at Microsoft.VisualStudio.DesignTools.Markup.XamlParser.AddPropertiesAndChildren(XamlParserContext parserContext, DocumentCompositeNodeReference nodeReference, XmlElementReference xmlElementReference, XmlElement xmlElement) at Microsoft.VisualStudio.DesignTools.Markup.XamlParser.ParseCompositeElement(XamlParserContext parserContext, IDocumentNodeReference nodeReference, IType typeId, XmlElementReference xmlElementReference, XmlElement xmlElement) at Microsoft.VisualStudio.DesignTools.Markup.XamlParser.ParseElementContent(XamlParserContext parserContext, IDocumentNodeReference nodeReference, IType typeId, XmlElementReference xmlElementReference, XmlElement xmlElement) at Microsoft.VisualStudio.DesignTools.Markup.XamlParser.ParseRootElement(XamlParserContext parserContext, XmlElementReference xmlElementReference, XmlElement xmlElement) at Microsoft.VisualStudio.DesignTools.Markup.XamlParser.Parse(XamlParserContext parserContext, XmlDocumentReference xmlDocumentReference, XmlDocument xmlDocument) at Microsoft.VisualStudio.DesignTools.Markup.XamlParser.ParseInternal(XamlParserContext parserContext) at Microsoft.VisualStudio.DesignTools.Markup.XamlLanguageService.ParseDocument(CancellationToken cancelToken) at Microsoft.VisualStudio.DesignTools.Markup.MarkupDocument.ParseInternal(CancellationToken cancelToken) at Microsoft.VisualStudio.DesignTools.Markup.MarkupDocument.<>cDisplayClass88_0.b0() at Microsoft.VisualStudio.DesignTools.Markup.MarkupDocument.DisposeAwareParse(Action parseAction) at Microsoft.VisualStudio.DesignTools.Markup.MarkupDocument.EnsureParsed(CancellationToken cancelToken) at Microsoft.VisualStudio.DesignTools.SurfaceDesigner.DesignerService.<>cDisplayClass27_1.b0() at Microsoft.VisualStudio.DesignTools.Utility.ProtectionZone.TrueProtectionZone.Execute(Action action) --- End of stack trace from previous location where exception was thrown --- at Microsoft.VisualStudio.Telemetry.WindowsErrorReporting.WatsonReport.GetClrWatsonExceptionInfo(Exception exceptionObject)

Do you have any idea ?

DVaughan commented 4 years ago

@alphamax I tested the project in WpfApp2.zip on a couple different machines; running VS 16.7 Preview 1, VS 16.7 Preview 4. The designer was broken until I enabled the new designer as @mgoertz-msft suggested.

Visual Studio needs a restart after you enable the new designer. I assume you did that, but I thought I'd mention it anyway. Does the WpfApp2.zip cause the same issue? Is that what you're using to repro?

alphamax commented 4 years ago

You are right, the "minimal" demo application is working in this configuration, not the "product" one that is much more complex, and that produces the exception below... :'(

Thanks for your help, by the way.

mgoertz-msft commented 4 years ago

@alphamax The ArgumentNullException in DesignTimePropertyId..ctor just got fixed the other day and will be part of 16.7 Preview 5. In the meantime you could try and turn off the new "Expanded Design-time Data Support" Preview Feature, which hopefully avoids that problematic code path. Please let us know how that works for you.

alphamax commented 4 years ago

Thanks for all theses tips. For now it reveal some other problems that "seems" to be on the code (but i have a doubt...)

First i'll try to do is to "find" the assembly that does not seem to be loaded (even if at runtime i have no problem :/)

brianlagunas commented 1 year ago

It has been a few years, and this thread has gone stale. I recently tried to reproduce it using VS2022 and was not able to. Therefore, I am closing this issue. If this is still an issue, please let us know and we can reopen the thread.