I'm building an ArcMap extension. In its Startup method I subscribe to IApplicationStatusEvents.Initialized event. In handler of this event I use some methods of GPUtilities class:
public class SomeExtension : IExtension
{
#region COM Registration Function(s)
[ComRegisterFunction]
[ComVisible(false)]
private static void RegisterFunction(Type registerType)
{
ArcGISCategoryRegistration(registerType);
}
[ComUnregisterFunction]
[ComVisible(false)]
private static void UnregisterFunction(Type registerType)
{
ArcGISCategoryUnregistration(registerType);
}
#region ArcGIS Component Category Registrar generated code
/// <summary>
/// Required method for ArcGIS Component Category registration -
/// Do not modify the contents of this method with the code editor.
/// </summary>
private static void ArcGISCategoryRegistration(Type registerType)
{
string regKey = string.Format(CultureInfo.InvariantCulture, "HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}", registerType.GUID);
MxExtension.Register(regKey);
}
/// <summary>
/// Required method for ArcGIS Component Category unregistration -
/// Do not modify the contents of this method with the code editor.
/// </summary>
private static void ArcGISCategoryUnregistration(Type registerType)
{
string regKey = string.Format(CultureInfo.InvariantCulture, "HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}", registerType.GUID);
MxExtension.Unregister(regKey);
}
#endregion
#endregion
// ...
void IExtension.Startup(ref object initializationData)
{
// ...
var application = initializationData as IApplication;
bool initialized = true;
var applicationStatus = Application as IApplicationStatus;
if (applicationStatus != null)
initialized = applicationStatus.Initialized;
var applicationStatusEvents = Application as IApplicationStatusEvents_Event;
if (applicationStatusEvents != null && !initialized)
applicationStatusEvents.Initialized += ApplicationInitialized;
else
ApplicationInitialized();
// ...
}
private void ApplicationInitialized()
{
// ...
var gpUtilities = (IGPUtilities3)Activator.CreateInstance(Type.GetTypeFromCLSID(typeof(GPUtilitiesClass).GUID));
IGPParameter gpParameter = new GPParameterClass();
gpUtilities.PackGPValue(new DEFeatureClassClass(), gpParameter); // This line causes Metadata tools are broken
// ...
}
// ...
}
Steps to reproduce the problem:
But if on the first step you open ArcMap with opened and shown ArcToolbox then everything is fine, Metadata tools are valid and can be executed. If I comment line #74 in the code snippet above then everything is fine too. It seems that GPUtilities must be used only after ArcToolbox is shown.
This strange behavior started to appear with ArcMap 10.4. So 10.4, 10.4.1 and 10.5 has this problem. In 10.3.1 all is OK. I believe that this is bug on ArcGIS side, so I really hope that it will be fixed.
I didn't find any workaround for this issue. Maybe with 10.4.1 I need to execute some magic code before I can use GPUtilities so Metadata tools will not be broken?
Have you fired this off to ESRI support, my impression is they don't do any thing until it is reported through the support line?