Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: Assembly can not be loaded.
Detail: <OrganizationServiceFault xmlns=/http://schemas.microsoft.com/xrm/2011/Contracts/ xmlns:i=/http://www.w3.org/2001/XMLSchema-instance/>
<ActivityId>b444e52e-c7b7-4a22-9c05-1f9f5b978234</ActivityId>
<ErrorCode>-2147200995</ErrorCode>
<ErrorDetails xmlns:a=/http://schemas.datacontract.org/2004/07/System.Collections.Generic/>
<KeyValuePairOfstringanyType>
<a:key>ApiExceptionSourceKey</a:key>
<a:value i:type=/b:string/ xmlns:b=/http://www.w3.org/2001/XMLSchema/>Plugin/Microsoft.Crm.ObjectModel.PluginTypeService</a:value>
</KeyValuePairOfstringanyType>
<KeyValuePairOfstringanyType>
<a:key>ApiOriginalExceptionKey</a:key>
<a:value i:type=/b:string/ xmlns:b=/http://www.w3.org/2001/XMLSchema/>Microsoft.Crm.CrmException: Assembly can not be loaded. ---> Microsoft.Crm.CrmException: Assembly can not be loaded.
at Microsoft.Crm.Workflow.ObjectModel.CustomActivityInfoMetadataBase.GetCustomActivityInfo(ActivityInfo activityInfo, Int32 isolationMode, Guid pluginAssemblyId)
at Microsoft.Crm.ObjectModel.PluginTypeServiceInternal`1.SetIsWorkFlowActivityAttribute(PluginType pluginTypeArg, IBusinessEntity PluginAssembly, SandboxCustomActivityInfo& customActivityInfo, CrmPluginTypeMetadata& typeMetadata, ExecutionContext Context)
at Microsoft.Crm.ObjectModel.PluginTypeServiceInternal`1.Create(IBusinessEntity entity, ExecutionContext context)
--- End of inner exception stack trace ---
at Microsoft.Crm.Extensibility.VersionedPluginProxyStepBase.Execute(PipelineExecutionContext context)
at Microsoft.Crm.Extensibility.PipelineInstrumentationHelper.Execute(Boolean instrumentationEnabled, String stopwatchName, ExecuteWithInstrumentation action, PipelineExecutionContext context)
at Microsoft.Crm.Extensibility.Pipeline.<>c__DisplayClass3_0.<RunStep>b__0()</a:value>
</KeyValuePairOfstringanyType>
<KeyValuePairOfstringanyType>
<a:key>ApiStepKey</a:key>
<a:value i:type=/b:guid/ xmlns:b=/http://schemas.microsoft.com/2003/10/Serialization//>3dcabb1b-ea3e-db11-86a7-000a3a5473e8</a:value>
</KeyValuePairOfstringanyType>
<KeyValuePairOfstringanyType>
<a:key>ApiDepthKey</a:key>
<a:value i:type=/b:int/ xmlns:b=/http://www.w3.org/2001/XMLSchema/>1</a:value>
</KeyValuePairOfstringanyType>
<KeyValuePairOfstringanyType>
<a:key>ApiActivityIdKey</a:key>
<a:value i:type=/b:guid/ xmlns:b=/http://schemas.microsoft.com/2003/10/Serialization//>b444e52e-c7b7-4a22-9c05-1f9f5b978234</a:value>
</KeyValuePairOfstringanyType>
<KeyValuePairOfstringanyType>
<a:key>ApiPluginSolutionNameKey</a:key>
<a:value i:type=/b:string/ xmlns:b=/http://www.w3.org/2001/XMLSchema/>System</a:value>
</KeyValuePairOfstringanyType>
<KeyValuePairOfstringanyType>
<a:key>ApiStepSolutionNameKey</a:key>
<a:value i:type=/b:string/ xmlns:b=/http://www.w3.org/2001/XMLSchema/>System</a:value>
</KeyValuePairOfstringanyType>
<KeyValuePairOfstringanyType>
<a:key>ApiExceptionCategory</a:key>
<a:value i:type=/b:string/ xmlns:b=/http://www.w3.org/2001/XMLSchema/>ClientError</a:value>
</KeyValuePairOfstringanyType>
<KeyValuePairOfstringanyType>
<a:key>ApiExceptionMesageName</a:key>
<a:value i:type=/b:string/ xmlns:b=/http://www.w3.org/2001/XMLSchema/>CustomActivityInvalid</a:value>
</KeyValuePairOfstringanyType>
<KeyValuePairOfstringanyType>
<a:key>ApiExceptionHttpStatusCode</a:key>
<a:value i:type=/b:int/ xmlns:b=/http://www.w3.org/2001/XMLSchema/>400</a:value>
</KeyValuePairOfstringanyType>
</ErrorDetails>
<HelpLink>http://go.microsoft.com/fwlink/?LinkID=398563&error=Microsoft.Crm.CrmException%3a8004501d&client=platform</HelpLink>
<Message>Assembly can not be loaded.</Message>
<Timestamp>2023-06-20T16:20:36.0283954Z</Timestamp>
<ExceptionRetriable>false</ExceptionRetriable>
<ExceptionSource i:nil=/true/ />
<InnerFault>
<ActivityId>b444e52e-c7b7-4a22-9c05-1f9f5b978234</ActivityId>
<ErrorCode>-2147200995</ErrorCode>
<ErrorDetails xmlns:a=/http://schemas.datacontract.org/2004/07/System.Collections.Generic/ />
<HelpLink i:nil=/true/ />
<Message>Assembly can not be loaded.</Message>
<Timestamp>2023-06-20T16:20:36.0283954Z</Timestamp>
<ExceptionRetriable>false</ExceptionRetriable>
<ExceptionSource i:nil=/true/ />
<InnerFault i:nil=/true/ />
<OriginalException i:nil=/true/ />
<TraceText i:nil=/true/ />
</InnerFault>
<OriginalException i:nil=/true/ />
<TraceText i:nil=/true/ />
</OrganizationServiceFault>
That error code by the way, when I look it up on Web service error codes: -2147200995 simply says /Invalid Custom Activity/ which is not very specific.
But if there is an error with my activity please let me know. I have posted the code below, which by the way it doesn't seem to work (when it registered successfully the first time). What this code tries to do is to make an API call to this third party company called Initium and get a standardized address. Then for testing, I want to put part of that address on some text field in the Address form of Dynamics by using a workflow. The API call part itself was tested pretty well against the Console and of course I put /CONFIDENTIAL/ where I should not expose some ids provided to me and my org. But here it is:
using System;
using System.Collections.Generic;
using RestSharp;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Xrm.Sdk.Workflow;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.Json;
using System.Text.Json.Serialization;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Converters;
using System.Globalization;
using System.Workflow;
using System.Activities;
namespace WheatonPluginDelta.Activities
{
//Main Program:
public class InstantAddress : CodeActivity
{
//For parsing Token:
public partial class TokenAcquisition
{
[JsonProperty(/Token/)]
public string Token { get; set; }
}
//For parsing Response: AddressItems is main Root, which contains a list which also constains a dict.
public partial class AddressItems
{
[JsonProperty(/InstantAddressResult/)]
public InstantAddressResult[] InstantAddressResult { get; set; }
}
public partial class InstantAddressResult
{
[JsonProperty(/StandardizedAddress/)]
public Dictionary<string, string> StandardizedAddress { get; set; }
[JsonProperty(/InstantAddressResponse/)]
public InstantAddressResponse[] InstantAddressResponse { get; set; }
}
public partial class StandardizedAddress
{
[JsonProperty(/Street1/)]
public string Street1 { get; set; }
[JsonProperty(/Street2/)]
public string Street2 { get; set; }
[JsonProperty(/Street3/)]
public string Street3 { get; set; }
[JsonProperty(/City/)]
public string City { get; set; }
[JsonProperty(/State/)]
public string State { get; set; }
[JsonProperty(/ZipCode/)]
public string ZipCode { get; set; }
[JsonProperty(/Country/)]
public string Country { get; set; }
}
public partial class InstantAddressResponse
{
[JsonProperty(/AdditionalElements/)]
public AdditionalElement[] AdditionalElements { get; set; }
}
public partial class AdditionalElement
{
[JsonProperty(/Value/)]
public string Value { get; set; }
}
[Output(/MailingLabel/)]
public OutArgument<string> MailingLabel { get; set; }
protected override void Execute(CodeActivityContext executionContext)
{
ITracingService tracingService = executionContext.GetExtension<ITracingService>();
IWorkflowContext workflowContext = executionContext.GetExtension<IWorkflowContext>();
IOrganizationServiceFactory serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();
IOrganizationService orgService = serviceFactory.CreateOrganizationService(workflowContext.UserId);
//From INITIUM software: Token acquisition
var options1 = new RestClientOptions(https://addressvalidation.initiumsoftware.com/)
{
MaxTimeout = -1,
};
var client1 = new RestClient(options1);
var request1 = new RestRequest(/api/auth/tokenacquisition/, Method.Post);
request1.AddHeader(/Content-Type/, /application/json/);
var body1 = @/ /*If you copy and paste this snippet please remember to remove comments, to avoid any issues.*// + /// +
@/ {/ + /// +
//Must input updated accesskey and Appid:
@/ //AccessKey//: //CONFIDENTIAL//,/*Key provided by Initium Software. Used in conjunction with the AppId to authenticate.*// + /// +
@/ //AppId//: //CONFIDENTIAL//,/*ID provided by Initium Software. Used in conjunction with the AccessKey to authenticate.*// + /// +
@/ //ApplicationName//: ////, /*Name generated by Initium Software.*// + /// +
@/ //ApplicationTag//: ////, /*Optional application tag generated by Client.*// + /// +
@/ //Reference1//: ////,/*Optional Reference field, maximum of 10.*// + /// +
@/ //Reference2//: ////,/*Optional Reference field, maximum of 10*// + /// +
@/ //Reference3//: ////,/*Optional Reference field, maximum of 10*// + /// +
@/ //Reference10//: /////*Optional Reference field, maximum of 10*// + /// +
@/}/;
request1.AddStringBody(body1, DataFormat.Json);
RestResponse response1 = client1.Execute(request1);
JObject tokenjson = JObject.Parse(response1.Content);
TokenAcquisition tokenAcquisition = System.Text.Json.JsonSerializer.Deserialize<TokenAcquisition>(tokenjson.ToString()); //must have jsonobject.ToString()
var token = tokenAcquisition.Token;
//Must pull address variables from CRM and assign:
string st1 = /2414 W Lexington/;
string zip = /60612/;
//From INITIUM Software Single Address Validation:
var options = new RestClientOptions(https://addressvalidation.initiumsoftware.com/)
{
MaxTimeout = -1,
};
var client = new RestClient(options);
var request = new RestRequest(/api/core/getaddress/, Method.Post);
request.AddHeader(/token/, token);
request.AddHeader(/Content-Type/, /application/json/);
var body = @/{ //Street1//: / + $/'{st1}',/
+ /// +
@/ //Street2//: ////,
/ + /// +
@/ //Street3//: ////,
/ + /// +
@/ //Street4//: ////,
/ + /// +
@/ //Street5//: ////,
/ + /// +
@/ //City//: ////,
/ + /// +
@/ //State//: ////,
/ + /// +
@/ //ZipCode//: / + $/'{zip}',/
+ /// +
@/ //Country//: //USA//,
/ + /// +
@/ ////ResponseType//://Formatted//,
/ + /// +
@/ //ResponseType//://Full//,
/ + /// +
@/ ////ResponseType//://Default//
/ + /// +
@/ ////ResponseType//://Formatted//
/ + /// +
@/ ////ResponseType//://Standardized//
/ + /// +
@/ ////IntegratorNotes//: true
/ + /// +
@/}
/ + /// +
@/
/ + /// +
@/
/ + /// +
@/ /;
request.AddStringBody(body, DataFormat.Json);
RestResponse response = client.Execute(request);
JObject addressjson = JObject.Parse(response.Content);
AddressItems addressItems = System.Text.Json.JsonSerializer.Deserialize<AddressItems>(addressjson.ToString()); //must have o.ToString()
var street1 = addressItems.InstantAddressResult[0].StandardizedAddress[/Street1/];
var street2 = addressItems.InstantAddressResult[0].StandardizedAddress[/Street2/];
var street3 = addressItems.InstantAddressResult[0].StandardizedAddress[/Street3/];
var city = addressItems.InstantAddressResult[0].StandardizedAddress[/City/];
var state = addressItems.InstantAddressResult[0].StandardizedAddress[/State/];
var zipcode = addressItems.InstantAddressResult[0].StandardizedAddress[/ZipCode/];
var country = addressItems.InstantAddressResult[0].StandardizedAddress[/Country/];
var county = addressItems.InstantAddressResult[0].InstantAddressResponse[0].AdditionalElements[18].Value;
string fulladdress = street1 + / / + street2 + / / + street3 + / / + city + / / + country + / / + state + / / + zipcode + / / + county;
//Console.Write(street1);
//Console.Read();
MailingLabel.Set(executionContext, street1.ToString());
}
}
}
Any help would be very highly appreciated.
Thank you.