0

To make my console application launch after install I have added an installer class to my project.

public override void Commit(IDictionary savedState)
{
     base.Commit(savedState);
     System.Diagnostics.Process.Start(System.IO.Path.GetDirectoryName(this.Context.Parameters["AssemblyPath"]) + @"\MyAppName.exe");
}

I have added custom actions to my SetupProject (shortcut to Primary output MyApp.exe under Install and Commit) to execute launch after install and it does launch the app.

However when the app launches after install, and Main() runs UserPrincipal.Current.EmailAddress; I get this error:

Unable to cast object of type 'System.DirectoryServices.AccountManagement.GroupPrincipal' to type 'System.DirectoryServices.AccountManagement.UserPrincipal'.

(This is on my workplace network by the way).

Now if I go to the application folder and run the .exe.... it works.

So my question is: what is it about the "run after install" method that's making this happen and how can I fix it?

I've tried almost every corner of the internet but cant get my head around this and many other solutions haven't worked.

I've tried solutions from this SO post with no luck.

I've tried getting the email address from outlook instead but I get a different error (which doesnt happen during debug or from clicking the .exe).

Steve
  • 4,372
  • 26
  • 37
  • Please post the line of code where UserPrincipal.Current.EmailAddress; is used – Muhammad Saqlain Nov 01 '19 at 05:45
  • It looks like this: string emailAddress = UserPrincipal.Current.EmailAddress; – Steve Nov 01 '19 at 05:48
  • Couple things. First, have you tried these solutions: https://forums.asp.net/t/1749954.aspx?Unable+to+cast+object+of+type+System+DirectoryServices+AccountManagement+GroupPrincipal+to+type+System+DirectoryServices+AccountManagement+UserPrincipal – IAmTimCorey Nov 01 '19 at 14:57
  • Second, it sounds like you are running under a group account for the installer, which is why it is launching in the wrong profile and causing an issue. Maybe try verifying which credentials you are running under will help. Another option is to put a logger in the code and log UserPrincipal.Current as an object (the whole object and don't cast it) to see if maybe that tells you more information. – IAmTimCorey Nov 01 '19 at 14:59

0 Answers0