I encountered this error when trying to export the solution from Dev environment. There was little information in the exception or the log file, but I could guess that something had been deleted and it didn’t update the MetadataCache (or the solution) somehow.
After googling, I found the solution is to delete the attribute/component from the CRM solution.
private static void RemoveComponentFromSolution(IOrganizationService service, Guid componentId, int componentType, string solutionName)
{
RemoveSolutionComponentRequest removeRequest = new RemoveSolutionComponentRequest()
{
// this is the Guid you have found within your Dynamics 365 trace files
ComponentId = componentId,
ComponentType = componentType,
// This is the unique name, not the display name of the solution you are trying to export
SolutionUniqueName = solutionName
};
var response = service.Execute(removeRequest);
}
The component type can be retrieved using FetchXML
<fetch top="50" >
<entity name="solutioncomponent" >
<all-attributes/>
<filter type="and" >
<condition attribute="objectid" operator="eq" value="component guid here" />
</filter>
</entity>
</fetch>