This project has moved and is read-only. For the latest updates, please go here.

clr-namespace Problem


I'm following the WPF example of the BasketballRoster in chapter 16.

In the LeagueWindow.xaml I have an error that says "Undefined CLR namespace. The 'clr-namespace' URI refers to a namespace 'BasketballRoster.ViewModel' that is not included in the assembly.' Of course, that error cascades to cause the error that the type viewmodel:LeagueViewModel does not exist.

I have checked all of the code and compared it to the code provided on the web site. They are identical. I have unloaded and reloaded the project and I have also reentered the clr-namespace line a couple of times using the IDE intelisense to help make sure everything is right.

I attached two screen shots of the offending problem.

file attachments


andrewstellman wrote Nov 21, 2014 at 4:16 PM

That's odd. Try doing this:
  1. Create a new WPF project called BasketballRoster (you may need to create it in a new folder so you don't overwrite your existing one)
  2. Create a ViewModel folder
  3. Create an empty LeagueViewModel.cs class in the ViewModel folder
  4. Rebuild the project
  5. Add xmlns:viewmodel="clr-namespace:BasketballRoster.ViewModel" to MainWindow.xaml
  6. Rebuild the project
  7. Add <Window.Resources> to MainWindow.xaml with <viewmodel:LeagueViewModel x:Key="LeagueViewModel" />
  8. Rebuild the project
I just did that in VS2013 (twice, just to make sure) and it worked totally fine for me. If it works for you, add the the Model and View folders and empty classes to them, and build the skeleton of the project. Then you can copy your classes into them.

Scottintexas wrote Nov 21, 2014 at 8:24 PM

OK. That worked. Is there anything you can tell me to explain why it didn't work the first time? I would hate to get into a big project and have to go through these steps to clear that up somewhere down the road.

BTW I am using VS 2010

andrewstellman wrote Nov 21, 2014 at 11:21 PM

Honestly, 99 times out of 100 when a tool is functioning weirdly for me, it's because I made a typo or some other error. I suspect if you go through the code really carefully, you'll find a typo somewhere. One thing you can try is using a diff tool to compare the .csproj files -- there might be a difference there that explains it.

Obviously, I can't be 100% sure that it's anything you did wrong. There are occasionally issues with VS not recognizing a clr-namespace, but I've only seen it in VS2012 and Windows Store projects, not VS2010 and WPF. But if you build up the skeleton of your project like that, and make sure the namespaces work at every stage, you should be fine.

I hope this helps!