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:
<SPAN class="keyword token">public</SPAN> <SPAN class="keyword token">class</SPAN> <SPAN class="token class-name">SomeExtension</SPAN> <SPAN class="punctuation token">:</SPAN> IExtension
<SPAN class="punctuation token">{</SPAN>
<SPAN class="token preprocessor">#region COM Registration Function(s)</SPAN>
<SPAN class="punctuation token">[</SPAN>ComRegisterFunction<SPAN class="punctuation token">]</SPAN>
<SPAN class="punctuation token">[</SPAN><SPAN class="token function">ComVisible</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">false</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="keyword token">private</SPAN> <SPAN class="keyword token">static</SPAN> <SPAN class="keyword token">void</SPAN> <SPAN class="token function">RegisterFunction</SPAN><SPAN class="punctuation token">(</SPAN>Type registerType<SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="token function">ArcGISCategoryRegistration</SPAN><SPAN class="punctuation token">(</SPAN>registerType<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="punctuation token">[</SPAN>ComUnregisterFunction<SPAN class="punctuation token">]</SPAN>
<SPAN class="punctuation token">[</SPAN><SPAN class="token function">ComVisible</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">false</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="keyword token">private</SPAN> <SPAN class="keyword token">static</SPAN> <SPAN class="keyword token">void</SPAN> <SPAN class="token function">UnregisterFunction</SPAN><SPAN class="punctuation token">(</SPAN>Type registerType<SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="token function">ArcGISCategoryUnregistration</SPAN><SPAN class="punctuation token">(</SPAN>registerType<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="token preprocessor">#region ArcGIS Component Category Registrar generated code</SPAN>
<SPAN class="comment token">/// <summary></SPAN>
<SPAN class="comment token">/// Required method for ArcGIS Component Category registration -</SPAN>
<SPAN class="comment token">/// Do not modify the contents of this method with the code editor.</SPAN>
<SPAN class="comment token">/// </summary></SPAN>
<SPAN class="keyword token">private</SPAN> <SPAN class="keyword token">static</SPAN> <SPAN class="keyword token">void</SPAN> <SPAN class="token function">ArcGISCategoryRegistration</SPAN><SPAN class="punctuation token">(</SPAN>Type registerType<SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">string</SPAN> regKey <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">string</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="token function">Format</SPAN><SPAN class="punctuation token">(</SPAN>CultureInfo<SPAN class="punctuation token">.</SPAN>InvariantCulture<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}"</SPAN><SPAN class="punctuation token">,</SPAN> registerType<SPAN class="punctuation token">.</SPAN>GUID<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
MxExtension<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Register</SPAN><SPAN class="punctuation token">(</SPAN>regKey<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="comment token">/// <summary></SPAN>
<SPAN class="comment token">/// Required method for ArcGIS Component Category unregistration -</SPAN>
<SPAN class="comment token">/// Do not modify the contents of this method with the code editor.</SPAN>
<SPAN class="comment token">/// </summary></SPAN>
<SPAN class="keyword token">private</SPAN> <SPAN class="keyword token">static</SPAN> <SPAN class="keyword token">void</SPAN> <SPAN class="token function">ArcGISCategoryUnregistration</SPAN><SPAN class="punctuation token">(</SPAN>Type registerType<SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">string</SPAN> regKey <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">string</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="token function">Format</SPAN><SPAN class="punctuation token">(</SPAN>CultureInfo<SPAN class="punctuation token">.</SPAN>InvariantCulture<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}"</SPAN><SPAN class="punctuation token">,</SPAN> registerType<SPAN class="punctuation token">.</SPAN>GUID<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
MxExtension<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Unregister</SPAN><SPAN class="punctuation token">(</SPAN>regKey<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="token preprocessor">#endregion</SPAN>
<SPAN class="token preprocessor">#endregion</SPAN>
<SPAN class="comment token">// ...</SPAN>
<SPAN class="keyword token">void</SPAN> IExtension<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Startup</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">ref</SPAN> <SPAN class="keyword token">object</SPAN> initializationData<SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="comment token">// ...</SPAN>
<SPAN class="keyword token">var</SPAN> application <SPAN class="operator token">=</SPAN> initializationData <SPAN class="keyword token">as</SPAN> IApplication<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">bool</SPAN> initialized <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">true</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">var</SPAN> applicationStatus <SPAN class="operator token">=</SPAN> Application <SPAN class="keyword token">as</SPAN> IApplicationStatus<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>applicationStatus <SPAN class="operator token">!=</SPAN> <SPAN class="keyword token">null</SPAN><SPAN class="punctuation token">)</SPAN>
initialized <SPAN class="operator token">=</SPAN> applicationStatus<SPAN class="punctuation token">.</SPAN>Initialized<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">var</SPAN> applicationStatusEvents <SPAN class="operator token">=</SPAN> Application <SPAN class="keyword token">as</SPAN> IApplicationStatusEvents_Event<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>applicationStatusEvents <SPAN class="operator token">!=</SPAN> <SPAN class="keyword token">null</SPAN> <SPAN class="operator token">&&</SPAN> <SPAN class="operator token">!</SPAN>initialized<SPAN class="punctuation token">)</SPAN>
applicationStatusEvents<SPAN class="punctuation token">.</SPAN>Initialized <SPAN class="operator token">+</SPAN><SPAN class="operator token">=</SPAN> ApplicationInitialized<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">else</SPAN>
<SPAN class="token function">ApplicationInitialized</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="comment token">// ...</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="keyword token">private</SPAN> <SPAN class="keyword token">void</SPAN> <SPAN class="token function">ApplicationInitialized</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="comment token">// ...</SPAN>
<SPAN class="keyword token">var</SPAN> gpUtilities <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN>IGPUtilities3<SPAN class="punctuation token">)</SPAN>Activator<SPAN class="punctuation token">.</SPAN><SPAN class="token function">CreateInstance</SPAN><SPAN class="punctuation token">(</SPAN>Type<SPAN class="punctuation token">.</SPAN><SPAN class="token function">GetTypeFromCLSID</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">typeof</SPAN><SPAN class="punctuation token">(</SPAN>GPUtilitiesClass<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>GUID<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
IGPParameter gpParameter <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">GPParameterClass</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
gpUtilities<SPAN class="punctuation token">.</SPAN><SPAN class="token function">PackGPValue</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">DEFeatureClassClass</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> gpParameter<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">// This line causes Metadata tools are broken</SPAN>
<SPAN class="comment token">// ...</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="comment token">// ...</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>Steps to reproduce the problem:
- open ArcMap with closed or folded (not pinned) ArcToolbox window;
- open AcrToolbox;
- now all tools from the Metadata toolset are broken (they have red cross icon and cannot be opened and executed).
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?