【问题标题】:VS2010 C# WPF App: New WPF Project Cannot Call Static Class Method from Another ProjectVS2010 C# WPF App:新建WPF项目无法从另一个项目调用静态类方法
【发布时间】:2011-07-24 13:23:55
【问题描述】:

在我当前的personal project 中,我有一个Core 项目、一个DependencyResolution 项目和一个UI 项目(WPF 应用程序)。在 UI 项目中,我尝试在 MainWindow.xaml.csApp.xaml.cs 中调用 DependencyResolution 中的 DependencyRegistrar 类。引用 DependencyResolution 项目的 UI 项目似乎存在问题,因为总是出现此编译器错误:

The type or namespace name 'DependencyResolution' does not exist in the namespace
'DMTools.InitiativeTracker' (are you missing an assembly reference?)    
D:\Dev\InitiativeTracker\src\UI\App.xaml.cs 2 33 UI

在 UI 中的任何位置都包含 using 语句会产生该错误。

using System.Windows;
using DMTools.InitiativeTracker.DependencyResolution;

namespace DMTools.InitiativeTracker.UI
{
    public partial class App : Application
    { }
}

我可以引用 Core 项目 (using DMTools.InitiativeTracker.Core) 并且一切都可以编译。此外,我可以在IntegrationTests 项目(另一个类库)中引用DependencyRegistrar,它可以编译。

您可以找到完整的源代码here。如果您需要更多信息,请随时请求特定的 sn-ps。

编辑: 我已经通过 ReSharper 和典型的 Visual Studio 方式添加了对 DependencyRegistrar 的程序集引用。两种情况都没有解决问题。另一条评论:当我添加对核心静态类 (IoC) 的引用时,XAML 保持不变,但可以正常编译。

【问题讨论】:

  • 您是否将程序集添加为对项目的引用?
  • 检查冲突的两个项目的 .NET 版本...

标签: c# wpf .net-4.0 compiler-errors


【解决方案1】:

蒂格兰的评论揭开了谜底。在 UI 项目中,我将 Target framework 从“.NET Framework 4 Client Profile”更改为“.NET Framework 4”,一切正常。

关于为什么这是 DependencyResolution 而不是 Core 的问题,我唯一能想到的是前者引用了与 Client Profile 有问题的第三方实用程序(即 Ninject),但我只是在这里猜测.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-29
    • 1970-01-01
    • 1970-01-01
    • 2020-07-30
    • 1970-01-01
    相关资源
    最近更新 更多