question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Fix the namespace/class issue

See original GitHub issue

As evidenced by the numerous issues here and in SO, there is much confusion and frustration with the namespace and class being named the same thing. (https://github.com/BcryptNet/bcrypt.net/issues/8, https://github.com/BcryptNet/bcrypt.net/issues/11, https://github.com/BcryptNet/bcrypt.net/issues/51, https://github.com/BcryptNet/bcrypt.net/issues/99, https://stackoverflow.com/questions/31844709/conflicting-namespace-resolution). This was a mistake from the very beginning and it was never fixed.

Yes, it’s breaking changes and no one likes breaking changes. But a mistake was made that violates best practices and guidance and sometimes the break is worth the fix. Every new user of this library has to go through the same head scratching/smacking/pounding and losses valuable time.

Let’s make things better for develops and fix this issue in the next major version of BCrypt. I propose the namespace be changed to BCryptNet. This is a simple search and replace for the library owners and users.

It doesn’t even need to be a breaking changes. We could just copy the current code into a new namespace and deprecate the classes in the old one. For this, we wouldn’t even need to wait for the next major version.

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:1
  • Comments:5

github_iconTop GitHub Comments

1reaction
ChrisMcKeecommented, Sep 12, 2022

I cant get the example from the readme to compile, and I think the problem is related to the namespace issue mentioned here.

BCrypt.Verify("my password", "passwordHash");

So I’m really confused about the example in the readme - how would you suggest getting that to work?

I’ve added a few more examples to the readme as its a common one. Obviously most will sink into oblivion with a rename; but it should help current users.

The addition:


DotNet4/6 etc

Due to the naming of the library if the namespace is after the using statements the call changes as .net fails to resolve naming correctly I’d advise rather than enter the entire namespace you simply use the import aliasing as below.


using BC = BCrypt.Net.BCrypt;

namespace DotNetSix;

string passwordHash =  BC.HashPassword("my password");

DotNet6

You can also do aliasing at the CSProj level; and wouldn’t need to add the using statement at all

This example would allow you to use an alias BC.HashPassword() in your code

    <ItemGroup>
        <!-- emits global using BcryptNet = global::BCrypt.Net.BCrypt; -->
        <Using Include="BCrypt.Net.BCrypt" Alias="BC"/>
    </ItemGroup>

This version would allow you to just call Verify and HashPassword in your code base without any other reference.

    <ItemGroup>
        <!-- emits global using static global::BCrypt.Net.BCrypt; -->
        <Using Include="BCrypt.Net.BCrypt" Static="True"/>
    </ItemGroup>
1reaction
ChrisMcKeecommented, Aug 22, 2022

@devklick its an inherited namespace issue; You can either do as you have done or beyond that it depends on where your using statements sit. Outside of namespace it causes issues; within namespace xxx { using… } it was fine. Obviously this is more of an annoyance in Net6 with global usings etc.

I’ll be renaming it in V5 and leaving a skeleton of the original namespace/class marked obsolete.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I fix a "type or namespace name could not be ...
I resolved the problem by deleting the folder and the classes inside, creating a new folder and creating new classes in that new...
Read more >
"The type or namespace name 'ClassName' does not exist" ...
Fixes an issue in which an incorrect minimally qualified name is generated for a public control in a Windows Form solution in Microsoft...
Read more >
namespace class missing
Hello, I have an odd problem that for some reason I have not figured ... Make sure to include the correct namespace for...
Read more >
VS2019 Not Recognizing Classes in Other Namespaces
I've tried re-adding the reference to the class library, deleting the .vs folder, the bin and obj folders, clean, rebuild, etc. and nothing...
Read more >
Unity can't recognize class and namespace, how can I fix it?
The problem appears to be in having native access to scripts across a folder hierarchy.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found