简体   繁体   English

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

[英]VS2010 C# WPF App: New WPF Project Cannot Call Static Class Method from Another Project

In my current personal project , I have a Core project, a DependencyResolution project, and a UI project (WPF application). 在我当前的个人项目中 ,我有一个Core项目,一个DependencyResolution项目和一个UI项目(WPF应用程序)。 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 . 在UI项目中,我尝试调用MainWindow.xaml.csApp.xaml.cs中DependencyResolution中的DependencyRegistrar类。 There seems to be an issue with the UI project referencing the DependencyResolution project, as this compiler error always occurs: 引用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. 我可以引用Core项目( using DMTools.InitiativeTracker.Core ),并且一切都可以编译。 Furthermore, I can make references to DependencyRegistrar in the IntegrationTests project (another Class Library) and it compiles okay. 此外,我可以在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. 编辑:我已经通过ReSharper和典型的Visual Studio方式向DependencyRegistrar添加了程序集引用。 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. 换句话来说:当我添加对Core静态类(IoC)的引用时,XAML保持不变,但可以正常编译。

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 framework从“ .NET Framework 4客户端配置文件”更改为“ .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 (ie Ninject) which has issues with Client Profile, but I'm only guessing here. 我唯一想到的是为什么这是DependencyResolution而不是Core的问题,原因是前者引用了与Client Profile有关的第三方实用程序(即Ninject),但我只是在这里猜测。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM