none
'ResourceDictionary' root element is a generic type and requires a x:Class attribute to support the x:TypeArguments attribute sp RRS feed

  • Question

  •  

    Error : 'ResourceDictionary' root element is a generic type and requires a x:Class attribute to support the x:TypeArguments attribute specified on the root element tag.

     

    Hi,

     

    I get this error when i include some namespaces in my ResourceDictionary to specify a Style for a custom control.
    Can anyone help me?

     

    Thx

    Stardusty

    Friday, September 7, 2007 1:50 PM

Answers

  • In my case this was caused by a user control that inherited from a generic base class using the x:TypeArguments attribute. The problem went away after adding an x:Class="<resource dictionary name>" to the resource dictionary, where the dictionary name can be anything.

    Tuesday, February 12, 2008 10:50 PM
  • Here's a resource dictionary where I pull in 2 namespaces and use them.  Could you post your code?


    Code Snippet

    e done some of that stuff before and might be able to help.  Could you post your code?  Here's a resource dictionary where I pull in an external library:

    <ResourceDictionary
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:valueConverters="clr-namespace:JBSi.TitleIVE.Windows.Controls.ValueConverters"
        xmlns:datePicker="clr-namespace:Microsoft.Samples.KMoore.WPFSamples.DateControls;assembly=WPFSamplesLib"
        >
        <valueConverters:InvertBooleanConverter x:Key="InvertBooleanConverter" />
        <Style TargetType="{x:Type datePicker:DatePicker}">
            <Setter Property="CanEdit" Value="True" />
        </Style>
    </ResourceDictionary>

    Friday, September 7, 2007 1:56 PM
  • Hello,

     

    We've had the experience that if a clr-namespace: mapping is used when there is an existing URI based mapping, we get this error.  The work-around seems to be to use the URI namespace.

     

    Best,

     

    --

    Nathan Allan

    Friday, January 11, 2008 8:24 PM

All replies

  • Here's a resource dictionary where I pull in 2 namespaces and use them.  Could you post your code?


    Code Snippet

    e done some of that stuff before and might be able to help.  Could you post your code?  Here's a resource dictionary where I pull in an external library:

    <ResourceDictionary
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:valueConverters="clr-namespace:JBSi.TitleIVE.Windows.Controls.ValueConverters"
        xmlns:datePicker="clr-namespace:Microsoft.Samples.KMoore.WPFSamples.DateControls;assembly=WPFSamplesLib"
        >
        <valueConverters:InvertBooleanConverter x:Key="InvertBooleanConverter" />
        <Style TargetType="{x:Type datePicker:DatePicker}">
            <Setter Property="CanEdit" Value="True" />
        </Style>
    </ResourceDictionary>

    Friday, September 7, 2007 1:56 PM
  • Hello, why do you want to use x:TypeArguments on a ResourceDictionary? This is not allowed. x:TypeArguments should only be used on generic root types such as PageFunction, and you must have a code behind class. Please have a look at http://msdn2.microsoft.com/en-us/library/ms750476.aspx.

     

    Monday, September 10, 2007 5:02 AM
  • Hi,

     

    That's the whole point. I don't want to use x:TypeArguments on a ResourceDictionary but the compiler says it needs it.

    And i don't know why.

     

    This code give no error:

    <ResourceDictionary

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    xmlns:sys="clr-namespaceTongue Tiedystem;assembly=mscorlib">  

    </ResourceDictionary>

     

    And by adding 3 namespaces it gives that weard error:

    <ResourceDictionary

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    xmlns:controls="clr-namespace:MyTime.View.Controls"

    xmlns:converters="clr-namespace:MyTime.View.Converters"

    xmlns:validationrules="clr-namespace:MyTime.View.ValidationRules"

    xmlns:sys="clr-namespaceTongue Tiedystem;assembly=mscorlib">  

    </ResourceDictionary>

    Monday, September 10, 2007 1:26 PM
  • Did you ever get an answer? Please reply if you did. Thanks!

    Thursday, September 13, 2007 4:54 PM
  • I have the same problem here. I'm using PageFunction<bool> and it won't compile the xaml code.

    I have to remove all PageFunction<bool> derived classes from the project to compile the xaml then add the PageFunctions to the project and then it works. Quite awkward :-(

    Tuesday, December 11, 2007 8:52 AM
  • Hello,

     

    We've had the experience that if a clr-namespace: mapping is used when there is an existing URI based mapping, we get this error.  The work-around seems to be to use the URI namespace.

     

    Best,

     

    --

    Nathan Allan

    Friday, January 11, 2008 8:24 PM
  • In my case this was caused by a user control that inherited from a generic base class using the x:TypeArguments attribute. The problem went away after adding an x:Class="<resource dictionary name>" to the resource dictionary, where the dictionary name can be anything.

    Tuesday, February 12, 2008 10:50 PM
  • Bizarre bug...

    Taco's workaround seems to Thanks.
    • Edited by Rei Miyasaka Sunday, June 29, 2008 1:49 AM Wrong person
    Sunday, June 29, 2008 1:48 AM
  • Diddo for me. I have a usercontrol in the same assembly that uses generics.

    <ResourceDictionary  
        x:Class="ArbitraryNameToEliminateBogusGenericsError" 
     
    Saturday, September 13, 2008 2:15 AM
  • In my case this was caused by a user control that inherited from a generic base class using the x:TypeArguments attribute. The problem went away after adding an x:Class="<resource dictionary name>" to the resource dictionary, where the dictionary name can be anything.


    Solved it for us too. Thanks. Hope it is solved in 4.0 though.
    Take a look at my blog: http://paul.sinnema.ch
    Friday, October 23, 2009 8:10 AM
  • Thanks Taco, that was the answer!

    Friday, April 16, 2010 2:42 AM
  • Thanks, Taco! This worked for me. I'm using 4.0, so apparently it still isn't fixed.
    Friday, May 21, 2010 6:39 PM
  • Fixed it for me.  Strange this is still required in 2011.
    Thursday, June 23, 2011 1:58 AM
  • Thanks... This is still required in 2012

    Take a look at WPF FlashMessage

    Wednesday, September 26, 2012 12:32 PM
  • And in 2013...
    Friday, July 19, 2013 2:38 PM
  • And in 2014...
    Thursday, April 10, 2014 3:03 PM
  • And in 2015, as well...

    I created a corresponding Connect issue, hoping the problem will be fixed eventually. Feel free to upvote it.

    Saturday, February 21, 2015 2:37 PM