WaelHamze / xrm-ci-framework

xRM CI Framework provides you with the tools automate the build and deployment of your CRM Solution. Using the framework to implement a fully automated DevOps pipeline will allow you to deploy more frequently with added consistency and quality.
MIT License
186 stars 116 forks source link

MSCRM Plugin Registration: Object reference not set to instance of an object. #214

Open devzesh opened 5 years ago

devzesh commented 5 years ago

Hi Wael,

We are having this issue when using MSCRM Plugin Registration task and this issue is happening while trying to register "Create" step for plugin assembly.

2019-05-21_14-36-41 2019-05-21_14-37-00

Is it possible to get more details to understand the error cause?

Thanks, Zeshan

devzesh commented 5 years ago

@WaelHamze Can you please update on this?

thanks..

WaelHamze commented 5 years ago

@devmzeshan please set system.debug = true and share the logs

devzesh commented 5 years ago

@WaelHamze Apologies for the delayed response, I have attached the logs. ReleaseLogs_63.zip

devzesh commented 5 years ago

@WaelHamze any updates on this?

strwase commented 4 years ago

I seem to experience a similar issue. the registration seems to work tough. plugin assembly, plugin and the step get registered, but it still throws an exception.

`##[debug]Caught exception from task script.

[debug]Error record:

[debug]Set-XrmPluginRegistration : Object reference not set to an instance of an object.

[debug]At C:\Agent_work\tools\MSCRMBuildTools\9.1.2\xRMCIFramework\9.0.0\PluginRegistration.ps1:40 char:1

[debug]+ Set-XrmPluginRegistration -RegistrationType $RegistrationType -Assemb ...

[debug]+ ~~~~~~~~~~~~~~~~~

[debug] + CategoryInfo : NotSpecified: (:) [Set-XrmPluginRegistration], NullReferenceException

[debug] + FullyQualifiedErrorId : System.NullReferenceException,Xrm.Framework.CI.PowerShell.Cmdlets.SetXrmPluginRegistrati on

[debug]

[debug]Script stack trace:

[debug]at , C:\Agent_work\tools\MSCRMBuildTools\9.1.2\xRMCIFramework\9.0.0\PluginRegistration.ps1: line 40

[debug]at , C:\Agent_work_tasks\MSCRMPluginRegistration_a48708ef-a5d6-4af5-a9be-589847132834\11.0.1\MSCRMPluginRegistration.ps1: line 38

[debug]at , : line 1

[debug]at , : line 22

[debug]at , : line 18

[debug]at , : line 1

[debug]Exception:

[debug]System.NullReferenceException: Object reference not set to an instance of an object.

[debug] at Xrm.Framework.CI.Common.PluginRegistrationHelper.UpsertPluginTypeAndSteps(Guid parentId, Type pluginType, String solutionName, RegistrationTypeEnum registrationType)

[debug] at Xrm.Framework.CI.PowerShell.Cmdlets.SetXrmPluginRegistration.ProcessRecord()

[debug] at System.Management.Automation.CommandProcessor.ProcessRecord()

`

improving-jeffd commented 4 years ago

I am actually just having troubles figuring out how to generate the plugin mapping file. There doesn't seem to be any documentation around this, although I did find the schema and a sample json so I guess I'll manually build it.

PS @devmzeshan Just wanted to highlight that your password is in your logs, if you haven't already changed it.

strwase commented 4 years ago

@qdi-jeffd, you can only generate a schema based on an existing registration. You can do that with the power shell cmdlets. But for new registrations, you'll have to create the mapping manually

WaelHamze commented 4 years ago

@qdi-jeffd If you have plug-ins in your environment already. You can use this script to generate the mapping file.

https://github.com/WaelHamze/dyn365-ce-devops-sample/blob/master/Sample/Xrm.CI.Framework.Sample/Xrm.CI.Framework.Sample.Plugins/GetPluginRegistration.ps1

I see many users generate the steps etc.. using plug-in registration tool in env and then generate a json from that.

You can also do this manually if you like and if you are familiar with the object model. You can link your mapping file to this schema file in visual studio which will give you some intellisense

https://github.com/WaelHamze/xrm-ci-framework/blob/master/MSDYNV9/Xrm.Framework.CI/Xrm.Framework.CI.Common/PluginRegistration/PluginRegistrationSchema.json

WaelHamze commented 4 years ago

@strwase can you share the mapping file?

I am specifically interested in what is in the mapping file after this step and how is this different than previous steps.

