You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
DirectoryVirtualListView.ApproximateTotal always returning zero for .NET Core #47169
After performing a search with the System.DirectoryServices.DirectorySearcher using a VirtualListView, the VirtualListView.ApproximateTotal value is always returning as 0 even in cases where there should be results.
Example code:
using (var searcher = new DirectorySearcher())
{
searcher.SearchRoot = new DirectoryEntry() { Path = $"GC://DC=jedi,DC=com" };
searcher.Filter = $"(objectCategory=user)";
searcher.Sort = new SortOption("cn", SortDirection.Ascending);
searcher.PropertiesToLoad.Add("objectSid");
searcher.VirtualListView = new DirectoryVirtualListView(0, 15, 1);
var users = searcher.FindAll().OfType<SearchResult>();
foreach (var user in users)
{
var sidProperty = user.Properties["objectSid"];
if (sidProperty.Count > 0)
{
var sidBytes = (byte[])(sidProperty[0]);
Console.WriteLine(new SecurityIdentifier(sidBytes, 0).ToString());
}
};
// Approximate total always returns zero
Console.WriteLine($"Approximate Total = {searcher.VirtualListView.ApproximateTotal}");
}
Configuration
.NET Core 3.1
Windows Server 2016
x64
Not aware that the problem is specific to this configuration.
Regression?
Yes. The same code returns the expected ApproximateTotal value in a .NET Framework application
Activity
ghost added
untriagedNew issue has not been triaged by the area owner
Thanks for the report @ben-falconer . Does it behave the same on .NET 5.0? Are you willing to debug a bit? The code should generally be the same as .NET Framework, on Windows.
I've just tried it and it does behave the same on .NET 5.0. Unfortunately, I don't have a huge amount of time to debug the issue too much further right now.
We're looking to migrate some functionality across from a .NET Framework app to a .NET Core app currently. If it is a bug then we'd need to change the design of the pagination control we're using to be a simpler Previous/Next control, and possibly perform additional LDAP queries to help calculate whether there is a next page in the search. It's not ideal, but I think we should be able to find a way to make it work.
OK - that probably makes sense because even if we did service for something, it would take some time and going back to 3.1 would be a higher bar to meet than 5.0.
@jasonpals I don't think so. We don't have much time to spend on this library, which has hardly changed in a long time, but we welcome fixes if others are interested in investigating.
@danmoseley
I just looked in the code and found the problem.
The problem is that searchResult in DirectorySearcher is not filled anymore (since ticket dotnet/corefx#40321)
But when retrieving the DirectorySearcher.VirtualListView it is assumed that the searchResult != null.
My workaround via Reflection: var results = directorySearcher.FindAll(); var virtualListView = results.GetType().GetProperty("VLVResponse", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)?.GetValue(results) as DirectoryVirtualListView; int? count = virtualListView?.ApproximateTotal;
Activity
danmoseley commentedon Jan 20, 2021
Thanks for the report @ben-falconer . Does it behave the same on .NET 5.0? Are you willing to debug a bit? The code should generally be the same as .NET Framework, on Windows.
ben-falconer commentedon Jan 20, 2021
I've just tried it and it does behave the same on .NET 5.0. Unfortunately, I don't have a huge amount of time to debug the issue too much further right now.
danmoseley commentedon Jan 20, 2021
Interesting. Are you blocked, do you have a workaround? Perhaps @joperezr has an idea why the behavior changed.
ben-falconer commentedon Jan 20, 2021
We're looking to migrate some functionality across from a .NET Framework app to a .NET Core app currently. If it is a bug then we'd need to change the design of the pagination control we're using to be a simpler Previous/Next control, and possibly perform additional LDAP queries to help calculate whether there is a next page in the search. It's not ideal, but I think we should be able to find a way to make it work.
danmoseley commentedon Jan 20, 2021
OK - that probably makes sense because even if we did service for something, it would take some time and going back to 3.1 would be a higher bar to meet than 5.0.
jasonpals commentedon Jun 24, 2021
I am using .Net Core 5.0 and this still isn't fixed. Any timeframe on a resolution?
danmoseley commentedon Jun 24, 2021
@jasonpals I don't think so. We don't have much time to spend on this library, which has hardly changed in a long time, but we welcome fixes if others are interested in investigating.
mrksmhr commentedon Oct 27, 2021
@danmoseley
I just looked in the code and found the problem.
The problem is that searchResult in DirectorySearcher is not filled anymore (since ticket dotnet/corefx#40321)
But when retrieving the DirectorySearcher.VirtualListView it is assumed that the searchResult != null.
My workaround via Reflection:
var results = directorySearcher.FindAll(); var virtualListView = results.GetType().GetProperty("VLVResponse", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)?.GetValue(results) as DirectoryVirtualListView; int? count = virtualListView?.ApproximateTotal;danmoseley commentedon Oct 27, 2021
@mrksmhr thanks for investigating! Would you like to offer a PR?
akoeplinger commentedon Dec 5, 2022
This is fixed by #79093. We have pending backports for the 6.0 and 7.0 releases.