Skip to content

WinForms Interop: XamlParseException on .NET Core #1366

Closed

Description

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

  1. changed the title [-]WinForms Interop: Creating WinForms Controls in XAML fails on .NET Core[/-] [+]WinForms Interop: XamlParseException on .NET Core[/+] on Jul 24, 2019
  2. added
    Bug
    regression
    on Jul 26, 2019
  3. added this to the 3.0 milestone on Jul 26, 2019
  4. added
    needs-updated-estimate
    on Jul 29, 2019
  5. rladuca commented on Jul 30, 2019

    @rladuca
    Member

    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?

  6. merriemcgaw commented on Jul 30, 2019

    @merriemcgaw

    @dreddy-work can you take a look? You did a lot of the System.Design stuff on our end. Seems possible to me.

  7. removed
    needs-updated-estimate
    on Jul 30, 2019
  8. dreddy-work commented on Jul 30, 2019

    @dreddy-work
    Member

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

  9. dreddy-work commented on Jul 30, 2019

    @dreddy-work
    Member

    @rladuca , DataMemberFieldConverter was internal class and we don't see typeforward even after we port it. How exactly this typeconverter is used in wpf?

  10. weltkante commented on Jul 30, 2019

    @weltkante

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

  11. dreddy-work commented on Jul 30, 2019

    @dreddy-work
    Member

    Thanks. Will port this and make sure right assembly is referenced. @merriemcgaw can you help move this issue to winforms repo?

  12. rladuca commented on Jul 30, 2019

    @rladuca
    Member

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

  13. merriemcgaw commented on Jul 30, 2019

    @merriemcgaw

    I copied the issue to the WinForms runtime repo. Is this something that must be done for 3.0 GA?

  14. rladuca commented on Jul 30, 2019

    @rladuca
    Member

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

  15. added
    issue-type-tracking-external
    and removed
    Bug
    regression
    on Jul 30, 2019
  16. rladuca commented on Aug 5, 2019

    @rladuca
    Member

    @thomasclaudiushuber This is closed on the WinForms side. Can you grab a nightly build and confirm you're fixed?

  17. added
    📭 waiting-author-feedback
    on Aug 8, 2019
  18. thomasclaudiushuber commented on Aug 11, 2019

    @thomasclaudiushuber
    ContributorAuthor

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

  19. removed
    📭 waiting-author-feedback
    on Aug 22, 2019
  20. ghost locked as resolved and limited conversation to collaborators on Apr 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

issue-type-tracking-external

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions