Skip to content

WinForms Interop: XamlParseException on .NET Core #1542

Closed

Description

@merriemcgaw

@thomasclaudiushuber commented on Wed Jul 24 2019

  • .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


@rladuca commented on Mon Jul 29 2019

This looks like possibly a WinForms bug. From what I am seeing, we're choking on trying to use DataMemberFieldConverter which 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 commented on Mon Jul 29 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 commented on Mon Jul 29 2019

DataMemberFieldConverter is not yet ported to core. I will make those changes and get the PR out.


@dreddy-work commented on Tue 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 commented on Tue 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 commented on Tue 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 commented on Tue 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.

Activity

  1. rladuca commented on Jul 30, 2019

    @rladuca
    Member

    I did a quick search and just the first hit LinkAreaConverter seems to not have an implementation. This makes me think that there are definitely other TypeConverters that are not implemented. If WPF ever attempts to instantiate these, it will crash in the same fashion.

  2. added this to the 3.0.0-Preview9 milestone on Jul 30, 2019
  3. added
    🪲 bug
    tenet-compatibility
    on Jul 30, 2019
  4. ghost added
    🚧 work in progress
    on Jul 31, 2019
  5. dreddy-work commented on Jul 31, 2019

    @dreddy-work
    Member

    I did a quick search and just the first hit LinkAreaConverter seems to not have an implementation. This makes me think that there are definitely other TypeConverters that are not implemented. If WPF ever attempts to instantiate these, it will crash in the same fashion.

    That is true. Types in "System.Design" assembly are ported only on need basis or based on their usage. Will have to create a separate issue for them and fix them in 3.1 if they are not blocking any customer scenarios immediately.

  6. weltkante commented on Jul 31, 2019

    @weltkante
    Contributor

    LinkAreaConverter has a typeof and isn't constructed by string, so it wouldn't compile if it weren't implemented. It is implemented inside LinkArea.cs, the github search just returns one match per file so its not visible on the search page.

    Also it can't be referencing the wrong assembly since the typeof will use the assembly where the compiler actually sees it. You need to search for TypeConverter attributes which are constructed with strings, and most likely AssemblyRef.SystemDesign

  7. rladuca commented on Jul 31, 2019

    @rladuca
    Member

    LinkAreaConverter has a typeof and isn't constructed by string, so it wouldn't compile if it weren't implemented. It is implemented inside LinkArea.cs, the github search just returns one match per file so its not visible on the search page.

    Also it can't be referencing the wrong assembly since the typeof will use the assembly where the compiler actually sees it. You need to search for TypeConverter attributes which are constructed with strings, and most likely AssemblyRef.SystemDesign

    Doh, you're right. I'll see myself out : - ).

  8. ghost removed
    🚧 work in progress
    on Aug 5, 2019
  9. John-Qiao commented on Aug 27, 2019

    @John-Qiao
    Contributor

    Verified in .NET Core 3.0.100-preview9-014004, issue has been fixed.

    image

  10. RussKie commented on Aug 27, 2019

    @RussKie
    Contributor

    Thank you!

  11. ghost locked as resolved and limited conversation to collaborators on Feb 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

🪲 bugtenet-compatibility

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions