c# - 冲突的命名空间解析

标签 c# .net visual-studio-2013 namespaces

我正在使用一个名为 BCrypt.net 的库,作者将Namespace 与Class 同名,所以Class 全路径为:BCrypt.Net.BCrypt,其中BCrypt.Net 为Namespace,BCrypt 为Class 名称。

我正在尝试在我的代码中使用,就像我能找到的所有示例一样,例如:

BCrypt.HashPassword("234");

但是 Visual Studio 提示说:

Error 3 The type or namespace name 'HashPassword' does not exist in the namespace 'BCrypt' (are you missing an assembly reference?)



我的项目中有程序集(因为我是从 NuGet 得到的):

Assembly Reference

如果我添加一个 using BCrypt.Net;using BCrypt; ,在我的命名空间之前,错误说明相同。
我将它添加到我的命名空间中,发生了一些有趣的事情。我工作,代码编译并执行。但是 Visual Studio 显示错误!我无法理解它是如何编译出错的。
namespace Test.Data
{
    using BCrypt.Net; // The 'Net' is marked with a Red Error line in VS2013
    ....
    string s = BCrypt.HashPassword("234");

Error 3 The type name 'Net' does not exist in the type >'BCrypt.Net.BCrypt'


using BCrypt = BCrypt.Net.BCrypt; 的错误(但编译和执行正常)相同

发生什么了?

编辑:

我知道我可以用它作为 BCrypt.Net.BCrypt.HashPassword("234"); ,但我想避免它。

最佳答案

添加

using BCrypt = BCrypt.Net.BCrypt;

到您的用途:
namespace YourNamespace
{
    using BCrypt = BCrypt.Net.BCrypt;

    class Program
    {
        static void Main(string[] args)
        {
            BCrypt.HashPassword("234");
        }
    }

打样画面:

VS 2015 likes this

关于c# - 冲突的命名空间解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31844709/

相关文章:

c# - 如何将颗粒与 C# 连接? (在 C# 中加载本体。)

.net - 为什么 ReadOnlyCollection<T> 不是 ReadOnlyList<T>?

.net - 在 Azure 中并行运行的任务数量有限

C# 如何序列化 system.linq.expressions?

c# - 如何: Representing NULL in SQLite queries

c# - 是否可以将 Action 委托(delegate)传递给 ThreadPool.QueueUserWorkItem?

c# - 是什么导致 RoleEnvironment 初始值设定项中的 ModuleLoadException?

asp.net - 在MVC5中,如何保证cookie中包含的用户仍然存在或者密码与上次登录没有变化?

c# - 在 ASP.NET Web 应用程序、存储库模式上放置业务规则的位置

visual-studio-2013 - Visual Studio 2013 更新 3 个问题