To connect to an ldap-Server i want to use Directory Services in a c#-console application.
- The services are available in dotnet-7.0
- Therefore i need to upgrade from dotnet-5.0
These are the steps to reproduce:
- On a console execute these commands
dotnet new console -f=net5.0 -o=ConsoleFiveToSevencd ConsoleFiveToSevendotnet run- Inside
ConsoleFiveToSeven.csprojchange<TargetFramework>net5.0</TargetFramework>to<TargetFramework>net7.0</TargetFramework>and save - Execute
dotnet runagain. This creates\ConsoleFiveToSeven\bin\Debug\net7.0 - Execute
dotnet add package System.DirectoryServices.Protocols --version 7.0.0 - Add the code below
- Execute
dotnet build
What is the problem?
- Expected: The solutions compiles without a problem
- Actual: Error CS0103
distinguishedNameandldapFilterandsearchScopeandattributeListdoes not exist in the current context
The docs for SearchRequest contains this constructor
public SearchRequest (string distinguishedName
, string ldapFilter
, System.DirectoryServices.Protocols.SearchScope searchScope
, params string[] attributeList);
Question
To my understanding the following code below should be fine. What is the problem?
Code for step 8 above
using System;
using System.Net;
using System.DirectoryServices.Protocols;
namespace ConsoleFiveToSeven
{
class Program
{
static void Main(string[] args)
{
SearchRequest search = new SearchRequest(
distinguishedName = "foo",
ldapFilter = "foo",
searchScope = SearchScope.Subtree,
attributeList = new string [] {"cn=foo", "cn=bar", "cn=com"}
);
}
}
}
Not entirely. In C#,
=to specify parameters by names is invalid. You should use:But if you use default order of parameters you can omit their names: