System.DirectoryServices.AccountManagement.PrincipalContext support in .NET Core 2.0
Hello,
I have tried to download the latest version of preview System.DirectoryServices.AccountManagement from myget - https://dotnet.myget.org/feed/dotnet-core/package/nuget/System.DirectoryServices.AccountManagement
And I have tried to use the PrincipalContext:
using(var context = new PrincipalContext(ContextType.Domain))
{
//code
}
And I get the System.NullReferenceException:
{System.NullReferenceException: Object reference not set to an instance of an object.
at System.DirectoryServices.Protocols.LdapConnection.ConstructEntry(IntPtr entryMessage)
at System.DirectoryServices.Protocols.LdapConnection.ConstructResponse(Int32 messageId, LdapOperation operation, ResultAll resultType, TimeSpan requestTimeOut, Boolean exceptionOnTimeOut)
at System.DirectoryServices.Protocols.LdapConnection.SendRequest(DirectoryRequest request, TimeSpan requestTimeout)
at System.DirectoryServices.AccountManagement.PrincipalContext.ReadServerConfig(String serverName, ServerProperties& properties)
at System.DirectoryServices.AccountManagement.PrincipalContext.DoServerVerifyAndPropRetrieval()
at System.DirectoryServices.AccountManagement.PrincipalContext..ctor(ContextType contextType, String name, String container, ContextOptions options, String userName, String password)
at System.DirectoryServices.AccountManagement.PrincipalContext..ctor(ContextType contextType)
at CoreADcko.Controllers.HomeController.Index() in C:\Projects\CoreADcko\CoreAD\CoreAD\Controllers\HomeController.cs:line 17
at lambda_method(Closure , Object , Object[] )
at Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object target, Object[] parameters)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeActionMethodAsync>d__12.MoveNext()}
I have used the WebApplication .NET Core template with windows authentication enabled and these dependecies:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<MvcRazorCompileOnPublish>true</MvcRazorCompileOnPublish>
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0-preview2-final" />
<PackageReference Include="System.DirectoryServices.AccountManagement" Version="4.5.0-preview2-25628-01" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0-preview2-final" />
</ItemGroup>
</Project>
How can I solve this error?
Thank you.
Same issue here
What I found was that targetting net47 things work properly, but when targetting netcoreapp2.0 running in a Windows environment I get the exact same exception.
Same issue with targeting netcoreapp2.0. I am using the latest build: 25630-01
Can confirm this is trivially reproed. Line numbers:
> System.DirectoryServices.Protocols.dll!System.DirectoryServices.Protocols.LdapConnection.ConstructEntry(System.IntPtr entryMessage) Line 1786 C# Symbols loaded.
System.DirectoryServices.Protocols.dll!System.DirectoryServices.Protocols.LdapConnection.ConstructResponse(int messageId, System.DirectoryServices.Protocols.LdapOperation operation, System.DirectoryServices.Protocols.ResultAll resultType, System.TimeSpan requestTimeOut, bool exceptionOnTimeOut) Line 1553 C# Symbols loaded.
System.DirectoryServices.Protocols.dll!System.DirectoryServices.Protocols.LdapConnection.SendRequest(System.DirectoryServices.Protocols.DirectoryRequest request, System.TimeSpan requestTimeout) Line 300 C# Symbols loaded.
System.DirectoryServices.Protocols.dll!System.DirectoryServices.Protocols.LdapConnection.SendRequest(System.DirectoryServices.Protocols.DirectoryRequest request) Line 245 C# Symbols loaded.
System.DirectoryServices.AccountManagement.dll!System.DirectoryServices.AccountManagement.PrincipalContext.ReadServerConfig(string serverName, ref System.DirectoryServices.AccountManagement.ServerProperties properties) Line 1132 C# Symbols loaded.
System.DirectoryServices.AccountManagement.dll!System.DirectoryServices.AccountManagement.PrincipalContext.DoServerVerifyAndPropRetrieval() Line 700 C# Symbols loaded.
System.DirectoryServices.AccountManagement.dll!System.DirectoryServices.AccountManagement.PrincipalContext.PrincipalContext(System.DirectoryServices.AccountManagement.ContextType contextType, string name, string container, System.DirectoryServices.AccountManagement.ContextOptions options, string userName, string password) Line 434 C# Symbols loaded.
System.DirectoryServices.AccountManagement.dll!System.DirectoryServices.AccountManagement.PrincipalContext.PrincipalContext(System.DirectoryServices.AccountManagement.ContextType contextType) Line 362 C# Symbols loaded.
1.dll!Program.AssemblyLoadRepro.Main() Line 21 C# Symbols loaded.
This request
DistinguishedName null string
Filter "(objectClass=*)" object {string}
Scope Base System.DirectoryServices.Protocols.SearchScope
is giving back an empty result from ldap_get_dn. I am not famliar with the code so I don't know yet what is supposed to happen.
@tquerec @jay98014 do you have any pointers? I could set up the same repro on desktop to see what it does there, but you know far more about this than I do (zero)
How to get debugging - build corefx in the normal way. Create project thus, replacing paths to the corefx output path:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Reference Include="C:\git\corefx\bin\Windows_NT.AnyCPU.Debug\System.DirectoryServices.AccountManagement\netstandard\System.DirectoryServices.AccountManagement.dll"/>
<Reference Include="C:\git\corefx\bin\Windows_NT.AnyCPU.Debug\System.DirectoryServices.Protocols\netstandard\System.DirectoryServices.Protocols.dll"/>
<Reference Include="C:\git\corefx\bin\Windows_NT.AnyCPU.Debug\System.DirectoryServices\netstandard\System.DirectoryServices.dll"/>
<PackageReference Include="System.DirectoryServices.AccountManagement" Version="4.5.0-preview2-25628-01" />
</ItemGroup>
</Project>
Paste this line into main
using(var context = new PrincipalContext(ContextType.Domain)) {}
Hit F5.
@danmosemsft I have used this setting for now:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.DirectoryServices.AccountManagement" Version="4.5.0-preview2-25631-02" />
</ItemGroup>
</Project>
using(var context = new PrincipalContext(ContextType.Domain)) {}
But I get absolutely same System.NullReferenceException.
Thank you for any points.
Hmm even easier repro, just run System.DirectoryServices.AccountManagement.Tests, at least on my machine. Interestingly they fail differently in test runs https://mc.dot.net/#/product/netcore/master/source/official~2Fcorefx~2Fmaster~2F/type/test~2Ffunctional~2Fcli~2F/build/20170901.02/workItem/System.DirectoryServices.AccountManagement.Tests
@tquerec @jay98014 can you help us get System.DirectoryServices.AccountManagement.Test passing? Or give me pointers to investigate further?
On Helix machines, they are getting different results: https://github.com/dotnet/corefx/issues/23548. They are not domain joined. We need to fix both.
@tarekgh this is the first thing to look at it directory services. A lot of folks are hitting this. I also got it at one point when running the unit tests.
I'll start looking on Monday.
@tarekgh Hello! Where can I download fix for Domain type PrincipalContext instantiating? Could I find it in future System.DirectoryServices.AccountManagement NuGet package or it would release only as CoreFX fix?
@kazantsev-nikita since yesterday our build system is down and this is being worked on. I would expect this to automatically go to myget when it's up. That doesn't explain why there was no update to the package since the 7th. We certainly had builds since then. @tarekgh any idea about that?
I'll check why we didn't have build for these packages since Sept 7th.
@kazantsev-nikita the fix I did will show at https://dotnet.myget.org/feed/dotnet-core/package/nuget/System.DirectoryServices.Protocols when our builds succeed.
@danmosemsft we already have packages published yesterday. you may look at the version 4.5.0-preview1-25718-03 of the package. note that the list in myget is not sorted by publishing date so you have to scroll down to see such package.
I am not expecting my fix will show in the latest published package though. I think tomorrow's one would be.
@danmosemsft are there any predictions when build system will work?
Guys, something is really messed up with these version numbers, you are building 4.5.0-preview1- now, but the builds from Sep 7 were 4.5.0-preview2-, that's why the list is out of order on your myget.
CC @weshaggard
@kazantsev-nikita
are there any predictions when build system will work?
Hopefully, we'll get build tomorrow.
@los93sol
something is really messed up with these version numbers, you are building 4.5.0-preview1- now, but the builds from Sep 7 were 4.5.0-preview2-, that's why the list is out of order on your myget.
We are trying to align the version with the 2.1 release. This is why we changed it to preview1. preview2 version can be deleted from myget but we don't see strong reason doing that.
@tarekgh Why not bump from 4.5.0 to 4.6.0 so it isn't so confusing
@tarekgh Why not bump from 4.5.0 to 4.6.0 so it isn't so confusing
We wanted to avoid versioning everything in the repo and essentially skipping versions. This is an issue that will only be seen in our dev feeds so it is limited it will never be seen in our official releases on nuget.org.
I have tried download the latest version of System.DirectoryServices.AccountManagement - but I still get same exception - 4.5.0-preview1-25718-03.
Can you please help me with this - is it correct version?