Cannot load form or even display a message box

1017
9
07-06-2011 03:46 PM
OlwynBruce
New Contributor III
Hi there,
I'm trying to learn how to use Visual Studio to create a button that loads a form. I'm using Visual Studio Express 2008 (VB.NET). I've followed, step by step, two tutorials:
http://gis.qtools.com/blog/tutorials/vba-to-c-add-in/part-4-creating-new-add-in-project/ (up to Part 4 and using VB.NET)
http://www.esri.com/news/arcuser/0311/recycling-vba.html

In neither tutorial have I been able to get a form to load. In the case of the first tutorial, I can't even get a message box to display. It's pretty frustrating.

So, I started from scratch in a new project (ArcMapAddIn1). It is a button (Button1) on a toolbar (My Toolbar). When the button is pressed a message box is supposed to pop up (this is under the OnClick event for Button1).  Nothing happens when I press the button! It just goes grey.

Any ideas about what I'm missing here?
Cheers,
Olwyn
0 Kudos
9 Replies
JeffreyHamblin
New Contributor III
Hi Olwyn,

Maybe something in this thread will help:
Add-in; Failure to get code to execute when toolbar button pressed

Specifically, check that class names and namespaces are consistant across code and the Config.esriaddinx file.

I'm pretty sure the graying out of a button happens when ArcGIS can't find the classes named in the xml config.
0 Kudos
OlwynBruce
New Contributor III
Hi Jeff,
I looked at that thread - lots of good information! However, I seem to still be having problems.

I went back to the beginning and followed your tutorial at gis.qtools.com (VBA to C add-in). My system is:
Windows 7, 64-bit
Visual C# Express 2008 SP1
ArcMap 10.0 SP2 (ArcInfo)

I did parts 3 & 4. I'm able to make a toolbar with a button but nothing happens when I click on it (it just goes grey).

Here's the code from config.esriaddinx:
<ESRI.Configuration xmlns="http://schemas.esri.com/Desktop/AddIns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <Name>CSTutorial</Name>
  <AddInID>{4e2c325a-27f5-4d4b-b2a0-266819364cc2}</AddInID>
  <Description>C# tutorial</Description>
  <Version>1.0</Version>
  <Image>Images\CSTutorial.png</Image>
  <Author>jobruce</Author>
  <Company>YGS</Company>
  <Date>7/13/2011</Date>
  <Targets>
    <Target name="Desktop" version="10.0" />
  </Targets>
  <AddIn language="CLR" library="CSTutorial.dll" namespace="CSTutorial">
    <ArcMap>
      <Commands>
        <Button id="YGS_CSTutorial_StaggerOffsetButton" class="StaggerOffsetButton" message="Stagger Offset: Offsets all feature in selected layer by a user-specified stagger amount on either side of the original position. Start an edit session before use." caption="Stagger Offset Features" tip="Stagger Offset Features: Offsets all features in selected layer." category="Add-In Controls" image="Images\StaggerOffsetButton.png" />
      </Commands>
      <Toolbars>
        <Toolbar id="YGS_CSTutorial_CS_Toolbar" caption="CS_Toolbar" showInitially="true">
          <Items>
            <Button refID="YGS_CSTutorial_StaggerOffsetButton" />
          </Items>
        </Toolbar>
      </Toolbars>
    </ArcMap>
  </AddIn>
</ESRI.Configuration>


Here's the code from StaggerOffsetButton.cs:
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Windows.Forms;

namespace CSTutorial
{
    public class StaggerOffsetButton : ESRI.ArcGIS.Desktop.AddIns.Button
    {
        public StaggerOffsetButton()
        {
        }

        protected override void OnClick()
        {
            //
            //  TODO: Sample code showing how to access button host
            //
            ArcMap.Application.CurrentTool = null;
            MessageBox.Show("Hello world");
        }
        protected override void OnUpdate()
        {
            Enabled = ArcMap.Application != null;
        }
    }

}


Any suggestions? I'd really like to start customizing with .NET but having zero luck so far.
Olwyn
0 Kudos
JeffreyHamblin
New Contributor III
Hi Olwyn,

My system is identical. Not sure why it is not working for you. Weird...

If you ZIP up the solution folder for the tutorial project and post it here I can take a look at the structure and load the project and see if it builds and functions on my system.
0 Kudos
OlwynBruce
New Contributor III
Hi Jeff,
I really appreciate your help on this. I'm going to ask a co-worker of mine to install the software and do parts 3 & 4 as well - maybe it's some weird, obscure setting on my system. We'll see 😉

