Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Suggested answer

Dynamics 365: Plugin error : System.Text.StringBuilder.FormatError()

Posted on by 459

Hi I created a plugin to add Multi Select Option set in Dynamics Portals. I followed the this link to create plugin. 

powerusers.microsoft.com/.../433804

I used visual studio 4.7.2 to create the plugin. SDK 9.X version. i was able to compile the code successfully. when i tried to register the plugin i am getting the following error. Please advice me what i need to do to fix this error. (code snippet available at the bottom of the page )

Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: An unexpected error occurred.

Detail: <OrganizationServiceFault xmlns="">schemas.microsoft.com/.../Contracts" xmlns:i="">www.w3.org/.../XMLSchema-instance">

  <ActivityId>09ac7f47-4b9d-4644-adba-66adbda8bb1b</ActivityId>

  <ErrorCode>-2147220970</ErrorCode>

  <ErrorDetails xmlns:a="">schemas.datacontract.org/.../System.Collections.Generic">

    <KeyValuePairOfstringanyType>

      <a:key>ApiExceptionSourceKey</a:key>

      <a:value i:type="b:string" xmlns:b="">www.w3.org/.../a:value>

    </KeyValuePairOfstringanyType>

    <KeyValuePairOfstringanyType>

      <a:key>ApiOriginalExceptionKey</a:key>

      <a:value i:type="b:string" xmlns:b="">www.w3.org/.../XMLSchema">Microsoft.Crm.CrmException: An unexpected error occurred. ---&gt; System.FormatException: Input string was not in a correct format.

   at System.Text.StringBuilder.FormatError()

   at System.Text.StringBuilder.AppendFormatHelper(IFormatProvider provider, String format, ParamsArray args)

   at System.String.FormatHelper(IFormatProvider provider, String format, ParamsArray args)

   at System.String.Format(IFormatProvider provider, String format, Object arg0, Object arg1)

   at Microsoft.Crm.ObjectModel.TargetFrameworkVersionValidator.ValidateInternal()

   at Microsoft.Crm.ObjectModel.PluginValidatorBase.Validate()

   at Microsoft.Crm.ObjectModel.PluginAssemblyServiceInternal`1.ValidateAssemblyMetadata(ExecutionContext context, IBusinessEntity pluginAssembly, CrmPluginAssemblyMetadata assemblyMetadata)

   at Microsoft.Crm.ObjectModel.PluginAssemblyServiceInternal`1.VerifyRegistrationAbility(IBusinessEntity pluginAssembly, Boolean createCall, ExecutionContext context, CrmPluginAssemblyMetadata assemblyMetadata)

   at Microsoft.Crm.ObjectModel.PluginAssemblyServiceInternal`1.ValidateOperation(String operationName, IBusinessEntity entity, ExecutionContext context)

   at Microsoft.Crm.ObjectModel.SdkEntityServiceBase.CreateInternal(IBusinessEntity entity, ExecutionContext context, Boolean verifyAction)

   --- 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.&lt;&gt;c__DisplayClass3_0.&lt;RunStep&gt;b__0()</a:value>

    </KeyValuePairOfstringanyType>

    <KeyValuePairOfstringanyType>

      <a:key>ApiStepKey</a:key>

      <a:value i:type="b:guid" xmlns:b="">schemas.microsoft.com/.../a:value>

    </KeyValuePairOfstringanyType>

    <KeyValuePairOfstringanyType>

      <a:key>ApiDepthKey</a:key>

      <a:value i:type="b:int" xmlns:b="">www.w3.org/.../a:value>

    </KeyValuePairOfstringanyType>

    <KeyValuePairOfstringanyType>

      <a:key>ApiActivityIdKey</a:key>

      <a:value i:type="b:guid" xmlns:b="">schemas.microsoft.com/.../a:value>

    </KeyValuePairOfstringanyType>

    <KeyValuePairOfstringanyType>

      <a:key>ApiPluginSolutionNameKey</a:key>

      <a:value i:type="b:string" xmlns:b="">www.w3.org/.../a:value>

    </KeyValuePairOfstringanyType>

    <KeyValuePairOfstringanyType>

      <a:key>ApiStepSolutionNameKey</a:key>

      <a:value i:type="b:string" xmlns:b="">www.w3.org/.../a:value>

    </KeyValuePairOfstringanyType>

    <KeyValuePairOfstringanyType>

      <a:key>ApiExceptionCategory</a:key>

      <a:value i:type="b:string" xmlns:b="">www.w3.org/.../a:value>

    </KeyValuePairOfstringanyType>

    <KeyValuePairOfstringanyType>

      <a:key>ApiExceptionMesageName</a:key>

      <a:value i:type="b:string" xmlns:b="">www.w3.org/.../a:value>

    </KeyValuePairOfstringanyType>

    <KeyValuePairOfstringanyType>

      <a:key>ApiExceptionHttpStatusCode</a:key>

      <a:value i:type="b:int" xmlns:b="">www.w3.org/.../a:value>

    </KeyValuePairOfstringanyType>

  </ErrorDetails>

  <HelpLink>go.microsoft.com/.../

  <Message>An unexpected error occurred.</Message>

  <Timestamp>2020-07-02T16:36:59.2857131Z</Timestamp>

  <ExceptionRetriable>false</ExceptionRetriable>

  <ExceptionSource i:nil="true" />

  <InnerFault>

    <ActivityId>09ac7f47-4b9d-4644-adba-66adbda8bb1b</ActivityId>

    <ErrorCode>-2147220970</ErrorCode>

    <ErrorDetails xmlns:a="">schemas.datacontract.org/.../System.Collections.Generic" />

    <HelpLink i:nil="true" />

    <Message>System.FormatException: Input string was not in a correct format.

   at System.Text.StringBuilder.FormatError()

   at System.Text.StringBuilder.AppendFormatHelper(IFormatProvider provider, String format, ParamsArray args)

   at System.String.FormatHelper(IFormatProvider provider, String format, ParamsArray args)

   at System.String.Format(IFormatProvider provider, String format, Object arg0, Object arg1)

   at Microsoft.Crm.ObjectModel.TargetFrameworkVersionValidator.ValidateInternal()

   at Microsoft.Crm.ObjectModel.PluginValidatorBase.Validate()

   at Microsoft.Crm.ObjectModel.PluginAssemblyServiceInternal`1.ValidateAssemblyMetadata(ExecutionContext context, IBusinessEntity pluginAssembly, CrmPluginAssemblyMetadata assemblyMetadata)

   at Microsoft.Crm.ObjectModel.PluginAssemblyServiceInternal`1.VerifyRegistrationAbility(IBusinessEntity pluginAssembly, Boolean createCall, ExecutionContext context, CrmPluginAssemblyMetadata assemblyMetadata)

   at Microsoft.Crm.ObjectModel.PluginAssemblyServiceInternal`1.ValidateOperation(String operationName, IBusinessEntity entity, ExecutionContext context)

   at Microsoft.Crm.ObjectModel.SdkEntityServiceBase.CreateInternal(IBusinessEntity entity, ExecutionContext context, Boolean verifyAction): Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #7BF06A8E</Message>

    <Timestamp>2020-07-02T16:36:59.2857131Z</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>

 

