Can't create xmlns reference to other project in XAML
Asked Answered
A

5

8

I have a WPF project defined like this:

MyApp.sln
  MyAppWPF
  MyApp.Domain

In one of my xaml files in the MyAppWPF project I'm trying to reference a class defined in MyApp.Domain project. I have a project reference in MyAppWPF to MyApp.Domain. I am trying to create the reference like this:

<Window x:Class="MyAppWPF.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:MyApp.Domain;assembly=MyApp.Domain"
    Title="Window1" Height="305" Width="485">
    <Window.Resources>
       <local:MyClass x:Key="mine" />
    </Window.Resources>
</Window>

I get an error saying the assembly cannot be found, however I can create an instance of the class I want to reference in the code behind, so I know I've got it referenced correctly.

How do I do this? Do I need a strong name, or reference the dll directly instead of using a project reference?

Atrip answered 19/10, 2008 at 18:6 Comment(2)
Hi Ted - Did you ever resolve this problem?Gader
No, but I haven't really looked at it much since I asked the question. It was just an app to learn WPF on.Atrip
E
6

If it helps anyone, I was able to solve my problems by simply adding ;assembly= at the end of the namespace declaration that referred to the containing project itself. For example:

xmlns:local="clr-namespace:YourProjectNameSpace;assembly=" 
Eccrinology answered 12/8, 2015 at 16:39 Comment(0)
R
3

Check if

  1. the fully qualified name for MyClass is MyApp.Domain.MyClass
  2. MyClass has a default public constructor (with no parameters) so that XAML can instantiate it.
Risteau answered 19/10, 2008 at 18:13 Comment(0)
L
2

Could be of any help?

Visual Studio 2008 (RTM) WPF Designer Could Not Load Assembly or Dependency

I assume you are using Visual Studio 2008. If you are using Visual Studio 2005, this is a known issue in the XAML designer code-named "Cider", which is included in the "Visual Studio 2005 Extensions for WPF and WCF".

Larios answered 20/10, 2008 at 12:31 Comment(0)
J
2

You only need to put the assembly=MyApp.Domain if you're compiling loose XAML dynamically.

If you're just building your XAML once initially, exclude that token and just say xmlns:local="clr-namespace:MyApp.Domain" instead.

Joyance answered 26/2, 2015 at 23:10 Comment(0)
S
1

If the XAML is not loose (is compiled within an assembly (DLL/EXE)
make sure that assembly has a reference to the assembly you are looking for
(right click on the project --> add reference ...).

If the XAML is loose, make sure the assembly it is looking for is copied to the same directory the exe is ran from.

Sedulous answered 7/2, 2009 at 13:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.