<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>COM on Marko Apfel</title><link>http://blog.marko-apfel.de/tags/com/</link><description>Recent content in COM on Marko Apfel</description><generator>Hugo</generator><language>en-US</language><lastBuildDate>Fri, 25 Nov 2011 14:10:00 +0100</lastBuildDate><atom:link href="http://blog.marko-apfel.de/tags/com/index.xml" rel="self" type="application/rss+xml"/><item><title>Interop effects by resolving and instantiating types with ArcObjects</title><link>http://blog.marko-apfel.de/posts/interop-effects-by-resolving-and-instantiating-types-with-arcobjects/</link><pubDate>Fri, 25 Nov 2011 14:10:00 +0100</pubDate><guid>http://blog.marko-apfel.de/posts/interop-effects-by-resolving-and-instantiating-types-with-arcobjects/</guid><description>&lt;h2 id="problem"&gt;Problem&lt;/h2&gt;
&lt;p&gt;this code does not work&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-cs" data-lang="cs"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;Type&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;typeof&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ESRI&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ArcGIS&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Framework&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;AppRefClass&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Object&lt;/span&gt; &lt;span class="n"&gt;obj&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Activator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;CreateInstance&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;but yet this code&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-cs" data-lang="cs"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;Type&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Type&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;GetTypeFromCLSID&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ESRI&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ArcGIS&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Framework&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;AppRefClass&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;GUID&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Object&lt;/span&gt; &lt;span class="n"&gt;obj&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Activator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;CreateInstance&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id="reason"&gt;Reason&lt;/h2&gt;
&lt;p&gt;In the first variant the runtime tries to cast to &lt;code&gt;AppRefClass&lt;/code&gt;. This is not possible.&lt;/p&gt;
&lt;p&gt;And in the second one, the runtime does not knows anything about &lt;code&gt;AppRefClass&lt;/code&gt;. So it leave it as &lt;code&gt;IUnknown&lt;/code&gt;.&lt;/p&gt;</description></item><item><title>"Failure has occurred while loading a type."</title><link>http://blog.marko-apfel.de/posts/failure-has-occurred-while-loading-a-type/</link><pubDate>Fri, 28 Oct 2011 12:08:00 +0200</pubDate><guid>http://blog.marko-apfel.de/posts/failure-has-occurred-while-loading-a-type/</guid><description>&lt;h2 id="motivation"&gt;Motivation&lt;/h2&gt;
&lt;p&gt;During programming suddenly this error (&lt;code&gt;Failure has occurred while loading a type&lt;/code&gt;) was thrown by accessing a artifact of a referenced library.&lt;/p&gt;
&lt;p&gt;In such cases I take the assembly fusion logger &lt;em&gt;fuslogvw&lt;/em&gt; to search for problems of loading assemblies. Sometimes an old version from a not expected folder is binded. But all bindings were correct.&lt;/p&gt;</description></item><item><title>Calling esriRegasm manually (outside an ArcGIS-installation)</title><link>http://blog.marko-apfel.de/posts/calling-esriregasm-manually-outside-an-arcgis-installation/</link><pubDate>Tue, 26 Apr 2011 20:53:00 +0200</pubDate><guid>http://blog.marko-apfel.de/posts/calling-esriregasm-manually-outside-an-arcgis-installation/</guid><description>&lt;p&gt;Since &lt;em&gt;ArcGIS 10&lt;/em&gt; during the &lt;em&gt;Visual Studio&lt;/em&gt; build an additional target with the execution of a program named &lt;code&gt;esriRegasm&lt;/code&gt; is called. Amongst other things this program adds the COM-categories in the registry.&lt;/p&gt;</description></item><item><title>Set ApartmentState for ArcObjects-logic in separate threads</title><link>http://blog.marko-apfel.de/posts/set-apartmentstate-for-arcobjects-logic-in-separate-threads/</link><pubDate>Wed, 08 Sep 2010 10:54:00 +0200</pubDate><guid>http://blog.marko-apfel.de/posts/set-apartmentstate-for-arcobjects-logic-in-separate-threads/</guid><description>&lt;h2 id="problem-context"&gt;Problem context&lt;/h2&gt;
&lt;p&gt;We use a &lt;code&gt;backgroundworker&lt;/code&gt; to load &lt;code&gt;.MXD&lt;/code&gt; documents from several places of the system and extract meta data and thumbnails which a GUI component shows in an asynchronous way.&lt;/p&gt;
&lt;p&gt;The unit tests for this logic throws an exception during the access the thumbnail:&lt;/p&gt;</description></item><item><title>Verwenden von partiellen Klassen für COM-Belange</title><link>http://blog.marko-apfel.de/posts/verwenden-von-partiellen-klassen-fur-com-belange/</link><pubDate>Mon, 12 Jul 2010 15:16:00 +0200</pubDate><guid>http://blog.marko-apfel.de/posts/verwenden-von-partiellen-klassen-fur-com-belange/</guid><description>&lt;h2 id="motivation"&gt;Motivation&lt;/h2&gt;
&lt;p&gt;Schon im Whitepaper „Auszeichnung von COM-Kategorien an .NET-Klassen mittels Attributen und deren Verwendung für Setup-Builds“ [1] habe ich deutlich gemacht warum das Verwenden von COM-Registrierungsfunktionen ein suboptimales Programmierpattern ist. Knackpunkt sind die Verstöße gegen SOC (separation of concerns) [2] und SRP (single responsibility principle) [3].&lt;/p&gt;</description></item><item><title>Catching COM-Exceptions from ArcObjects</title><link>http://blog.marko-apfel.de/posts/catching-com-exceptions-from-arcobjects/</link><pubDate>Tue, 20 Oct 2009 14:36:00 +0200</pubDate><guid>http://blog.marko-apfel.de/posts/catching-com-exceptions-from-arcobjects/</guid><description>&lt;p&gt;to catch the COM-Exception in own applications thrown from the underlaying ArcObjects-Library could be done with:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-cs" data-lang="cs"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;COMException&lt;/span&gt; &lt;span class="n"&gt;ComEx&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;MyCode errored: {0}, Error Code: {1}&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;ComEx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Message&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ComEx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ErrorCode&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;the special error constants could be found under:&lt;/p&gt;</description></item></channel></rss>