Posts

Showing posts from December, 2012

"Object reference not set to an instance of an object" when reading C# GroupPrincipal.Members.Count

Image
It seems that there is a bug in the .NET 3.5 managed library System.DirectoryServices.AccountManagement. When you try and view the Members.Count property of a Global group the system throws the following exception. System.NullReferenceException: Object reference not set to an instance of an object. at System.DirectoryServices.AccountManagement.ADDNLinkedAttrSet.BookmarkAndReset() at System.DirectoryServices.AccountManagement.PrincipalCollection.get_Count()   It is however possible to enumerate the members of the group   The following sample code demonstrates the issue where the domain is called demonstration.int and the group name is SampleGroup.   GroupPrincipal Group = GroupPrincipal .FindByIdentity( new PrincipalContext ( ContextType .Domain, "demonstration.int" ), "SampleGroup" ); MessageBox .Show(Group.Members.Count.ToString());   If anyone has any further information please feel free to post a comment. I've not

Cannot create an instance of ...type... because it is an abstract class

Image
When you are using the propertygrid to bind a generic list the system tends to work allowing you to add new items to the list as long as the items in List<T> are all of the exact same type. However if the List<T> is an abstract class and you want to select which item type to add to the list you will find the following error. Cannot create an instance of Type because it is an abstract class. What you want in this case it to be able to add any subclass of the abstract class defined as T in the list selecting the appropriate type. This can be done simply by inheriting from the CollectionEditor and letting the system know what types of object are valid for selection. I this example rather than manually return a list we use Reflection to read all of the types defined in the assembly and determine dynamically which ones are inherited from the base class T. /// <summary> /// Provides an editor to modify a list of variable definitions

Server Documentation

XIA Configuration is a professional, enterprise ready platform for the automated audit and documentation of your server environment. Supported Platforms Windows NT4 Workstation Windows NT4 Server Windows 2000 Professional Windows 2000 Server Windows XP Professional Windows Server 2003 (all editions) Windows Server 2003 R2 Windows Vista Windows Server 2008 Windows 7 Windows Server 2008 R2 Windows 8 Windows Server 2012 Capabilities Security Networking Settings Routing Tables Windows Services Installed Software Windows Patches Event Log Configuration Startup Commands Scheduled Tasks Local Users and Groups For more information see the following Server Documentation

"System.ObjectDisposedException: Safe handle has been closed" when running a background thread

Image
When using an ASP.NET page you may see the "System.ObjectDisposedException: Safe handle has been closed" when running a background thread. Typically this is seen when you try to access the name property - for example. Thread .CurrentPrincipal.Identity.Name     What appears to happen is that IIS has initiated the new background thread and the thread identity flows down to that new thread. The HTTP connection closes down and control is restored to the browser (which is probably what you wanted if you're using a background thread). Unfortunately the thread identity is closed down and disposed of as part of this process so you can't access it. To work around this problem it is possible to use clone the thread's CurrentPrincipal on the webform and pass this to the background thread and set to using the Thread.CurrentPrincipal property. This is possible as the threads are running in the same process - this method wouldn't work across process boun