【问题标题】:C# .NET DLL Won't Build Because of System.Web conflicts由于 System.Web 冲突,C# .NET DLL 无法构建
【发布时间】:2011-02-02 06:07:02
【问题描述】:

我在 Visual Studio C# Express 2010 中的类库出现问题。该项目配置了 .NET 4.0(不是客户端配置文件)的目标框架。

在我的类库中,我添加了对 System.Web 的引用,以使 URL 编码适用于我的 oAuth 库。

在构建 DLL 和相关的测试应用程序时,我收到以下错误:

Error   1   The type or namespace name 'TwitterAPI' could not be found (are you missing a using directive or an assembly reference?)    C:\Users\sammarks\Documents\Programming\Twitter.NET\Tester\Program.cs   5   7   Tester

而且,我收到以下警告消息:

Warning 2   The referenced assembly "C:\Users\sammarks\Documents\Programming\Twitter.NET\TwitterAPI\bin\Release\TwitterAPI.dll" could not be resolved because it has a dependency on "System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which is not in the currently targeted framework ".NETFramework,Version=v4.0,Profile=Client". Please remove references to assemblies not in the targeted framework or consider retargeting your project.   Tester

我不确定它为什么会这样,但这就是我来这里的原因。我已经尝试将类库重新定位到 3.5,但这只会进一步搞砸。

我也尝试将 System.Web 重新添加到引用中,但这也无济于事。

有什么建议吗?

【问题讨论】:

    标签: c# .net visual-studio-2010


    【解决方案1】:

    针对完整 .NET Framework 4.0 访问 System.Web(不是客户端配置文件):

    【讨论】:

    【解决方案2】:

    看起来您的类库引用了客户端配置文件,而您的测试可执行文件引用了非客户端配置文件。我从警告中收集到这一点:

    ...currently targeted framework ".NETFramework,Version=v4.0,Profile=Client ...
    

    【讨论】:

    • 那么这是否意味着我需要将目标框架更改为 .NET 4.0 Client Profile?
    • 不,不应该是客户资料;检查两个程序集是否针对相同的版本,因为该警告看起来很可疑,就像其中一个针对客户端配置文件一样。此外,请确保在更改属性后保存(仅进行构建或调试不会保存对程序集属性 IIRC 的更改)。
    【解决方案3】:

    可能听起来很傻,但是您尝试过重新启动 Visual Studio 吗?

    它有时往往会错过一两个参考。

    【讨论】:

    • 不。我重新启动它,它没有工作。如果这真的有效,我会感到非常震惊,虽然哈哈。
    • 这个答案和你的用户名有关系吗?
    • 我碰巧有一个包含公共成员的公共类,但我无法访问它们,因为它说它是受保护的或私有的。重启解决了这个问题。
    猜你喜欢
    • 1970-01-01
    • 2011-02-19
    • 2012-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-24
    • 2020-08-08
    相关资源
    最近更新 更多