Are your best practices out of date?

Today’s ‘best practices’ lead to dead ends; the best paths are new and untried. Peter Thiel

The best practices we use today are built on historic environments, they are past practices that were previously successful.

As environments change, best practices should adapt and update. Best practices are not static, they evolve and improve to take advantage of new thinking, technology and environments.

Updating best practices is difficult because people have been successful using those best practices. People like to use familiar processes and in times of pressure will fall back on what they know.

This brings resistance to change. Even when best practices become less effective, it’s difficult to move on from them and embrace new best practices or a new approach.

Project methodology

Project methodologies offer an interesting example. Waterfall projects were the accepted way to deliver IT projects. Agile methodologies appeared and gained popularity until customers were demanding projects are Agile..

Old best practices linger on and Waterfall projects are still happening. Some people change and warn that Waterfall is dead (yet it lives it on)

Waterfall project management is dead

I see Agile is regularly pronounced dead (yet I keep working on Agile projects :-))

Agile software development is dead. Deal with it

Projects are a good example of past best practices being used. Individuals have had good, bad or indifferent experiences of Agile projects and this influences their choice of future projects. We should decide project methodology based on the project, people and the culture, not what was successful on previous projects with different circumstances.

Dynamics 365 CE

The best practices in creating solutions and delivering projects in Dynamics 365 have changed over the last 5 years.

  • Dynamics projects moved from on Premise to cloud
  • Worksflow will be replaced by PowerAutomate (so stop creating workflows)
  • Long running processes using to C# applications running on a server are replaced by Azure functionality (Azure Functions, Logic Apps)
  • Cognitive services have replaced custom code
  • Code has been replaced with no code and low code.
  • Big monolith Dynamics solutions have been replaced by small focused PowerApps, Dynamics apps and everything is connected.

The changes above shows the speed of change and the influence of Azure and the PowerPlatform. The previous best practices, skills and knowledge have been replaced and the people who thrive are the ones who adapt to the new environment.

What should you do

Best practices could still be the best way to do things but it’s important you are open to improving them and don’t blindly implement them. IT is changing at rates quicker than in the past. How you delivered a project and the solution you create today won’t be the same as the project you deliver in 2 years time.

Technology will change and the best practices need to change with it. Question the best practices being implemented, keep learning to see if you can implement new ones.

The past should be respected but the future should be embraced. Don’t waste time fighting the past but focus on creating a better future. Change is an opportunity to make things better. Best practices might not be best practices in the new environment, so question them and look for better practices.

This quote “best practice is, by definition, past practice” came from this article — A framework for decision making, please read it

 

Dynamics 365 – Error when exporting a solution

If debugging is the process of removing software bugs, then programming must be the process of putting them in. Edsger Dijkstra

 

I got an error message when the ALM tool was exporting an unmanaged solution from an environment and packaging it up before deploying it.

The ALM tool sometimes errors but usually around data. This problem needed more thinking to resolve it because I wasn’t sure the cause and I hadn’t seen it before.

When I’m not sure of the cause, I remember this quote

If I had an hour to solve a problem, I’d spend 55 minutes thinking about the problem and 5 minutes thinking about solutions — Albert Einstein

Before I solve a problem, I ask myself some questions.

  • What did I know about the deployment?
  • What are the facts?
  • What assumptions I am making?

Think before action, create a plan and execute

When debugging, eliminate what isn’t causing the problem and whatever code or customization is left must be the culprit. #HoskWisdom

The error message

The error message was my best lead, here it is

Unhandled exception:

Exception type: System.ServiceModel.FaultException`1[Microsoft.Xrm.Sdk.OrganizationServiceFault]

Message: An unexpected error occurred.Detail:

<OrganizationServiceFault xmlns:i=”http://www.w3.org/2001/XMLSchema-instance“ xmlns=”http://schemas.microsoft.com/xrm/2011/Contracts“>

<ActivityId>cbce1d3a-44d6–47d0-b319-f082f16a71f5</ActivityId>

<ErrorCode>-2147220970</ErrorCode>

<ErrorDetails xmlns:d2p1=”http://schemas.datacontract.org/2004/07/System.Collections.Generic“>

<KeyValuePairOfstringanyType>

<d2p1:key>ApiExceptionSourceKey</d2p1:key>

<d2p1:value xmlns:d4p1=”http://www.w3.org/2001/XMLSchema“ i:type=”d4p1:string”>Plugin/Microsoft.Crm.WebServices.ExportXmlService</d2p1:value>

</KeyValuePairOfstringanyType>

<KeyValuePairOfstringanyType>

<d2p1:key>ApiOriginalExceptionKey</d2p1:key>

<d2p1:value xmlns:d4p1=”http://www.w3.org/2001/XMLSchema“ i:type=”d4p1:string”>Microsoft.Crm.CrmException: An unexpected error occurred. — -> System.IndexOutOfRangeException: Index was outside the bounds of the array.

at System.Collections.Generic.Dictionary`2.FindEntry(TKey key)

