Repository navigation
Description
- .NET Core Version: 3.0.100-preview8-013410
- Windows version: 1903
- Does the bug reproduce also in WPF for .NET Framework 4.8?: No
Problem description:
Creating a WinForms DataGridView in WPF XAML throws XamlParseException on .NET Core. This happens for the DataPropertyName property of the DataGridViewTextBoxColumn:
<winForms:DataGridViewTextBoxColumn HeaderText="Firstname"
DataPropertyName="FirstName"/>
Actual behavior:
System.Windows.Markup.XamlParseException
HResult=0x80131501
Message=Invalid metadata for attribute 'System.ComponentModel.TypeConverterAttribute' on 'System.String DataPropertyName'. Expected '1' argument(s) of type 'System.Type'.
Source=PresentationFramework
StackTrace:
at System.Windows.Markup.XamlReader.RewrapException(Exception e, IXamlLineInfo lineInfo, Uri baseUri)
at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
at System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri)
at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
at WinFormsInWpf.MainWindow.InitializeComponent() in C:\Users\thoma\source\repos\WinFormsInWpf.Framework\WinFormsInWpf.Core\MainWindow.xaml:line 1
at WinFormsInWpf.MainWindow..ctor() in C:\Users\thoma\source\repos\WinFormsInWpf.Framework\WinFormsInWpf.Core\MainWindow.xaml.cs:line 9
Inner Exception 1:
XamlSchemaException: Invalid metadata for attribute 'System.ComponentModel.TypeConverterAttribute' on 'System.String DataPropertyName'. Expected '1' argument(s) of type 'System.Type'.
Expected behavior:
It should just work like in .NET Framework
Minimal repro:
I've created a minimal repro solution here that contains a working project that targets .NET Framework and a failing project that targets .NET Core: https://github.com/thomasclaudiushuber/WpfWinFormsXamlParseIssue
Activity
[-]WinForms Interop: Creating WinForms Controls in XAML fails on .NET Core[/-][+]WinForms Interop: XamlParseException on .NET Core[/+]rladuca commentedon Jul 30, 2019
This looks like possibly a WinForms bug. From what I am seeing, we're choking on trying to use
DataMemberFieldConverterwhich is marked on a few WinForms types.This used to live in System.Design. When I look at System.Design in WindowsDesktop, I see it's a facade assembly now, but there is no type forward for
DataMemberFieldConverter. This causes a Type.GetType call to fail here.@zsd4yr @merriemcgaw @Tanya-Solyanik @AdamYoblick Does this ring any bells or am I off base?
merriemcgaw commentedon Jul 30, 2019
@dreddy-work can you take a look? You did a lot of the System.Design stuff on our end. Seems possible to me.
dreddy-work commentedon Jul 30, 2019
DataMemberFieldConverter is not yet ported to core. I will make those changes and get the PR out.
dreddy-work commentedon Jul 30, 2019
@rladuca , DataMemberFieldConverter was internal class and we don't see typeforward even after we port it. How exactly this typeconverter is used in wpf?
weltkante commentedon Jul 30, 2019
@dreddy-work Converters don't need to be public in order to be referenced from attributes, in WinForms you are exporting TypeConverter attributes referencing System.Design by concatenating strings (see the link from @rladuca above).
WPF finds the attribute and wants to resolve the string, but there is not type forwarding in place.
dreddy-work commentedon Jul 30, 2019
Thanks. Will port this and make sure right assembly is referenced. @merriemcgaw can you help move this issue to winforms repo?
rladuca commentedon Jul 30, 2019
@dreddy-work It's probably a good idea to sweep for any TypeConverters you are using, WPF will break on using any WinForm control where there is a similar state to this bug.
merriemcgaw commentedon Jul 30, 2019
I copied the issue to the WinForms runtime repo. Is this something that must be done for 3.0 GA?
rladuca commentedon Jul 30, 2019
@merriemcgaw I think we should make an effort to fix this up. As people start using Winforms controls in WPF they will hit this. I'd suggest doing a code search for these sorts of attibutes and then seeing what the impact will be, I don't know how much is marked up on the WinForms side.
rladuca commentedon Aug 5, 2019
@thomasclaudiushuber This is closed on the WinForms side. Can you grab a nightly build and confirm you're fixed?
thomasclaudiushuber commentedon Aug 11, 2019
@rladuca I tried it with 3.0.100-preview9-013779 and it is fixed!
Thank y'all, @rladuca @merriemcgaw, @dreddy-work and @weltkante . I think this is another important fix for 3.0 GA! I close this issue now.