scottdurow / SparkleXrm

An open-source library for building Dynamics CRM XRM solutions using Script#, jQuery & Knockoutjs.
MIT License
265 stars 197 forks source link

NullReferenceException when registering plugin to a CustomApi #434

Open christoph-burker opened 3 years ago

christoph-burker commented 3 years ago

When trying to register an empty plugin (throwing a NotImplementedException) to an existing Custom Api I created through the XrmToolBox with spkl v.1.0.634-beta (Nuget) I receive following error.

Deploying Plugins
Searching for plugin config in 'C:\_git\----.Dataverse.CustomApi\spkl\..'
Using Config 'C:\_git\----.Dataverse.CustomApi'
Checking assembly '----.Dataverse.CustomApi.dll' for plugins
1 plugin(s) found!
The application terminated with an error.
Object reference not set to an instance of an object.
   at SparkleXrm.Tasks.Reflection.<>c.<GetAttributes>b__4_2(CrmPluginRegistrationAttribute s)
   at System.Linq.Lookup`2.Create[TSource](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
   at System.Linq.GroupedEnumerable`3.GetEnumerator()
   at System.Linq.Enumerable.<SelectManyIterator>d__17`2.MoveNext()
   at System.Linq.Enumerable.Count[TSource](IEnumerable`1 source)
   at SparkleXrm.Tasks.Reflection.GetAttributes(IEnumerable`1 types, String attributeName)
   at SparkleXrm.Tasks.PluginRegistraton.RegisterAssembly(FileInfo assemblyFilePath, Assembly assembly, IEnumerable`1 pluginTypes, Boolean isWorkflowActivity)
   at SparkleXrm.Tasks.PluginRegistraton.RegisterPlugin(String file, Boolean excludePluginSteps)
   at SparkleXrm.Tasks.DeployPluginsTask.DeployPlugins(OrganizationServiceContext ctx, ConfigFile config)
   at SparkleXrm.Tasks.DeployPluginsTask.ExecuteInternal(String folder, OrganizationServiceContext ctx)
   at SparkleXrm.Tasks.BaseTask.Execute(String folder)
   at SparkleXrmTask.Program.RunTask(CommandLineArgs arguments, IOrganizationService service, ITrace trace)
   at SparkleXrmTask.Program.Run(CommandLineArgs arguments)
   at SparkleXrmTask.Program.Main(String[] args)
Error Code=1

I tried builing from code from spkl-v1.0.633 from the GitHub repo and it registered the plugin just fine. The Custom API was callable from the ToolBox. The same error is thrown when trying to register with 1.0.633 from Nuget.

The plugin getting registered is nothing more than this:

namespace ----.Dataverse.CustomApi
{
    [CrmPluginRegistration("new_TestApi")]
    public class Class1Api : IPlugin
    {
        public void Execute(IServiceProvider serviceProvider)
        {
            throw new NotImplementedException();
        }
    }
}

Offtopic: Will there be extended Custom API support, as in, will API Request / Response configs be programmatically registered by spkl in the near future?

christoph-burker commented 3 years ago

Nevermind, it seems the deploy script chose an old spkl.exe version that was still lying about in the packages folder. Is it really a good idea to just take the first version the script finds? This seems kind of arbitrary and error-prone.

EDIT: As the scripts get redeployed with Nuget updates, they could be extended with a version check and at least output a warning when the exe is taken from an older / a different version.