You know you are having one of those days when even doing something simple like registering a plugin in Dynamics365 doesn’t work. Its something I have done literally thousands of times before and everything seemed to look ok until I pressed the Register Selected Plugins button in the registration tool. I had written the plugin myself, it was really simple, it loaded with no issues in the registration tool, I could see the function in the assembly correctly, Sandbox was selected as was database but each time it failed to register.
It was driving me nuts.
I checked the code, everything was public that needed to be, the assembly was signed but still no luck.
The error I got was : unexpected error occurred. —> System.FormatException: Input string was not in a correct format.
<a:value i:type="b:string" xmlns:b="http://www.w3.org/2001/XMLSchema">Microsoft.Crm.CrmException: An unexpected error occurred. ---> 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.<>c__DisplayClass3_0.<RunStep>b__0()</a:value>
Not very helpful, there are no input strings and I am not trying to format them.
Finally I worked it out, when I had created the project for the plugin in Visual Studio I just accepted the defaults of Dot Net 4.7.2. I added the relevant components for Dynamics365 in NuGet and ignored the fact that they are only Dot Net 4.6.2 assemblies, and carried on writing code.
That was the problem, as of 30th May 2020 nothing higher than Dot Net 4.6.2 is supported in the cloud, so an easy fix is to make sure the target version of your assembly is correct and recompile.
After that it registered first time.
Result.