I uninstalled/reinstalled VS2008 and the SDK late yesterday so the solution I've attached was built in this new "clean" install. Still the same behavior (greyed out button after click, with no message box).

Any tips would be terrific.
Cheers,
Olwyn
0 Kudos
JeffreyHamblin
New Contributor III
Hi Olwyn,

My first test with your project was to simply install the compiled Add-In, CSTutorial.esriAddIn found in the CSTutorial\bin\Debug folder. I copied it to a temp folder and double-clicked on it to launch the Add-In installer. It installed successfully, the toolbar with button showed on ArcMap startup, and clicking it displayed the "Hello World" dialog.

So there is nothing wrong with your project or Add-In directly, I believe. Likely either a conflict with an older version of the Add-In, or some other system issue.

Have you tried clearing the assembly cache and Add-Ins folders?

Try this:
-Using the Add-In Manager, delete the tutorial Add-In.
-Close ArcMap
-Delete everything in: C:\Users\[USER]\AppData\Local\ESRI\Desktop10.0\AssemblyCache
-Check the Add-Ins folder to ensure the tuturial Add-In was deleted:
  C:\Users\[USER]\Documents\ArcGIS\AddIns\Desktop10.0
  (if still there, delete it)
-Do a manual install of the Add-In as I did, and see if it works.
0 Kudos
OlwynBruce
New Contributor III
HI Jeff,
Perfect - I'm going to try that first and then, if that fails, do a COMPLETE uninstall/reinstall of ArcMap, VS2008 & the SDK. I was just over at my co-workers and his system is the same as mine - his worked straight off! So, clearly, there's something wrong on my end.

I'll post the results...thank you once again for all the help.
Cheers,
Olwyn
0 Kudos
MichaelRobb
Occasional Contributor III
Hi there,
I'm trying to learn how to use Visual Studio to create a button that loads a form. I'm using Visual Studio Express 2008 (VB.NET). I've followed, step by step, two tutorials:
http://gis.qtools.com/blog/tutorials/vba-to-c-add-in/part-4-creating-new-add-in-project/ (up to Part 4 and using VB.NET)
http://www.esri.com/news/arcuser/0311/recycling-vba.html

In neither tutorial have I been able to get a form to load. In the case of the first tutorial, I can't even get a message box to display. It's pretty frustrating.

So, I started from scratch in a new project (ArcMapAddIn1). It is a button (Button1) on a toolbar (My Toolbar). When the button is pressed a message box is supposed to pop up (this is under the OnClick event for Button1).  Nothing happens when I press the button! It just goes grey.

Any ideas about what I'm missing here?
Cheers,
Olwyn



Button going grey is a sign that the dll is not unpacked from the Addin, missing the class.
Check the Assembly Folder for the dll.. make sure your build action is AddinContent for the esriaddinx.  Make sure the others are Compile and if you are moving files over to the Assembly Folder, use Embedded Resource.  Just see what gets unpacked.. or check the ESRIAddin.exe itself by renaming it .zip and unzipping to see the contents.

In this case above... there is:
class="StaggerOffsetButton"

Is this class in the Solution?
0 Kudos
JeffreyHamblin
New Contributor III
I loaded the CSTutorialSolution attached to the earlier post (had to edit the path to ArcMap.exe in the CSTutorial.csproj.user file before I could compile). It compiled and ran fine in ArcMap.

- The project settings are good.
- The Add-In itself is good. (I tested that earlier from Olwyn's build)

Maybe it's a permissions or path issue on either the Add-Ins folder, the ESRI assembly cache, or ???

Clearly, on Olwyn's system, ArcMap finds and unpacks the Add-In because the button and toolbar display. So it's reading the config. But can't locate the class and or the DLL.
0 Kudos
OlwynBruce
New Contributor III
So the Final Solution for me was to completely nuke and pave my system. Apparently, I'm not the only one in our GIS world here that is having major problems with add-ins - this isn't the first time this has happened.

It makes me pretty leary about wanting to develop with them, if it's going to turf my system! It's probably some deeply buried setting but - like anyone - I don't have the time to futz around with it.

ESRI - any suggestions here? Any settings I can check or advice to pass on here?

Cheers,
Olwyn
0 Kudos