none
System.DirectoryServices RRS feed

  • Question

  • I am a newbie to c# and visual c#.I find it difficult to add this line to the visual c# project in .NET core..

    ''The type or namespace name 'Directoryservices' does not exist in the namespace 'System' (are you missing an assembly reference?''

    The above is the shown error

    Tuesday, May 29, 2018 12:48 PM

Answers

  • That generally means you're missing an assembly reference. There is no Directoryservices in .NET but there is a DirectoryServices. (notice the capitalizations).  That however is a namespace defined in an assembly that is not referenced by default.

    The recommended approach to coding is to use the type that you need in your code (e.g. DirectoryEntry). Then the IDE will indicate it is an unresolved identifier. But you can use the quick action (icon that appears next to it or right-click) and it will give you several options to resolve the symbol. In most cases you'll select the option to add a using statement. However if the assembly the type is defined in isn't available then you might get an option to add a reference to the assembly. Selecting these options will have the IDE update your code (and possibly project) to reference the correct assembly/namespace. The error will then go away.

    So, in summary, go to the type you're trying to reference in your code and use quick action to have the IDE generate the correct code for you.


    Michael Taylor http://www.michaeltaylorp3.net

    Tuesday, May 29, 2018 1:56 PM
    Moderator
  • Michael Taylor (CoolDadTx) explains how to do the following using Intellisense but this explains how things fit together.

    See System.DirectoryServices Namespace. You can use System.DirectoryServices instead of just DirectoryServices but to simplify things you can put a "using System.DirectoryServices" at the top of the program.

    The problem with the MSDN documentation is that namespace pages don't specify what library has the namespace. So look at the documentation of a class in the namespace, such as DirectoryEntry Class. It has:

    Assembly: System.DirectoryServices (in System.DirectoryServices.dll)

    So you need a reference for System.DirectoryServices. In Solution Explorer expand "References" and look for System.DirectoryServices; if it is not there then you need to add a reference for it. Do you know how to do that?



    Sam Hobbs
    SimpleSamples.Info

    Tuesday, May 29, 2018 4:59 PM

All replies

  • That generally means you're missing an assembly reference. There is no Directoryservices in .NET but there is a DirectoryServices. (notice the capitalizations).  That however is a namespace defined in an assembly that is not referenced by default.

    The recommended approach to coding is to use the type that you need in your code (e.g. DirectoryEntry). Then the IDE will indicate it is an unresolved identifier. But you can use the quick action (icon that appears next to it or right-click) and it will give you several options to resolve the symbol. In most cases you'll select the option to add a using statement. However if the assembly the type is defined in isn't available then you might get an option to add a reference to the assembly. Selecting these options will have the IDE update your code (and possibly project) to reference the correct assembly/namespace. The error will then go away.

    So, in summary, go to the type you're trying to reference in your code and use quick action to have the IDE generate the correct code for you.


    Michael Taylor http://www.michaeltaylorp3.net

    Tuesday, May 29, 2018 1:56 PM
    Moderator
  • Michael Taylor (CoolDadTx) explains how to do the following using Intellisense but this explains how things fit together.

    See System.DirectoryServices Namespace. You can use System.DirectoryServices instead of just DirectoryServices but to simplify things you can put a "using System.DirectoryServices" at the top of the program.

    The problem with the MSDN documentation is that namespace pages don't specify what library has the namespace. So look at the documentation of a class in the namespace, such as DirectoryEntry Class. It has:

    Assembly: System.DirectoryServices (in System.DirectoryServices.dll)

    So you need a reference for System.DirectoryServices. In Solution Explorer expand "References" and look for System.DirectoryServices; if it is not there then you need to add a reference for it. Do you know how to do that?



    Sam Hobbs
    SimpleSamples.Info

    Tuesday, May 29, 2018 4:59 PM
  • Thank u for ur time

    Wednesday, May 30, 2018 10:41 AM
  • Yeah I added the dll file using add reference and now it is working perfectly
    Wednesday, May 30, 2018 10:42 AM