Server stack trace:

   at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)

   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)

   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)

   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

 

Exception rethrown at [0]:

   at Microsoft.Crm.Tools.Libraries.RegistrationHelper.RegisterAssembly(CrmOrganization org, String pathToAssembly, CrmPluginAssembly assembly)

   at Microsoft.Crm.Tools.AssemblyRegistration.PluginRegistrationViewModel.btnregisterClick()

==============

Code snipit:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Extensions;

// plugin help to add multiple option set in the portal site.

namespace UpdateSubscriptionPlugin
{
public class Subscription_MultiOptionSetFieldUpdate:IPlugin
{

public void Execute(IServiceProvider serviceProvider)
{
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

Entity entity = (Entity)context.InputParameters["Target"];

ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));

// try
// {
if (entity.Attributes.ContainsKey("agri_interestedprovincesterritoriesportal"))
{
OptionSetValueCollection colours = new OptionSetValueCollection();
string[] array = entity.GetAttributeValue<String>("agri_interestedprovincesterritoriesportal").Split(',');
for (int i = 0; i < array.Length; i++)
{
string option = array[i];
colours.Add(new OptionSetValue(int.Parse(option)));
}

entity["agri_interestedprovince"] = colours;
}

// }catch(Exception ex)
// {
// tracingService.Trace("Subscription_MultiOptionSetFieldUpdate Plugin exception: {0}", ex.ToString());
// throw;

// }


}

}
}

  • Suggested answer
    RE: Dynamics 365: Plugin error : System.Text.StringBuilder.FormatError()

    Thanks for letting us know. Actually I meant 4.6.2 and not 4.5.2

  • SivaR Profile Picture
    SivaR 459 on at
    RE: Dynamics 365: Plugin error : System.Text.StringBuilder.FormatError()

    Thank you, Miguel,

    I resolved the issue as below.

    I created the plugin for Dynamics 365. it is required SDK 9.0 or higher.

    SDK 9.0 required V4.6.2  .Net framework version.

    Therefor I added V4.6.2 .Net framework to visual studio 2019  (it was missing in Visual Studio 2019)

    To add: Windows -> Search -> Visual Studio Installer -> Modify -> Individual Components and check the right version (v4.6.2)

    After choosing V4.6.2 .Net for Target framework in Visual Studio and build. I was successfully register the plugin .

    Regards,

    SivaR

  • Suggested answer
    RE: Dynamics 365: Plugin error : System.Text.StringBuilder.FormatError()

    Hi, please use 4.5.2 .NET

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans