Type reference cannot find public type named

前端 未结 5 1430
温柔的废话
温柔的废话 2021-01-07 20:24

I am getting error like \"Type reference cannot find public type named \'Sign\'\" in xaml. how can i resolve it. the Sign class is in the same assembly.

<         


        
相关标签:
5条回答
  • 2021-01-07 20:38

    If the type resides in the same assembly as the XAML you are modifying, omit the assembly segment of the clr-namespace when you import the namespace.

    DO

    xmlns:local="clr-namespace:NamespaceContainingSignClass"
    

    DO NOT

    xmlns:local="clr-namespace:NamespaceContainingSignClass;assembly=AssemblyContainingSignClassAndXAML"
    
    0 讨论(0)
  • 2021-01-07 20:47
    1. Go through and check all of the answers to this question - I'm sure one of them is right, but I don't know which one worked for me.
    2. Save your project, close Visual Studio, re-open Visual Studio.
    3. Voila, it now magically works, despite not changing anything.
    4. Swear at Microsoft under your breath, and carry on with your life...
    0 讨论(0)
  • 2021-01-07 20:48
    1. Check if the root tag of the xaml file has the namespace with class Sign mapped to local alias: xmlns:local="clr-namespace:NamespaceContainingSignClass"
    2. Check whether class Sign is marked public
    3. Check whether class Sign has parameterless constructor
    0 讨论(0)
  • 2021-01-07 20:55

    For those in my boat who weren't helped by the top 1,00 results for this error on Google....in my case it was the precise opposite of the advice from smelch: i had to ADD the assembly info on the end of my xmlns declaration. Likely because of my particular circumstances, i guess - my datatemplate was in a stand-alone resourcedictionary xaml file. Not sure. I just know it didn't work until i added the assembly info, so for those floundering out there give that a whack and see if it works. i'm not inclined to dive into why, it just did.

    0 讨论(0)
  • 2021-01-07 20:56

    I just discovered another issue, that may cause this problem. It is allowed to use dots in project names, e.g.

    FancyTrainsimTools.Desktop
    

    is a valid project name. If you use folders in the project, you may get constructs like this:

    FancyTrainsimTools.Desktop.Logic
    

    If you define data templates referencing items in this folder, this results in error messages. I also used a hierarchical datatemplate, but this gives slightly different messages.

    The workaround:

    Rename your project by removing the dot:

    FancyTrainsimToolsDesktop
    

    Edit: I try to reproduce the issue again, in order to report a bug, but now it all works.... So mystery not yet solved and not clear what to do to create w ork around....

    0 讨论(0)
提交回复
热议问题