[wix-devs] Extending UserVerifier
Ron Martin
cpuwzd at comcast.net
Tue Aug 9 19:46:28 PDT 2022
Since I've been working on adding user comments for user accounts
created by Wix installations, I've come up with a need to extend the
UserVerifier class used in the MSI end to end tests so that it can aet
and verify user comments.
Digging into Active Directory for the first time in my life has been a
real adventure. I've come up with a few MS examples, but have yet to be
able to make any of them work.
Here's a stand-alone test that give the essence of my problem:
Start by creating a .net Framework 4.72 console application. Use the
code below as the only .cs file. Add a reference to
System.DirectoryServices.AccountManagement. The .cs file should look like:
--------------------------------------------------------------------------------------------
using System.DirectoryServices.AccountManagement;
namespace UserPrincipalBug
{
internal class Program
{
static void Main(string[] args)
{
WindowsUser user = WindowsUser.GetUser("<put a valid local
user name here>");
user.Comment = "This is my comment!";
}
}
[DirectoryRdnPrefix("CN")]
[DirectoryObjectClass("user")]
public class WindowsUser : UserPrincipal
{
public WindowsUser(PrincipalContext context) : base(context)
{
}
[DirectoryProperty("comment")]
public string Comment
{
set
{
ExtensionSet("comment", value);
}
}
public static new WindowsUser FindByIdentity(PrincipalContext
context,
IdentityType
identityType,
string identityValue)
{
return (WindowsUser)FindByIdentityWithType(context,
typeof(WindowsUser),
identityType,
identityValue);
}
public static WindowsUser GetUser(string userName)
{
using (var context = new PrincipalContext(ContextType.Machine))
{
return FindByIdentity(context, IdentityType.Name,
userName);
}
}
}
}
--------------------------------------------------------------------------------------------
The problem boils down to FindByIdentityWithType not being able to
return an object of type WindowsUser. The class that actually implements
this method is several levels higher in the inheritance hierarchy, i a
class named Principal. It manages to return an object of type
UserPrincipal, which is the parent class of WindowsUser, but cannot be
cast to WindowsUser. Oddly, the code compiles without error and only
throws an exception at runtime.
All of the examples I have tried run into the same problem. I don't know
if the code is emitting IL or what kind of trick it is using, but it
appears to be broken.
If I have to, I'll back up and access the inner structure in a less
glamorous way, but I'm hoping that the person who wrote UserVerifier can
set me straight. I'll be listening during Thursday's meeting to see if
any help is forthcoming. I have some related questions I'd like to ask,
as well.
Ron
More information about the wix-devs
mailing list