Design Time Error (XamlObjectWriterException: Collection property 'System.Windows.Controls.TextBox'.'Triggers' is null)
smittynusmc opened this issue · 17 comments
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:Interaction.Triggers x:Uid="SSTriggers">
<i:EventTrigger EventName="LostFocus" >
<i:InvokeCommandAction Command="{Binding ElementName=SSLItemControl,
Path=DataContext.saveParamterizedCommand}" CommandParameter="{Binding}"/>
</i:EventTrigger>
<i:KeyTrigger Key="Enter">
<i:InvokeCommandAction Command="{Binding ElementName=SSLItemControl,
Path=DataContext.saveParamterizedCommand}" CommandParameter="{Binding}"/>
</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.
Desktop (please complete the following information):
- Version with bug:
Windows 10
Visual Studio Community 2017
Microsoft.Xaml.Behaviors.Wpf 1.1.19
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:
'''
'''
TO
'''
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.
Thank you for submitting your issue. However, if you do not provide the required working reproduction sample, this issue will be closed.
I do not what is a reproduction sample is. What do need?
A running application that can replicate the issue you are having that we can use to step through and debug.
I can't give you a reproduction sample for security reasons.
You can't create a small stand-alone application that reproduces this issue?
I can try. I'm going to need a day or two to make a smaller standalone.
either provide a link to the github repo, or just upload the zip
Here is reproduction example:
(Same here, kind of a pain in Design: Blend of VS)
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:
- Create a WPF full framework application.
- Add the missing "Behavior" package that Blend proposes to add (through NuGet).
- Add one of your custom behavior.
Until now, Blend designer and VS designer are working.
Then:
Change or create a solution platform x64 and move to it
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
@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.
Thanks for the tips but does not seems to work better :(
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.<>c__DisplayClass88_0.b__0()
at Microsoft.VisualStudio.DesignTools.Markup.MarkupDocument.DisposeAwareParse(Action parseAction)
at Microsoft.VisualStudio.DesignTools.Markup.MarkupDocument.EnsureParsed(CancellationToken cancelToken)
at Microsoft.VisualStudio.DesignTools.SurfaceDesigner.DesignerService.<>c__DisplayClass27_1.b__0()
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 ?
@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?
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.
@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.
Thanks for all theses tips.
For now it reveal some other problems that "seems" to be on the code (but i have a doubt...)
- Could not load file or assembly 'XXX.MVVM, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.
- Cannot find resource named 'BooleanToVisibilityConverter'. Resource names are case sensitive.
- Severity Code Description Project File Line Suppression State
- Cannot set unknown member '{clr-namespace:Microsoft.Xaml.Behaviors;assembly=Microsoft.Xaml.Behaviors}Interaction.Triggers'.' Line number '6' and line position '22'.
- {DependencyProperty.UnsetValue}' is not a valid value for the 'System.Windows.Controls.Control.Template' property on a Setter.
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 :/)
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.