*.net referenced dll is not seen with a using statement

iqworks Information Quality Works 276 Reputation points
2024-04-29T15:37:56.6+00:00

Hi, I have a project called MBSAnalysisMVCWebApp which is a web app.

I reference MBSAnalysisMVCWebApp from my main MVC project called Mbsa.

But when I try a using statement, It says MBSAnalysisMVCWebApp cannot be seen?  The MBSAnalysisMVCWebApp.dll resides in both the references and bin folders.

I am wondering what could cause this? 

Thanks for any advice or suggestions.

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,307 questions
{count} votes

Accepted answer
  1. Michael Taylor 49,166 Reputation points
    2024-04-30T01:59:39.2033333+00:00

    You're mixing concepts here. In order to use an assembly you must add a reference to it in your project. This is done under the Dependencies node in Solution Explorer (for newer projects). For older projects you use the References node. This is the list of assemblies, COM libraries, other projects and NuGet packages your code relies on. You must add a reference before using code defined outside the project.

    Once you add a reference you now have access to all the public types in that assembly. You can now write code that uses the type. However all types must be fully qualified so you'd need to type in the fully qualified namespace name of the type. For example assembly A my have type S under namespace M and type T under namespace N. To use them you must specify the full name.

    M.S instanceS = new M.S();
    N.T instanceT = new N.T();
    

    Note that you are limited to types that are public and members that are public (or protected if deriving). If a type is internal then it is not accessible outside the assembly it is defined. If there is no accessiblity then it is internal.

    Typing the fully qualified namespace name every time is painful, enter the using directive. This directive imports into the current scope (your file) the namespace you specify. Hence if you're using types from namespaces M and N then you can save some typing by adding a using for them.

    using M;
    using N;
    
    S instanceS = new S();
    T instanceT = new T();
    

    Literally the only thing the using directive (here) is bring in the types that are contained in the given namespace into scop so you can reference them directly. When the compiler sees an identifier it tries to resolve the identifier using the current scope and then the file. If it cannot find it then it looks in the namespaces you including (using) in the file. Where those namespaces are defined is completely irrelevant since namespaces don't represent an object at runtime. They are simply used to fully qualify a name. In fact namespaces can (and do) exist in multiple assemblies.

    Summary: references give you access to the code in an assembly, using directives import namespaces into a file so you can use the simple name instead of a fully qualified namespace name.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Lan Huang-MSFT 26,196 Reputation points Microsoft Vendor
    2024-05-01T02:34:04.56+00:00

    Hi @iqworks Information Quality Works,

    After my testing, I guess you changed the name of your project?

    Please ensure that the namespace in MBSAnalysisMVCWebApp is consistent with the name of the using statement.

    In MBSAnalysisMVCWebApp

    User's image

    In Mbsa

    User's image

    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.