I’ve got a class named Hasher in a namespace named Hasher. So the fully-qualified name would be:
Hasher.Hasher ...
I’m try to use the Hasher class in an external assembly (C#). I’ve imported the namespace into my class:
using Hasher;
But when I try to use the Hasher class the compiler will not find it.
using Hasher;
namespace Test {
///<summary>
///This is a test class for HasherTest and is intended
///to contain all HasherTest Unit Tests
///</summary>
[TestClass()]
public class HasherTest {
///<summary>
///A test for GenerateFromRawData with null seed
///</summary>
[TestMethod()]
[ExpectedException( typeof( ArgumentNullException ) )]
public void GenerateFromRawDataTest_NullSeed() {
byte[] seed = null;
byte[] salt = null;
seed = null;
salt = null;
Hasher.GenerateFromRawData( seed, salt );
}
}
Generates:
Error The type or namespace name 'GenerateFromRawData' does not exist in the namespace 'Hasher' (are you missing an assembly reference?) M:\j41833b_UR403088_ReportingDotNet\ReportingDotNet\src\AG385\_UnitTest\HasherTest.cs _UnitTest
Am I not using “using” correctly? (My primary language is VB.NET, so my C# is a bit rusty. A cursory examination of the MSDN documentation didn’t reveal anything)
EDIT: This works fine.
namespace Test {
///<summary>
///This is a test class for HasherTest and is intended
///to contain all HasherTest Unit Tests
///</summary>
[TestClass()]
public class HasherTest {
///<summary>
///A test for GenerateFromRawData with null seed
///</summary>
[TestMethod()]
[ExpectedException( typeof( ArgumentNullException ) )]
public void GenerateFromRawDataTest_NullSeed() {
byte[] seed = null;
byte[] salt = null;
seed = null;
salt = null;
Hasher.Hasher.GenerateFromRawData( seed, salt );
}
}
Thanks to @asawyer for the following article:
http://blogs.msdn.com/b/ericlippert/archive/2010/03/09/do-not-name-a-class-the-same-as-its-namespace-part-one.aspx
There are two ansers. One, using extern alias:
http://msdn.microsoft.com/en-us/library/ms173212(v=vs.100).aspx
Two, rename the Hasher namespace. (This is recommended when you have control of the source code and it’s the option I chose.)