2019-06-24T06:34:28.6261028Z ##[debug]Upsert SdkMessageProcessingStep 7c18d1a2-1b3a-4e89-990b-d2d1d8ed43bf completed

strwase commented 4 years ago

Hi @WaelHamze,

here is the mappingfile i'm using.

{ "$schema": "./PluginRegistrationSchema.json", "Id": "{9e9d9681-b7b5-46a4-8c45-77a4f56a6a95}", "Name": "Norriq.Crm.Codipack.Plugins.dll", "IsolationMode": "Sandbox", "SourceType": "Database", "PluginTypes": [ { "Id": "{8876e445-d064-4b0f-84ec-4d9932cb5983}", "Name": "Norriq.Crm.Codipack.Plugins.QuotePropertyTemplate.CopyTemplateQuestions: Create of nrq_quotepropertiestemplate", "FriendlyName": "0d6cf174-4b19-437a-ac51-9ba0c4c37cab", "TypeName": "Norriq.Crm.Codipack.Plugins.QuotePropertyTemplate.CopyTemplateQuestions", "Steps": [ { "Id": "{c4a291af-33b9-4802-8ffa-5ed99187c9b5}", "Name": "Norriq.Crm.Codipack.Plugins.QuotePropertyTemplate.CopyTemplateQuestions: Create of nrq_quotepropertiestemplate", "MessageName": "Create", "PrimaryEntityName": "nrq_quotepropertiestemplate", "Mode": "Synchronous", "Stage": "Postoperation", "SupportedDeployment": "ServerOnly", "StateCode": "Enabled", "Rank": 1, "AsyncAutoDelete": false } ] } ] }

as far as I can tell, the step registration completes, but then an exception get thrown from somewhere.

`##[debug]Upsert SdkMessageProcessingStep c4a291af-33b9-4802-8ffa-5ed99187c9b5 completed

[debug]Caught exception from task script.

[debug]Error record:

[debug]Set-XrmPluginRegistration : Object reference not set to an instance of an object.

[debug]At C:\Agent_work\tools\MSCRMBuildTools\9.1.2\xRMCIFramework\9.0.0\PluginRegistration.ps1:40 char:1

[debug]+ Set-XrmPluginRegistration -RegistrationType $RegistrationType -Assemb ...

`

improving-jeffd commented 4 years ago

@WaelHamze I do have an existing plugin that I am trying to automate deployment of. I cannot get that script to work for my environment it seems though. I am connecting to an organization on D365 and if I use the url of the organization I get the following:

The service '/XRMServices/2011/Discovery.svc' cannot be activated due to an exception during compilation. The exception message is: Could not load file or assembly 'Microsoft.Crm.Site.Services.

Which a little research shows for that for D365 I need to use the discovery url, but providing that isn't working either. The error I get when I switch to the disco url is: Unable to login to Dynamics CRM, Error was : clientCredentials.UserName.UserName or clientCredentials.Windows.ClientCredential.UserName MUST be populated!

I have been providing the credentials though. I started building the mapping file manually, but it would be great to figure out what I am doing wrong to generate it via the script. Edit: I am providing the connection string as follows (security obfuscated): CrmConnectionString="AuthType=Office365;UserName=user@domain.ca;password=PASSWORD;url=https://disco.crm3.dynamics.com/XRMServices/2011/Discovery.svc;"

Thanks!

improving-jeffd commented 4 years ago

I still am having no luck with getting the script to generate my mapping file. I was able to get a connection string formatted that works through XrmToolBox (turns out some of the issues I was having were due to federated security on my account and MFA). Using an App registration and client secret I can get xrmtoolkit connecting, but not the powershell script. I am getting the error I mentioned above about Microsoft.Crm.Site.Services even when I use the disco url.

With a manually created partial mapping file (just did the first plugin and step). I get to the same point as the other two users here and get the Object reference error.

Any help you can give is appreciated. If it helps to know more about our environments to see what is common I am running the plugin registration through a pipeline in Azure DevOps On prem. The build agents run on Windows Server, I could grab some other versions if needed but Power Shell is on version 5.1.14409.1018.

Edit: It is probably worth noting that in my case I am editing a previously working pipeline that was/is deploying a managed solution prior to the plugin registration step.

improving-jeffd commented 4 years ago

@strwase @devmzeshan FYI In my case it turned out to be bad json for the plugins. Specifically that I had put "Images": null Instead of "Images": []

As the specific plugin that I was testing with did not have images for any of it's steps.

I still cannot generate the json file though.

Jeff

tklooster commented 4 years ago

Try copying your plugin dll to your script folder where you are running. I was getting a blank json file generated before I did this. Works great now.