MC3074 - type does not exist in "clr-namespace ..."

I am having problems referencing classes in xaml from other assemblies.

In the same solution, I have two projects. One of them is called Controls (for storing user controls), and one is called DataBinding (holding transformers / validation rules). In the control, im is trying to refer to a validation rule in xaml:

<Binding.ValidationRules>
   <databind:Validators.FileExistsRule />
</Binding.ValidationRules>

My project refers to a project containing my classes. I added this declaration at the top of my Control.xaml:

xmlns:databind="clr-namespace:GuiParts.DataBinding;assembly=DataBinding"

However, when I compile, I get an error:

The tag 'Validators.FileExistsRule' does not exist in XML namespace 'clr-namespace:GuiParts.DataBinding;assembly=DataBinding'.

The class definitely exists, I can name it in the code behind without problems, but not through haml. If I transfer the class to the same project, again, I have no problem. Here I saw other questions and tried the following:

  • , .Net(4.0, Full Profile)
  • 'assembly' .

. , ?

FileExists:

namespace GuiParts.DataBinding.Validators
{
   /// <summary>
   /// Validates that the file with the specified name exists
   /// </summary>
   public class FileExistsRule : ValidationRule
   {
      public override ValidationResult Validate(object value, CultureInfo cultureInfo)
      {
         ValidationResult res = null;
         res = ( ! File.Exists((string)value))
                  ? new ValidationResult(false, "File does not exist")
                  : new ValidationResult(true, null);
         return res;
      }
   }
}

:

new GuiParts.DataBinding.Validators.FileExistsRule();

, ..

+5
3

:

xmlns:databind="clr-namespace:GuiParts.DataBinding.Validators;assembly=DataBinding"

<Binding.ValidationRules>    
    <databind:FileExistsRule />    
</Binding.ValidationRules> 
+3
  • ?
  • Validators, public?
  • GuiParts.DataBinding?
+2

, , CLR. , XML... XmlnsPrefixAttribute XmlnsDefinitionAttribute s.

:

[assembly: XmlnsPrefix("http://my.xml.namespace.com/", "databind")]
[assembly: XmlnsDefinition("http://my.xml.namespace.com/",
    "GuiParts.DataBinding")]
[assembly: XmlnsDefinition("http://my.xml.namespace.com/",
    "GuiParts.DataBinding.Validators")]

, xmlnames xaml, :

xmlns:databind="http://my.xml.namespace.com/"

, ReSharper, , Visual Studio. xmlns , . , 1:1 xml clr, clr xml.

, , , , , , . , - , xmlns, clr/assembly.


Oh, and the last thing ... if you want to use version control in your xml namespace naming scheme (what you need), don't worry about locking yourself for backward compatibility. You can always use XmlnsCompatibleWithAttributeto make sure that code using the old friendly namespace is not interrupted if you ever update your external assemblies to map to a new xml namespace.

For example, if you had an assembly pointing to the 2012 namespace, then switched to the 2013 namespace because you updated the assembly ...

// Previous Assembly version
//[assembly: XmlnsDefinition("http://schemas.xyzcorp.com/wpf/2012",
//    "Xyz.Databinding")]

[assembly: XmlnsCompatibleWith("http://schemas.xyzcorp.com/wpf/2012",
    "http://schemas.xyzcorp.com/wpf/2013")]
[assembly: XmlnsDefinition("http://schemas.xyzcorp.com/wpf/2013",
     "Xyz.Databinding")]
+2
source

All Articles