无法加载程序集

时间:2012-12-12 03:57:55

标签: wpf visual-studio-2010 build wpf-controls

我很困惑。我有一个WPF解决方案,我将各种视图分成不同的项目。我还有一个自定义控件的项目。最后,我的应用程序在另一个项目中,设置为默认项目。

我的主窗口和其他一个视图都使用自定义控件项目中的控件。除了使用自定义控件的第二个视图外,我的所有项目都成功构建。

我无法在示例应用中复制此内容,但我会尽力在此处进行说明。

MySolution
    MyApp.csproj
       References
           MyMainWindow
           MySecondWindow
           MyThirdWindow
           MyViewModels
           [std WPF references]
       App.xaml
           App.xaml.cs
    MyMainWindow.csproj
       References
           MyControls
           [std WPF references]
       MainWindow.xaml
           MainWindow.xaml.cs
    MySecondWindow.csproj
       References
           [std WPF references]
       SecondWindow.xaml
           SecondWindow.xaml.cs
    MyThirdWindow.csproj
       References
           MyControls
           [std WPF references]
       ThirdWindow.xaml
           ThirdWindow.xaml.cs
    MyControls
       References
           [std WPF references]
       ControlForMainWindow.xaml
           ControlForMainWindow.xaml.cs
       ControlForThirdWindow.xaml
           ControlForThirdWindow.xaml.cs

在这个(非常粗略的)示例中,MyMainWindow项目和MyThirdWindow项目的引用相同。除MyThirdWindow之外的每个项目都成功构建。我得到的错误是:

Could not load file or assembly '[MyControls]' or one of its dependencies.
The system cannot find the file specified.

有人知道为什么当一个看似相同的项目失败时,一个项目会建立吗?

修改1:

如果我从MyThirdWindow中删除ControlForThirdWindow(和名称空间声明)(但保留项目引用),即使MyMainWindow仍使用ControlForMainWindow,整个解决方案也会构建并运行应用程序。我已经验证了名称空间声明是正确的(我从MyMainWindow复制了它)

1 个答案:

答案 0 :(得分:0)

我一直致力于将所有窗口移动到单独的项目中。对于每个窗口,这需要几个步骤:

  • 创建新项目
  • 将窗口代码复制到新项目
  • 更新副本中的命名空间
  • 从应用程序项目中删除窗口代码
  • 将参考(和using语句)添加到应用程序项目中的新项目
  • 如有必要,在新项目中添加对依赖项的引用
  • 更新目标框架

显然,MyControls上的目标框架设置为.NET Framework 4,MyThirdWindow设置为.NET Framework 4 Client Profile 。我把它设置在我所有的其他窗口项目上,只是错过了这个。

现在解决方案很好。