Unanswered Accessing code behind objects

  • Wednesday, November 08, 2006 9:02 PM
     
     

    Hi, this is the XAML:

    <Window x:Class="MyCompany.MyProductSpace.MyWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:my="clr-namespace:MyCompany.MyProductSpace"
    >

    <Window.Resources>
     <
    my:MyConverter x:Key="myConverter" />
    </Window.Resources>

    This is the code behind:

    namespace MyCompany.MyProductSpace
    {
     
    [ValueConversion(typeof(String), typeof(String))]
     
    public class MyConverter : IValueConverter
     
    { ... }
    }

    And this is the error:

    error 4 Assembly '' was not found. The 'clr-namespace' URI refers to an assembly that is not referenced by the project.

    What's wrong and how to solve it?

    Thanks,
       Jan

All Replies

  • Thursday, November 09, 2006 1:55 AM
     
     
    This works for me, but it does break Cider (WPF designer in visual studio).  It seems that, currently, once you implement the custom namespace, you have to code all of your XAML by hand.  It still shows errors, but will compile.

    I am still running on RC1, though, and it may be better in RTM.
  • Thursday, November 09, 2006 2:09 AM
    Moderator
     
     
    works fine on my machine
  • Thursday, November 09, 2006 5:26 PM
     
     
    I am running RC2 and I cannot compile, because the MyConverter type cannot be found (not so suprising, if it cannot resolve the assembly...)
  • Thursday, November 09, 2006 8:25 PM
     
     
    If this is a different assembly that your current one, then you also need to add it to your project references, otherwise you will also receive that error.
  • Friday, November 10, 2006 9:04 AM
     
     
    Hi. How could it be a different assembly when it is in the codebehind of the xaml? If the custom namespace makes the parser unable to find it, which would be rather a bug I think, what is the syntax to specify the full assembly name? (of the current one?
  • Friday, November 10, 2006 10:26 AM
    Moderator
     
     

    Can you try moving the class and custom namespace to its own file, may be nested class issue

    you can say xmlns:local="clr-namespace:XXX;assembly=XXX"

  • Friday, November 10, 2006 11:17 AM
     
     

    Yeah, the solution would be to have its own dll for converters, but... I'm not sure that this is so cool.. ;-)

    Any ideas of trying to resolve assembly ''? Is this okay or bad? Is the current assembly always referenced as empty string when resolving or reflecting?

    You know, I'm trying to find out whether the error is in the resolving (empty assembly is valid) or in the xaml or translation (there should be placed my current assembly name).

    Thanks

  • Friday, November 10, 2006 1:04 PM
    Moderator
     
     
    I was saying in the same project create another class file and move your class from window code
  • Friday, November 10, 2006 1:36 PM
     
     

    Okay,

     thank you for that tip. Good is, that this found compilation error in the converter class. The bad thing is, that such compilation errors are not generated when the class is in the codebehind file.

    Now, two things: Whether it is in separate class file or codebehind it behaves the same: The assembly is not resolved, but the project can be now built and run and it works. However, the designer in VisualStudio stops working because of this error, so you have to type XAML and don't see anything until runtime.

    Any workaround?