<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic VB.Net custom tool crashes ArcMap in ArcObjects SDK Questions</title>
    <link>https://community.esri.com/t5/arcobjects-sdk-questions/vb-net-custom-tool-crashes-arcmap/m-p/437790#M11853</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm trying to implement a custom tool for an add-in.&amp;nbsp; I inserted the following snippet, which works fine:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim UIDCls As ESRI.ArcGIS.esriSystem.UID = New ESRI.ArcGIS.esriSystem.UIDClass()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ' id property of menu from Config.esriaddinx document&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; UIDCls.Value = "esriArcMapUI.ZoomInTool" &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim commandItem As ESRI.ArcGIS.Framework.ICommandItem = TryCast(document.CommandBars.Find(UIDCls), ESRI.ArcGIS.Framework.ICommandItem)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If commandItem Is Nothing Then&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Exit Sub&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End If&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; My.ArcMap.Application.CurrentTool = commandItem &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I then added a custom tool:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Add New Item&amp;gt;ArcGis&amp;gt;Extending ArcObjects&amp;gt;Base Tool. I called it (default) Tool1.vb.&amp;nbsp; It created a module allowing me to add code for mouse events, along with some COM GUIDs.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;When I try to replace the UIDCls value above (esriArcMapUI.ZoomInTool) to refer to my custom tool, Arcmap will crash.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;My project is called VBNET_Test, so I've tried referring to my tool as VBNET_Test.Tool1, VBNET_Test_Tool1; also tried giving the tool a MyBase.m_name and referring to that as Tool1_[m_name].&amp;nbsp; Everything I do causes ArcMap to crash.&amp;nbsp; The only way I can get ArcMap to continue, (to the Exit Sub line, because the tool's not recognized - CommandItem=nothing) is by adding the classID in the tool module ("{513f6529-78cf-4913-a86d-058985bbf4ed}").&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My tool is not on a toolbar/command bar - but I've read others' experiences stating that this is not necessary.&amp;nbsp; I don't want it on a toolbar.&amp;nbsp; In my VBA project I had to have the tool on a toolbar.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Potentially related is my selection of disabling Com interop in the main project properties.&amp;nbsp; If I enable it I get an error and the code won't compile.&amp;nbsp; The error states:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Error 1 Cannot register assembly "C:\Users\Computer\Documents\Visual Studio 2008\Projects\VBNet_Test\VBNet_Test\bin\Debug\VBNet_Test.dll". Could not load file or assembly 'ESRI.ArcGIS.Desktop.AddIns, Version=10.0.0.0, Culture=neutral, PublicKeyToken=8fc3cc631e44ad86' or one of its dependencies. The system cannot find the file specified. VBNet_Test&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any help would be greatly appreciated.&amp;nbsp; I'm trying to migrate a huge VBA project over to VB.net- some things seem really easy but this has me stumped.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 03 Jun 2011 16:26:09 GMT</pubDate>
    <dc:creator>KevinAndras</dc:creator>
    <dc:date>2011-06-03T16:26:09Z</dc:date>
    <item>
      <title>VB.Net custom tool crashes ArcMap</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/vb-net-custom-tool-crashes-arcmap/m-p/437790#M11853</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm trying to implement a custom tool for an add-in.&amp;nbsp; I inserted the following snippet, which works fine:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim UIDCls As ESRI.ArcGIS.esriSystem.UID = New ESRI.ArcGIS.esriSystem.UIDClass()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ' id property of menu from Config.esriaddinx document&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; UIDCls.Value = "esriArcMapUI.ZoomInTool" &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim commandItem As ESRI.ArcGIS.Framework.ICommandItem = TryCast(document.CommandBars.Find(UIDCls), ESRI.ArcGIS.Framework.ICommandItem)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If commandItem Is Nothing Then&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Exit Sub&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End If&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; My.ArcMap.Application.CurrentTool = commandItem &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I then added a custom tool:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Add New Item&amp;gt;ArcGis&amp;gt;Extending ArcObjects&amp;gt;Base Tool. I called it (default) Tool1.vb.&amp;nbsp; It created a module allowing me to add code for mouse events, along with some COM GUIDs.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;When I try to replace the UIDCls value above (esriArcMapUI.ZoomInTool) to refer to my custom tool, Arcmap will crash.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;My project is called VBNET_Test, so I've tried referring to my tool as VBNET_Test.Tool1, VBNET_Test_Tool1; also tried giving the tool a MyBase.m_name and referring to that as Tool1_[m_name].&amp;nbsp; Everything I do causes ArcMap to crash.&amp;nbsp; The only way I can get ArcMap to continue, (to the Exit Sub line, because the tool's not recognized - CommandItem=nothing) is by adding the classID in the tool module ("{513f6529-78cf-4913-a86d-058985bbf4ed}").&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My tool is not on a toolbar/command bar - but I've read others' experiences stating that this is not necessary.&amp;nbsp; I don't want it on a toolbar.&amp;nbsp; In my VBA project I had to have the tool on a toolbar.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Potentially related is my selection of disabling Com interop in the main project properties.&amp;nbsp; If I enable it I get an error and the code won't compile.&amp;nbsp; The error states:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Error 1 Cannot register assembly "C:\Users\Computer\Documents\Visual Studio 2008\Projects\VBNet_Test\VBNet_Test\bin\Debug\VBNet_Test.dll". Could not load file or assembly 'ESRI.ArcGIS.Desktop.AddIns, Version=10.0.0.0, Culture=neutral, PublicKeyToken=8fc3cc631e44ad86' or one of its dependencies. The system cannot find the file specified. VBNet_Test&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any help would be greatly appreciated.&amp;nbsp; I'm trying to migrate a huge VBA project over to VB.net- some things seem really easy but this has me stumped.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 03 Jun 2011 16:26:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/vb-net-custom-tool-crashes-arcmap/m-p/437790#M11853</guid>
      <dc:creator>KevinAndras</dc:creator>
      <dc:date>2011-06-03T16:26:09Z</dc:date>
    </item>
    <item>
      <title>Re: VB.Net custom tool crashes ArcMap</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/vb-net-custom-tool-crashes-arcmap/m-p/437791#M11854</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;have you tried steppping through your code to see the line it crashes on?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;if you haven't already done it; i suggest putting a breakpoint into your code very early (before it bombs) and then use the "step into" tool to go through line by line and figuring out specifically where it is breaking.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Jun 2011 18:11:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/vb-net-custom-tool-crashes-arcmap/m-p/437791#M11854</guid>
      <dc:creator>maxsteinbrenner</dc:creator>
      <dc:date>2011-06-06T18:11:41Z</dc:date>
    </item>
    <item>
      <title>Re: VB.Net custom tool crashes ArcMap</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/vb-net-custom-tool-crashes-arcmap/m-p/437792#M11855</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;try/catch blocks.&amp;nbsp; Any code which handles events, such as create, click or in the class constructor (new), mouse down, etc. should have try catch blocks.&amp;nbsp; You can pop the exception in a message box or write it to the trace.&amp;nbsp; It should help you to figure out what is wrong and hopefully prevent arcmap from crashing.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Jun 2011 19:44:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/vb-net-custom-tool-crashes-arcmap/m-p/437792#M11855</guid>
      <dc:creator>AlexanderGray</dc:creator>
      <dc:date>2011-06-06T19:44:17Z</dc:date>
    </item>
    <item>
      <title>Re: VB.Net custom tool crashes ArcMap</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/vb-net-custom-tool-crashes-arcmap/m-p/437793#M11856</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Yes, I've done that. If I give the Clas ID ({513f6529-78cf-4913-a86d-058985bbf4ed}) then CommandItem ends up as Nothing and the code exits, without implementing my tool. If I tell it anything else (i.e. VBNET_Test.Tool1, VBNET_Test_Tool1, etc) Arc will crash on the same line:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;UIDCls.Value = {whatever}&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Jun 2011 19:46:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/vb-net-custom-tool-crashes-arcmap/m-p/437793#M11856</guid>
      <dc:creator>KevinAndras</dc:creator>
      <dc:date>2011-06-06T19:46:07Z</dc:date>
    </item>
    <item>
      <title>Re: VB.Net custom tool crashes ArcMap</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/vb-net-custom-tool-crashes-arcmap/m-p/437794#M11857</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;If I catch the exception, this is the error message:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;{"Value does not fall within the expected range."}&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Jun 2011 21:38:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/vb-net-custom-tool-crashes-arcmap/m-p/437794#M11857</guid>
      <dc:creator>KevinAndras</dc:creator>
      <dc:date>2011-06-13T21:38:48Z</dc:date>
    </item>
    <item>
      <title>Re: VB.Net custom tool crashes ArcMap</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/vb-net-custom-tool-crashes-arcmap/m-p/437795#M11858</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I changed the UID value to this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;uid.Value = My.ThisAddIn.IDs.[tool name]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;and it seems to be the active tool, though the click events aren't registering.&amp;nbsp; And the UID that the local variable watch displays is not anywhere else in my code.&amp;nbsp; Perhaps it's making it up on the fly and not connecting to my code for what the tool is supposed to do.&amp;nbsp; And, once that tool is activated, I can't change tools to anything else.&amp;nbsp; For example I'll click on the Zoom Out Tool button and nothing happens.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Jun 2011 16:44:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/vb-net-custom-tool-crashes-arcmap/m-p/437795#M11858</guid>
      <dc:creator>KevinAndras</dc:creator>
      <dc:date>2011-06-14T16:44:13Z</dc:date>
    </item>
    <item>
      <title>Re: VB.Net custom tool crashes ArcMap</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/vb-net-custom-tool-crashes-arcmap/m-p/437796#M11859</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I've figured out how to do this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Project &amp;gt; New Item &amp;gt; ArcGIS &amp;gt; Desktop Add-ins &amp;gt; Add-in Component &amp;gt; Tool&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In the code module for the tool, you can add things like&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Protected Overrides Sub OnMouseUp(ByVal arg As ESRI.ArcGIS.Desktop.AddIns.Tool.MouseEventArgs)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; msgbox("Mouse up! You are at X = " &amp;amp; arg.X &amp;amp; " and Y = " &amp;amp; arg.Y)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;End Sub&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;And to call the tool, you do this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim uid As UID = New ESRI.ArcGIS.esriSystem.UIDClass&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; uid.Value = My.ThisAddIn.IDs.[toolname]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim commandItem As ESRI.ArcGIS.Framework.ICommandItem = TryCast(document.CommandBars.Find(uid), ESRI.ArcGIS.Framework.ICommandItem)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; My.ArcMap.Application.CurrentTool = commandItem&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 22 Jun 2011 18:25:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/vb-net-custom-tool-crashes-arcmap/m-p/437796#M11859</guid>
      <dc:creator>KevinAndras</dc:creator>
      <dc:date>2011-06-22T18:25:14Z</dc:date>
    </item>
    <item>
      <title>Re: VB.Net custom tool crashes ArcMap</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/vb-net-custom-tool-crashes-arcmap/m-p/437797#M11860</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank K_Andras works a charm!!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Mar 2012 10:19:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/vb-net-custom-tool-crashes-arcmap/m-p/437797#M11860</guid>
      <dc:creator>DaleHarris</dc:creator>
      <dc:date>2012-03-14T10:19:21Z</dc:date>
    </item>
  </channel>
</rss>

