Reference added but Namespace is not recognized

前端 未结 8 1598
不知归路
不知归路 2021-01-11 12:56

I added a DLL to my project. The DLL contains the namespace test.security. Now, test.security is not recognized. Why is this?

I am using this DLL in oth

8条回答
  •  自闭症患者
    2021-01-11 13:33

    I would like to add a cause for this, found in VB.NET (Visual Studio 2010, in my case; yours may vary).

    As an example, I have two projects: P1 and P2.

    P1 is an Application, and P2 is a Class Library.

    Stipulations:

    • There is a reference in P1 to P2
    • Both P1 and P2 are targeting .NET 4.0 (full, not Client)
    • Both P1 and P2 target x86 (not that it likely matters)
    • There are 0 errors and 0 warnings

    However, in P1, it is not possible to declare an 'Imports P2...' expression, nor to use any Shared methods found in P2. It exactly as if the Namespace P2 does not exist, though the reference is there.

    Cause: P2 was converted to a separate assembly from code in which all methods were contained in a VB.NET Public Module. However, the 'Module' was not re-typed as a Public Class.

    No errors whatsoever, but the P2 Namespace was entirely unavailable to P1 until a Public Class was created.

    Of note, it was not actually necessary to convert the original Module to a Class. It was only necessary to declare some Public Class (even if it is empty) within the P2 Namespace, and then all methods found in that Public Module were available.

提交回复
热议问题