Search code examples
azuredynamics-crmilmerge

Dynamics 365/ Microsoft.ServiceBus DLL - System.Security.SecurityException: That assembly does not allow partially trusted callers


Dynamics 365 version 8.2.24.23

We want to send messages from Dynamics 365 to the Azure Service Bus. To do this we merged microsoft.servicebus.dll into the main DLL through ilmerge. When we invoke the DLL through a custom workflow activity we get the exception below.

Is there anyway around the partially trusted caller issue? As a workaround, we can call the Azure Service Bus via the REST API but we'd prefer not to do that.

System.Security.SecurityException: That assembly does not allow partially trusted callers.

at Microsoft.ServiceBus.Messaging.MessagingFactorySettings..ctor() at Microsoft.ServiceBus.Messaging.Configuration.KeyValueConfigurationManager.CreateFactory(IEnumerable1 endpoints, IEnumerable1 stsEndpoints, IEnumerable1 viaEndpoints, String operationTimeout, String issuerName, String issuerKey, String sasKeyName, String sasKey, String sasToken, String windowsDomain, String windowsUser, SecureString windowsPassword, String oauthDomain, String oauthUser, SecureString oauthPassword, String transportType, String enableAmqpLinkRedirect, String amqpSecurityScheme) at Microsoft.ServiceBus.Messaging.Configuration.KeyValueConfigurationManager.GetOrUpdateFactory(IEnumerable1 endpoints, IEnumerable1 stsEndpoints, IEnumerable1 viaEndpoints, String operationTimeout, String issuerName, String issuerKey, String sasKeyName, String sasKey, String sasToken, String windowsDomain, String windowsUser, SecureString windowsPassword, String oauthDomain, String oauthUser, SecureString oauthPassword, String transportType, String enableAmqpLinkRedirect, String amqpSecurityScheme) at Microsoft.ServiceBus.Messaging.Configuration.KeyValueConfigurationManager.CreateMessagingFactory(Boolean useCachedFactory) at Microsoft.ServiceBus.Messaging.MessagingFactory.CreateFromConnectionString(String connectionString, Boolean useCache) at Microsoft.ServiceBus.Messaging.TopicClient.CreateFromConnectionString(String connectionString, String path)


Solution

  • Dynamics 365 custom workflow assemblies are deployed in a partially trusted environment (i.e. sandbox). The assembly you are referencing unfortunately requires a full trust environment. Your option will be to consume the REST API.

    Here is a similar scenario, where a SharePoint assembly is referenced but requires full trust:

    ILMerge with CRM plugin and Sharepoint Online

    I'm assuming you are using Dynamics 365 Online. Note that in an on premise implementation, you can deploy custom workflow assemblies outside of the sandbox environment.