XAML XMLNS:Local C#

31,035

Solution 1

You must not have spaces in there & if it's the assembly you work in just do not specify assembly.

xmlns:local="clr-namespace:WPFMVVM"

The assembly parameter is for referenced assemblies. Also see the MSDN article on XAML namespaces.

assembly can be omitted if the clr-namespace referenced is being defined within the same assembly as the application code that is referencing the custom classes. Or, an equivalent syntax for this case is to specify assembly=, with no string token following the equals sign.

Solution 2

Not sure if this will help or not, but I had the same problem and managed to fix it on two different projects. I right clicked on the project and clicked build. Once the build was completed, the errors were gone. I'm no xaml expert or anything, but looking at the code, it says xmlns:myns="clr-namespace:somethingorother". If its a clr-namespace, then it must be compiled in order for it to exist.

Solution 3

There is a bug in the xaml builder. On the first attempt to build, the failure causes not all req'd files in debug\obj to be created. On the second attempt to build, more files are created in debug\obj, but not all that are req'd for the xaml. If you build a 3rd time, then all files that are supposed to be in debug\obj are finally created, and the xaml will compile.

Which is why when you clean or rebuild the solution, the problem reappears until you build/build the solution.

This is only a problem when the namespace is in the same assembly as the xaml. If the namespace is in another assembly, and the other assembly exists, then you will get a successful build. If the other assembly does not exist, then obviously the build will fail.

Solution 4

There is known issue. You are working on 64 bit machine. Simply set x86 build configuration at developing process.

Share:
31,035
Darren Young
Author by

Darren Young

Updated on July 05, 2022

Comments

  • Darren Young
    Darren Young almost 2 years

    I am working through an MVVM tutorial, and I have the following code, written in Xaml:

    <Window x:Class="WPFMVVM.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:WPFMVVM; assembly=WPFMVVM"
        Title="MainWindow" Height="388" Width="545">
    

    The xmlns:local line is complaining saying that WPFMVVM assembly is not referenced. Although it is the assembly that I am working in.

    Anybody know why?

    Thanks

  • Darren Young
    Darren Young almost 13 years
    I still get an error saying 'Assembly must be specified for XAML files that are not part of the project? Any ideas? Thanks.
  • H.B.
    H.B. almost 13 years
    Has it stopped working again? (Since you deleted your earlier comment)
  • Darren Young
    Darren Young almost 13 years
    Hi, Yes it has. Was hoping I had deleted it before you had seen it. It's still the same problem. Thanks.
  • H.B.
    H.B. almost 13 years
    Is the file part of your project, if not why not?
  • Darren Young
    Darren Young almost 13 years
    Yeah, it's a single project where the namespace is as above. I need to reference that in Xaml. But it is not working. Looking around the web, lots of people experience this, but I cannot find a solution. Thanks.
  • Admin
    Admin almost 13 years
    MSDN is incorrect. can be omitted is 100% wrong. must be omitted is the correct state of affairs. If you specify the assembly via assembly= you will find that your application will no longer compile if you are referring to the current, rather than a referenced, assembly.
  • Darren Young
    Darren Young almost 13 years
    @Will, I have ommitted the assembly= part and it still will not work.
  • H.B.
    H.B. almost 13 years
    Did you rebuild the solution? What is the build mode of the XAML file? Still dealing with the error which complains about the file not being in the project?
  • Admin
    Admin almost 13 years
    Uh, I just screwed up. I am incorrect... Or at least I am with .NET 4.0. I could swear I remember having an issue with this a long time ago. Might be conflating it with the use of the XmlnsDefinitionAttribute which won't work within the same assembly. Mornings.
  • Darren Young
    Darren Young almost 13 years
    Yeah I rebuilt the solution. Have a look at my question edit. There is some strange behaviour here!
  • H.B.
    H.B. almost 13 years
    @Darren: I would suggest you extract that into a dedicated question, because it is a sufficiently separate issue.
  • H.B.
    H.B. over 12 years
    @Darren Young: Hey, care to accept this answer as this issue should have been resolved?