Add-in; Failure to get code to execute when toolbar button pressed

2971
25
11-22-2010 06:10 AM
New Contributor III
Hi,

I had written several VBA routines up through 9.3 and have since upgraded to 10.  Since VBA will be a thing of the past in the next version, I downloaded and installed VB Express 2008 and successfully (I think) migrated the VBA to VB.Net 2008.  I saved out each of the routines to their respective *.vb files and ran the Add-In wizard for a new project, adding each routine as a button added to a toolbar.

Everything compiles and I get my toolbar to show up in ArcMap, but when I press any of the buttons, they grey out and nothing executes.  Similarly, the breakpoints I have inserted go hollow with a yellow triangle and when I hover over the breakpoint, it states that "The breakpoint will not currently be hit.  No symbols have been loaded for this document."

I think that somehow I am missing the magic of how to tie the XML stuff to the VB.Net code.  Is there any VB code that links the code back to the XML so it functions? 

Any insight is greatly appreciated.

Thanks,

Dale Bridgford
Reply
0 Kudos
25 Replies
New Contributor III
Ok, my problem is resolved (although I believe the original poster's problem still exists).

After combing over the various config files in Visual Studio, I noticed in Config.esriaddinx that for each button the class name was not the same as my actual button class names. How they got out of sync I am not sure... and I certainly should have found that sooner. But it explains the behavior.

Sorry for confusing this issue further.

(edit: 12/15)

I now know what happened, and it was completely my fault, not the Add-In wizard or Visual Studio. I located my notes from a few weeks back: I had used refactoring to change the name of the classes without fully testing the Add-In before stopping work on it to start another project. Unfortunately, the refactoring utility does not know about or change the related values in Config.esriaddinx, so that has to be done manually.

I think because I was already posting to this thread, I "red herring" -ed myself.

-Jeff
Reply
0 Kudos
New Contributor III
Well, I would like to thank everyone for their input.  I have solved my dilemma, more or less.  I have found that the structure of the vb for the Add-In needed to be as follows:
Imports ....


Public Class btnAddHyperlink
    Inherits ESRI.ArcGIS.Desktop.AddIns.Button


    Public Sub New()

    End Sub


    Protected Overrides Sub OnClick()

        Dim pFeature As IFeature, pLayer As ILayer

        Dim pSRE As SpatialReferenceEnvironment
        Dim pQF As IQueryFilter


and with that structure, the button would hit the code.  Again, many thanks for everyone's assistance.

Dale
Reply
0 Kudos
New Contributor III
Dale,

Just so I am clear about what resolved your problem: All you had to do was remove the enclosing namespace that was created by the New Add-In Project wizard in the button class file?

What about the following entry in your original Config.esriaddinx file:

<AddIn language="CLR" library="ERMDTools.dll" namespace="ERMDTools">

Did you need to edit that as well to an empty namespace?

-Jeff
Reply
0 Kudos
New Contributor III
Jeff,

I didn't change anything in the XML file (Config.esriaddinx) and I think that I may have inadvertently shot myself in the foot by manually bracketing my code with Namespace/End Namespace very early on in the process. 

Still, when I go to debug the code, the filled in red breakpoint goes hollow with the yellow triangle as ArcMap launches, but when I click the associated button, it stops at the breakpoint and allows me to step through the code.  I suspect an error somewhere, but it does not seem to be significant (famous last words).

Thanks,

Dale

Dale,

Just so I am clear about what resolved your problem: All you had to do was remove the enclosing namespace that was created by the New Add-In Project wizard in the button class file?

What about the following entry in your original Config.esriaddinx file:

<AddIn language="CLR" library="ERMDTools.dll" namespace="ERMDTools">

Did you need to edit that as well to an empty namespace?

-Jeff
Reply
0 Kudos
New Contributor III
I have a similar problem with a different twist. My addin works fine on all the PC's I have installed it on except one. The main difference on the face of it is that the problem PC is running Windows 7 64 bit while the rest are running XP. I have not determined what the issue is here. Has anyone else had problems with addins on specific PC's ? The symptoms are the same as reported on this thread, when the buttons on the addin toolbar are clicked they turn grey and do not execute. The names in the XML match the classes that are being executed.

Keith AM Adlam
British Geological Survey
Reply
0 Kudos
New Contributor
I think the problem is when you have ArcMap open (add-in installed) and you recompile your code.  This seems to through off the registry and or arc map cache.  I would compile my code and the add-in wouldn't even run the latest code, no matter what I did (searched for hours on a solution).  I finally deleted add-in from arcmap, deleted it from assemblyCache, deleted bin and object directories from my project folder then rebooted my machine.  I then started arcmap, did not see my add-in (expected).  Closed arcmap and opened VS 2008 express and compiled my code.  Then installed the add-in from the debug (or output) directory and hit play to debug.  FINALLY it worked. Hopefully this helps you as well.
Reply
0 Kudos