0

While trying to add a ressource dictionary into the MergedDictionary of the application, I encounter a parsing error.

System.Windows.Markup.XamlParseException occurred
  HResult=-2146233087
  Message='Cannot create unknown type '{clr-namespace:Common.UserControls}ButtonVisibilityConverter'.' Line number '4' and line position '6'.
  Source=PresentationFramework
  LineNumber=4
  LinePosition=6
  StackTrace:
       at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
       at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, Boolean skipJournaledProperties, Uri baseUri)
       at System.Windows.Markup.XamlReader.Load(XamlReader xamlReader, ParserContext parserContext)
       at System.Windows.Markup.XamlReader.Load(XmlReader reader, ParserContext parserContext, XamlParseMode parseMode)
       at System.Windows.Markup.XamlReader.Load(Stream stream, ParserContext parserContext)
       at MS.Internal.AppModel.AppModelKnownContentFactory.XamlConverter(Stream stream, Uri baseUri, Boolean canUseTopLevelBrowser, Boolean sandboxExternalContent, Boolean allowAsync, Boolean isJournalNavigation, XamlReader& asyncObjectConverter)
       at MS.Internal.AppModel.MimeObjectFactory.GetObjectAndCloseStream(Stream s, ContentType contentType, Uri baseUri, Boolean canUseTopLevelBrowser, Boolean sandboxExternalContent, Boolean allowAsync, Boolean isJournalNavigation, XamlReader& asyncObjectConverter)
       at System.Windows.ResourceDictionary.set_Source(Uri value)
       at Common.Infrastructure.Bootstrapper.InitializeGlobalRessources() in e:\xxxxx\Common\Infrastructure\Bootstrapper.cs:line 113
  InnerException: System.Xaml.XamlObjectWriterException
       HResult=-2146233088
       Message='Cannot create unknown type '{clr-namespace:Common.UserControls}ButtonVisibilityConverter'.' Line number '4' and line position '6'.
       Source=System.Xaml
       LineNumber=4
       LinePosition=6
       StackTrace:
            at System.Xaml.XamlObjectWriter.WriteStartObject(XamlType xamlType)
            at System.Xaml.XamlWriter.WriteNode(XamlReader reader)
            at System.Windows.Markup.WpfXamlLoader.TransformNodes(XamlReader xamlReader, XamlObjectWriter xamlWriter, Boolean onlyLoadOneNode, Boolean skipJournaledProperties, Boolean shouldPassLineNumberInfo, IXamlLineInfo xamlLineInfo, IXamlLineInfoConsumer xamlLineInfoConsumer, XamlContextStack`1 stack, IStyleConnector styleConnector)
            at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
       InnerException: 

Which seems to point to an error with the declaration of my converter, but I can't figure out why.

Is here my loaded resource

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:local="clr-namespace:Common.UserControls">
    <local:ButtonVisibilityConverter x:Key="PageButtonVisibilityConverter"/>
    ....
</ResourceDictionary>

The converter declaration:

namespace Common.UserControls
{
    public class ButtonVisibilityConverter : IMultiValueConverter{
        ...
    }
}

The code that is loading the dictionary: ResourceDictionary dictionary = new ResourceDictionary {Source = new Uri("/Common;Component/UserControls/Generic.xaml", UriKind.RelativeOrAbsolute)};

The converter and the resource are in the same folder. The code loading the resource is in the same project.

I've no idea what is going wrong, because yesterday everything was working, so I'm not sure if I introduced a change by error or if there is something else to check?

I already cleared my whole output directory.

Also, the namespace declaration for the converter has been created directly by Resharper and it is rarely wrong.

Thank you for the help

J4N
  • 19,480
  • 39
  • 187
  • 340
  • Take a look here: http://stackoverflow.com/questions/6156723/error-cannot-create-unknown-type-clr-namespacenamespace-propertiessettings – Orace Sep 18 '15 at 08:56
  • Changing the converter back to Page is working :) I had set it to ressource because I was having difficulties to have my method finding the XAML so I tried several things. Thank you very much – J4N Sep 18 '15 at 08:59
  • But at a point, it worked :/. Not sure what I should do with this question, close it? Wait for you to answer it? – J4N Sep 18 '15 at 08:59
  • Close it, if the other solution work, it's a duplicate. If you have time, maybe you can edit the other question to make it more "general case" but I'm not sure it's needed I find it quickly by googling "Cannot create unknown type Common.UserControls" (as you should have do before ask your question ;)) – Orace Sep 18 '15 at 09:07

0 Answers0