at Microsoft.Crm.Tools.ImportExportPublish.ThirdPartyComponentPropertiesProvider.GetProperties(String componentKey)

at Microsoft.Crm.Tools.ImportExportPublish.ExportHandler.GetFullUnmanagedPropertyMapForType(String itemType, Boolean managed, IComponentPropertiesProvider componentPropertiesProvider)

at Microsoft.Crm.Tools.ImportExportPublish.ExportHandler.AddXmlProperties(String itemType, XmlDocument importDocument, XmlNode parentNode, IGenericType container, Boolean managed, EntityMetadata entityMetadata, Version targetVersion, IComponentPropertiesProvider componentPropertiesProvider)

at Microsoft.Crm.Tools.Common.ImportExportPublish.EmailTemplateHandler.ExportItem(XmlDocument XDoc, XmlNode Node)

at Microsoft.Crm.Tools.ImportExportPublish.ExportHandler.Export(XmlDocument XDoc)

at Microsoft.Crm.Tools.ImportExportPublish.ExportHandler.Export(XmlDocument XDoc)

at Microsoft.Crm.Tools.ImportExportPublish.RootExportHandler.RunExport()

at Microsoft.Crm.WebServices.ExportXmlService.ExportSolutionWithTargetVersion(String solutionName, Boolean managed, String targetVersion, Boolean exportAutoNumberingSettings, Boolean exportCalendarSettings, Boolean exportCustomizationSettings, Boolean exportEmailTrackingSettings, Boolean exportGeneralSettings, Boolean exportMarketingSettings, Boolean exportOutlookSynchronizationSettings, Boolean exportRelationshipRoles, Boolean exportIsvConfig, Boolean exportSales, Boolean exportExternalApplications, ExecutionContext context)

Here are some facts

The last successful deployment 4 days ago

Did I get the latest from source control? Yes

Is this problem just happening to me? ask someone else to deploy

What was in the patch? one workflow

In the blog post — Dynamics 365 error messages point you in the right direction (yes, I read my blog posts) I got some pointers

Dynamics 365 errors point you in the right direction

To diagnose an error, look at the error with an empty mind #HoskCodeWisdom

Dynamics 365 error messages point you in the right direction but never give you the answer. developers focus on the problem, they forget to think what the error message is telling them.

Don’t assume

Don’t rush to solve a bug, before coming up with a solution, understand the problem, identify your assumptions and find out the facts. Debug the code, identify and path the code is taking and then work out what it’s supposed to do.

An example of bug investigation and how to approach fixing bugs

Sherlock Hosk and the case of the annoying bug

Approach bugs with an empty mind and don’t assume what is happening but prove what is happening.

For example –How to diagnose plugin errors in Dynamics 365 it has a good section on plugin error messages

follow these steps

  • Stop
  • Engage Brain\Think
  • What’s happening?
  • What should happen?
  • Make a list of the possible causes of the problem
  • Investigate your list

The Plan

Get someone else to deploy — they did and got the same error

Understand the key parts from the error message and see where it points us. The key parts are below.

Plugin/Microsoft.Crm.WebServices.ExportXmlService

Microsoft.Crm.CrmException: An unexpected error occurred. — -> System.IndexOutOfRangeException: Index was outside the bounds of the array

at Microsoft.Crm.Tools.Common.ImportExportPublish.EmailTemplateHandler.ExportItem(XmlDocument XDoc, XmlNode Node)

at Microsoft.Crm.Tools.ImportExportPublish.ExportHandler.Export(XmlDocument XDoc)

at Microsoft.Crm.Tools.ImportExportPublish.ExportHandler.Export(XmlDocument XDoc)

at Microsoft.Crm.Tools.ImportExportPublish.RootExportHandler.RunExport()

The errors above are saying it’s an IndexOutOfRangeException, in programming terms this means your counter has incremented (plus one) but there are no more records. e.g. you are trying to get row 10 in your index but there are only 9 rows.

The plugins are from Microsoft, note plugins the team created

EmailtemplateHander — it seems like the problem is occurring when we are exporting email templates.

I tried to export the solution from the environment and I got the same error, so the error was nothing to do with the ALM tool. It was a Microsoft problem.

I searched the internet for similar problems, but the problems were different and the solutions were different. The common theme was there was a defective customisation that needed to be removed or recreated, the solution would export after that.

My feeling at this point was somehow one of the email templates (we didn’t have any other templates) had got corrupt. There were 40 so there wasn’t any easy way to identify which one (or ones) was causing the problem. My plan was to take those email templates from another environment and import them over the top.

I tried this, and it worked, and I could go back on with my deployments. It seems easy now but at the time it didn’t make much sense.

  • Deploying a workflow shouldn’t break email templates
  • I have never seen an error when exporting a solution
  • The error message wasn’t clear and didn’t give much information on the problem.

It was a tricky problem; I wanted to share my experience, just in case you have a similar experience or are contronted with a problem you aren’t sure how to solve.