Problems with deployment at end user

Why doesnt this code work when the msi.file is installed on the enduser machine. Nothing happens, while when run as 'Debug' in VS development environment everything works. All this code does is displaying a messagebox when Outlook is started. The project is made with VSTO and nothing in the setup project is tampered with, ie keys and such are intact. Help please!

in ThisApplication.cs:

private void ThisApplication_Startup(object sender, System.EventArgs e)
{
MessageBox.Show("Frustration");
}

in Installer.cs:

public class Installer : System.Configuration.Install.Installer
{

public Installer()
{
}

public override void Install(System.Collections.IDictionary stateSaver)
{
base.Install(stateSaver);

try
{
ConfigureSecurityPolicy();
}
catch (Exception ex)
{
throw new System.Configuration.Install.InstallException("Custom Installer Failed", ex);
}
}

public override void Uninstall(System.Collections.IDictionary savedState)
{
base.Uninstall(savedState);

try
{
DeleteSecurityPolicy();
}
catch (Exception ex)
{
throw new System.Configuration.Install.InstallException("Custom Installer Failed", ex);
}
}

private void ConfigureSecurityPolicy()
{
//Find the machine policy level
PolicyLevel machinePolicyLevel = GetMachinePolicyLevel();

//Get the install directory of the current installer
string assemblyPath = this.Context.Parameters["assemblypath"];
string installDirectory =
assemblyPath.Substring(0, assemblyPath.LastIndexOf("\\"));

if (!installDirectory.EndsWith(@"\"))
installDirectory += @"\";

installDirectory += "*";

//Create the code group
CodeGroup codeGroup = new UnionCodeGroup(
new UrlMembershipCondition(installDirectory),
new PolicyStatement(new NamedPermissionSet("FullTrust")));
codeGroup.Description = "hej och ha";
codeGroup.Name = "hej och ha";

//Add the code group
machinePolicyLevel.RootCodeGroup.AddChild(codeGroup);

// Save changes
SecurityManager.SavePolicy();
}

private static void DeleteSecurityPolicy()
{
PolicyLevel machinePolicy = GetMachinePolicyLevel();

foreach (CodeGroup codeGroup in machinePolicy.RootCodeGroup.Children)
{
if (codeGroup.Name == "hej och ha")
machinePolicy.RootCodeGroup.RemoveChild(codeGroup);
}

SecurityManager.SavePolicy();
}

private static PolicyLevel GetMachinePolicyLevel()
{
System.Collections.IEnumerator policyHierarchy = SecurityManager.PolicyHierarchy();

while (policyHierarchy.MoveNext())
{
PolicyLevel level = (PolicyLevel)policyHierarchy.Current;
if (level.Type == PolicyLevelType.Machine)
return level;
}

throw new ApplicationException("Could not find Machine Policy level. Code Access Security is not configured for this application.");
}
}


Answer this question

Problems with deployment at end user

  • ahr

    Please check that the add-in is properly installed and is not "blacklisted" by Outlook. You can click at Help/About Microsoft Office Outlook/Disabled Items...

    Alternatively, you can check HKLM\Software\Microsoft\Office\Outlook\Addins\LoadBehavior and HKCU\Software\Microsoft\Office\Outlook\Addins\LoadBehavior. The value should be 3.

    HTH,

    iouri

    ---

    This posting is provided AS-IS and confers no rights


  • MMMSobo

    Hi,

    Make sure all neccessary prerequisites (.NET 2.0, VSTOR, PIAs and Office 2003) are installed on the client computer.



  • T.Satish Kumar

    The dependency files don't take care of the prerequisites. When you run the program in debug mode, VS takes care of CAS policy and you have all prerequisites installed on your development computer. Looks like the prerequisites aren't installed on deployment computer.

    There is a solution for deploying prerequisites with setup project (http://weblogs.asp.net/mnissen/archive/2005/10/26/428564.aspx), also I suggest you read these two articles on MSDN:



  • Goye

    Thank you iouri,

    HKEY_CURRENT_USER\Software\Microsoft\Office\Outlook\Addins\HelloWorldAddin2\Load behaviour is 3

    machine /loadbehaviour is not set.

    The addin isnt blacklisted.

    It still doesnt wok :/

    HELP!

  • KRosenvold

    In the setup project, all the dependency files are marked as included. How does that work Arent they supposed to ensure that all the required dll's are in place Also, right now if I run the program in debug everything works fine, but when i install and run it doesnt work. "error when loading com"

    ...thx for help

  • dwith

    Also, in the tools/options/other/advanced/com add-inns/ it says that there is a run-time error in the com object....Strange, cause it works when run from Visual studio.

    Perplexed :P

  • Problems with deployment at end user