The name ViewModel does not exist in the namespace “clr-namespace:Project.ViewModels”

前端 未结 18 1878
旧时难觅i
旧时难觅i 2020-12-04 23:55

Now that\'s a real strange error. I am working on a WPF application and following MVVM. In my MainWindow I am setting views and view models and I get this strange error. Alt

18条回答
  •  猫巷女王i
    2020-12-05 00:45

    This one's been tying me in knots for hours.

    I have a VS2015 solution which is several years old. On my laptop, it builds beautifully, all the code is checked into TFS, but when I tried to build it on a different machine, I'd constantly get this message about the namespace not existing.

    Basically, this RepBaseWindow is a class inherited from the WPF Window class, with a few extra bells'n'whistles.

    public class RepBaseWindow : Window
    

    I'd tried a load of the suggestions on here, but no luck.

    The irony is that, despite this message, if I right-clicked on this faulty link and selected "View Code", it'd happily take me to this class. The namespace was fine, the class was fine... but WPF wasn't happy about it.

    If I tried to use Intellisense to find the namespace, I'd end up with the same markup... and the same Build Errors.

    I compared the working copy of the code with the TFS version, and realised the problem.

    I needed to go back to using an old copy of the WindowBase.dll file from 2012.

    Ridiculous, hey ?

    The working version of WindowBase.dll is 635kb in size, and shows this in the details tab:

    I'm just posting this answer to show that, sometimes, these errors have absolutely nothing to do with faulty WPF markup or wrongly-spelt namespace names.

    Hope this helps.

提交回复
热议问题