Tuesday, July 21, 2009

Cannot Delete/Publish changes in a Custom/System Entity

Hi all,

for quite some time I was struggling with this issue :

Neither we were able to publish changes to a custom entity nor the system allowing us to delete it. while doing so we get the general popup error from that says "An error has occured." We were able to publish updates to all other entities. Also we could add or delete other custom entities.

Another thing that Custom entities have their own custom icons when you click on them and go into the Form or looking at an attribute. For these entities, there's just a red X. I didn't delete any files but still no icons were displayed while other custom entities that work display the icons just fine.

after enabling the trace we found this in trace log :

[NullReferenceException: Object reference not set to an instance of an object.] at Microsoft.Crm.ObjectModel.OrganizationUIService.LabelLoaderAllLanguages.LoadMetadataLabel(Int32 entityType, String attributeName, ExecutionContext context) at Microsoft.Crm.ObjectModel.OrganizationUIService.LabelLoader.LoadCellLabel(Guid cellObjectId, String cellObjectColumnName, Int32 objectType, String attributeName, ExecutionContext context) at Microsoft.Crm.ObjectModel.OrganizationUIService.InsertFormLabels(IBusinessEntity entity, ILabelLoader labelLoader, ExecutionContext context) at Microsoft.Crm.ObjectModel.OrganizationUIService.RetrieveMultipleWithAllLanguages(EntityExpression entityExpression, ExecutionContext context) at Microsoft.Crm.Metadata.OrganizationUIHelper.RetrieveInProductionHelper(Int32 objectTypeCode, ExecutionContext context) at Microsoft.Crm.Tools.ImportExportPublish.FormXmlHandler.ExportItem(XmlDocument importDocument) 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(String[] ExportEntities, String[] ExportRoles, String[] ExportWorkflows, ExportMask Mask) at Microsoft.Crm.Tools.ImportExportPublish.ExportXml.RunExport(String xmlArgs, XmlDocument& ExportDoc) at Microsoft.Crm.WebServices.ExportXmlService.ExportCompressed(String entities, String embeddedFileName, ExecutionContext context) [TargetInvocationException: Exception has been thrown by the target of an invocation.] at Microsoft.Crm.Application.Utility.Util.RaiseXMLError(Exception exception) at Microsoft.Crm.Dialogs.ExportCustomizationsPage.ConfigureForm() at Microsoft.Crm.Application.Controls.AppUIPage.OnPreRender(EventArgs e) at System.Web.UI.Control.PreRenderRecursiveInternal() at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) [HttpUnhandledException: Exception of type 'System.Web.HttpUnhandledException' was thrown.] at System.Web.UI.Page.HandleError(Exception e) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest() at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) at System.Web.UI.Page.ProcessRequest(HttpContext context) at ASP.cot_puritech__grid_cmds_dlg_exportcustomizations_aspx.ProcessRequest(HttpContext context) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

After a long search i zeroed in to these posts:



In the first post the solution provided by André M Mestre
"This is normally caused by a missing attribute or a missing label:
[NullReferenceException: Object reference not set to an instance of an object.] at Microsoft.Crm.ObjectModel.OrganizationUIService.LabelLoaderAllLanguages.LoadMetadataLabel

So to solve this you need to go directly to your database and check in the XML of the forms and views and the XML of the entity and then find out if all the attributes that you can see in there are still viewable in the CRM UI. If not you should correct the XML and then update the database.
The XML for the Form is in the OrganizationUIBase table and you can also check the XML for the views in the UserQueryBase and in the SavedQueryBase.

This is unsupported by Microsoft but is the only solution I know for this kind of issues.
Also please note that correcting the XML might be tricky sometimes."

with the help of the above mentioned solution I checked the Form XML in OrganizationUIBase table and figured out that there was an atribute in the Form XML that was actually deleted from the entity and after that i exported the entity from our staging server to the production server. I still dont know why the entity attribute was there in the form? and if the attribute was there in the form then why the system allowed me to delete the attribute ?

but anyways after recreating the attribute in the entity everything started working properly. it now allows me to publish the changes and even deleting the entity.

hope this will help someone else too.


Eric said...


Somehow the email entity ended up in this same state where I could not delete or publish any changes to it.

Editing the form XML did the trick. There was a tab section defined but had nothing in it. Removing this did the trick.

A side note: You can easily find all your custom changes by searching for


in the xml - this will make it easier.

TravellerDan said...

Awesome thanks very much.

For me I found that I previously had a custom lookup against case called feees_originatorid (display name: Originator) and that we had replaced that deleted relationship with another custom relationship called feees_contactid (display name: Originator). [Probably without publishing in between, I'd guess?!]

The form wasn't loading correctly in design view and wouldn't publish, export or import.

I used the following command to sort it via SQL (although unsupported):

View form items for my entity:
SELECT * FROM OrganizationBaseUI WHERE formxml like '%name="incident"%'

Grabbed the formidunique value (not the formid) and ran:
UPDATE OrganizationBaseUI SET formxml = REPLACE(formxml,'feees_originatorid','feees_contactid') WHERE FormIdUnique = '(enter the formidunique GUID from your investigations here)'

In my case it was the form which was set to InProduction = 1 which needed updating.

Now I can export, Import, Publish with no issues.

I hope this helps someone else!

Graham Lower said...

I know this is an old issue, but ran into a similar problem. Here is a query to help discover customize production forms who have attributes that have since been deleted:

Form.value( '(/forms/entity/@name)[1]', 'nvarchar(max)' ) AS Entity, Ui.DataField.value( '.', 'nvarchar(max)' ) AS DataField
SELECT *, CONVERT(xml, [FormXml]) AS Form
FROM [dbo].[OrganizationUIBase]
WHERE [InProduction]= 1 AND [CustomizationLevel] > 0
) AS Data
Form.nodes( '//@datafieldname' ) AS UI(DataField)
SELECT entity.name, Attribute.Name
FROM [MetadataSchema].[Attribute]
ON Attribute.EntityId = Entity.EntityId;

Recreating the attribute allowed for publishing and export of the form. We removed the reference on the form and then removed recreated attribute. All was happy.