Loading assemblies and/or snapins

Nov 19, 2012 at 6:55 PM
Edited Nov 19, 2012 at 6:55 PM

I'm trying to author a workflow that will add or update appointments in an end user's exchange calendar. I have it working fine from the command line, but I'm running up against a brick wall trying to execute it from within a workflow. 

Here's the lines that should be loading EWS:

$EWSManagedPath = "\\SERVER\EWS\1.2.1\Microsoft.Exchange.WebServices.dll"
[void][Reflection.Assembly]::LoadFrom($EWSManagedPath);

I've tried to use both UNC path and file path (C:\EWS...) with no luck.

When I try to run this I get the following error:

 

System.Management.Automation.CmdletInvocationException: Could not load file or assembly 'Microsoft.Exchange.WebServices, Version=14.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. Failed to grant permission to execute. (Exception from HRESULT: 0x80131418) ---> System.IO.FileLoadException: Could not load file or assembly 'Microsoft.Exchange.WebServices, Version=14.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. Failed to grant permission to execute. (Exception from HRESULT: 0x80131418)  File name: 'Microsoft.Exchange.WebServices, Version=14.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' ---> System.Security.Policy.PolicyException: Execution permission cannot be acquired.     at System.Security.SecurityManager.ResolvePolicy(Evidence evidence, PermissionSet reqdPset, PermissionSet optPset, PermissionSet denyPset, PermissionSet& denied, Boolean checkExecutionPermission)     at System.Security.SecurityManager.ResolvePolicy(Evidence evidence, PermissionSet reqdPset, PermissionSet optPset, PermissionSet denyPset, PermissionSet& denied, Int32& securitySpecialFlags, Boolean checkExecutionPermission)     at System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)     at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)     at System.Reflection.Assembly.LoadFrom(String assemblyFile)     at Microsoft.PowerShell.Commands.AddTypeCommand.LoadAssemblyFromPathOrName(List`1 generatedTypes)     at Microsoft.PowerShell.Commands.AddTypeCommand.EndProcessing()     at System.Management.Automation.CommandProcessorBase.Complete()         --- End of inner exception stack trace ---     at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input, Hashtable errorResults, Boolean enumerate)     at System.Management.Automation.PipelineNode.Execute(Array input, Pipe outputPipe, ArrayList& resultList, ExecutionContext context)     at System.Management.Automation.StatementListNode.ExecuteStatement(ParseTreeNode statement, Array input, Pipe outputPipe, ArrayList& resultList, ExecutionContext context)

 

I'm not sure where to go from here. Is this a "you can't get there from here" scenario or am I missing something basic.

Thanks!

Steve