VS2010 C#WPF应用程序:新的WPF项目无法从另一个项目调用静态类方法

时间:2021-09-13 09:44:59

In my current personal project, I have a Core project, a DependencyResolution project, and a UI project (WPF application). In the UI project, I've tried to make a call to the DependencyRegistrar class that's in DependencyResolution in both MainWindow.xaml.cs and App.xaml.cs. There seems to be an issue with the UI project referencing the DependencyResolution project, as this compiler error always occurs:

在我目前的个人项目中,我有一个Core项目,一个DependencyResolution项目和一个UI项目(WPF应用程序)。在UI项目中,我试图调用MainWindow.xaml.cs和App.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

Just including the using statement anywhere in the UI yields that error.

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

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

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

I can reference the Core project (using DMTools.InitiativeTracker.Core) and everything compiles okay. Furthermore, I can make references to DependencyRegistrar in the IntegrationTests project (another Class Library) and it compiles okay.

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

You can find the complete source here. Feel free to request specific snippets if you need more info.

你可以在这里找到完整的来源。如果您需要更多信息,请随时索取特定的代码段。

EDIT: I have added an assembly reference to DependencyRegistrar both via ReSharper and the typical Visual Studio way. Both cases did not resolve the issue. To the other comment: When I add a reference to a Core static class (IoC), the XAML remains unchanged but it compiles fine.

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

1 个解决方案

#1


0  

Tigran's comment figured out the mystery. In the UI project, I changed Target framework from ".NET Framework 4 Client Profile" to ".NET Framework 4" and it all works correctly.

蒂格兰的评论找出了这个谜团。在UI项目中,我将Target框架从“.NET Framework 4 Client Profile”更改为“.NET Framework 4”,这一切都正常。

The only thing I can think of as to why this was an issue with DependencyResolution and not Core is that the former makes references to third party utilities (i.e. Ninject) which has issues with Client Profile, but I'm only guessing here.

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

#1


0  

Tigran's comment figured out the mystery. In the UI project, I changed Target framework from ".NET Framework 4 Client Profile" to ".NET Framework 4" and it all works correctly.

蒂格兰的评论找出了这个谜团。在UI项目中,我将Target框架从“.NET Framework 4 Client Profile”更改为“.NET Framework 4”,这一切都正常。

The only thing I can think of as to why this was an issue with DependencyResolution and not Core is that the former makes references to third party utilities (i.e. Ninject) which has issues with Client Profile, but I'm only guessing here.

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