Immediate custom actions don't participate in the installation/rollback
script and can't be elevated (unless you started the installation elevated
or you turned off UAC). They also may have run before the part of the
deferred script that actually writes the file to disk runs. All custom
actions that change machine state should be run deferred and have
accompanying rollback and remove (with its own rollback) actions. You can
set impersonation on if the action is to run as the user instead of as
LocalSystem.

Is your action setup to set just the local user's code access security
policy or are you intending to set it on that assembly for the entire
machine?

-----Original Message-----
From: Ericsson, Robert [mailto:rerics...@vestapartners.com] 
Sent: Monday, September 21, 2009 1:47 PM
To: wix-users@lists.sourceforge.net
Subject: [WiX-users] registering an assembly with caspol

Hello,

I'm creating an installer for an Office Add-in that uses some .NET
components which requires changes in CASPOL. I've had some success creating
the code groups using CASPOL in a custom action based on some code that I
found for installing Office Add-ins using the Visual Studio Installer
builder. I can get the add-in to work from my WiX installer if I just trust
the entire installation folder. However, I cannot get the assembly to load
during the install to apply security policy just to the assembly that needs
it.

The specific line it fails on is:

AssemblyName assemblyName = Assembly.LoadFile(assemblyPath).GetName();

The error message is:

System.Reflection.TargetInvocationException: Exception has been thrown by
the target of an invocation. ---> System.Exception: Cannot create the
security code group 'PMXA'. ---> System.IO.FileNotFoundException: The system
cannot find the file specified. (Exception from HRESULT: 0x80070002)
   at System.Reflection.Assembly.nLoadFile(String path, Evidence evidence)
   at System.Reflection.Assembly.LoadFile(String path)
   at CasCustomAction.CustomActions.AddSecurityPolicy(Boolean
machinePolicyLevel, String solutionCodeGroupName, String
solutionCodeGroupDescription, String assemblyPath, String
assemblyCodeGroupName, String assemblyCodeGroupDescription, Session session)
   --- End of inner exception stack trace ---
   at CasCustomAction.CustomActions.AddSecurityPolicy(Boolean
machinePolicyLevel, String solutionCodeGroupName, String
solutionCodeGroupDescription, String assemblyPath, String
assemblyCodeGroupName, String assemblyCodeGroupDescription, Session session)
   at CasCustomAction.CustomActions.SetCas(Session session)
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object
arguments, SignatureStruct& sig, MethodAttributes methodAttributes,
RuntimeTypeHandle typeOwner)
   at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object
arguments, Signature sig, MethodAttributes methodAttributes,
RuntimeTypeHandle typeOwner)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags
invokeAttr, Binder binder, Object parameters, CultureInfo culture, Boolean
skipVisibilityChecks)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags
invokeAttr, Binder binder, Object parameters, CultureInfo culture)
   at
Microsoft.Deployment.WindowsInstaller.CustomActionProxy.InvokeCustomAction(I
nt32 sessionHandle, String entryPoint, IntPtr remotingDelegatePtr)

The assembly path used in the custom action looks correct to me and I've
tested that the built assembly can load properly outside of the custom
action.

The relevant snippets of WIX are the following:

<Fragment>
    <CustomAction Id='SetCas' BinaryKey='CasCustomAction' DllEntry='SetCas'
Execute='immediate'
                  Return='check'/>
    <CustomAction Id='RemoveCas' BinaryKey='CasCustomAction'
DllEntry='RemoveCas' Execute='immediate'
                  Return='check'/>
    <Binary Id='CasCustomAction'
SourceFile='$(var.SolutionDir)CasCustomAction\bin\$(var.CasCustomAction.Conf
iguration)\CasCustomAction.CA.dll'/>

</Fragment>
...
<InstallExecuteSequence>
      <Custom Action='SetCas' Before='InstallFinalize'>NOT
Installed</Custom>
      <Custom Action='RemoveCas' Before='InstallFinalize'>Installed AND NOT
UPGRADINGPRODUCTCODE</Custom>
</InstallExecuteSequence>

First, is there a better way to do CASPOL registration for a .NET assembly?
Second, any ideas on the error I'm encountering? Should I run the custom
action at a different step in the installer?

After I get this fixed, I'll have a much better installer than the crazy
spaghetti generated by Visual Studio. :)

Thanks.
Rob


----------------------------------------------------------------------------
--
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
WiX-users mailing list
WiX-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wix-users


------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
WiX-users mailing list
WiX-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wix-users

Reply via email to