Reference to a tool within an extension no longer working ...

1157
5
09-23-2013 01:38 PM
shawnstanley
New Contributor III
Hello

We have recently moved our computers from Windows NT to Windows 7, and at the same time we've upgraded from ArcGIS 10.1 to 10.2.

I have an ArcGIS extension created in Visual Basic 2010, which had been running well in the previous set up.  I have moved things over onto my new computer in this new environment, and now something is not working.

I have on some of my forms a click event which access one of the tools elsewhere in the same extension.  When the click event is accessed now a unhandled exception error comes up "Object reference not set to an instance of an object".

I've obviously missed, or forgotten doing something which I had previously done.  Could anyone help with what that might be.  Here is the offending click event ...

    Private Sub cmdSelect1_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdSelect1.Click

        Dim pUID As ESRI.ArcGIS.esriSystem.UID = New ESRI.ArcGIS.esriSystem.UID
        Dim pCommandItem As ESRI.ArcGIS.Framework.ICommandItem = Nothing

        Dim Application As ESRI.ArcGIS.Framework.IApplication = m_pApp

        pUID.Value = "{" & SelectFPoint.ClassId & "}"

        pCommandItem = Application.Document.CommandBars.Find(pUID, False, False)
        pCommandItem.Execute()

    End Sub
0 Kudos
5 Replies
AlexanderGray
Occasional Contributor III
Without exception handling you are going to have a hard time figuring this out.  I suggest you put a try catch block in your onclick (and in any other event handler.) 
The likely culprit is the command item is not found, if it is not found, it will return nothing, you can call execute on nothing.  If this SelectFPPoint is not installed and registered correctly, you will get this error, but without exception handling that is hard to assess.
0 Kudos
shawnstanley
New Contributor III
I finally figured out what the problem was.  Unfortunately, I was doing everything properly with regard to registration of tool being accessed.

After going back, and forth, and back and forth again I noticed in the code generated code on the tool the following:

        Dim regKey As String = String.Format("HKEY_CLASSES_ROOT\CLSID\{{{0}}}", registerType.GUID)
        MxCommands.Register(regKey)

most particularly I noticed the word Register

One of the new things about our organisations move to Windows 7 has been greater security restrictions set on the computers.

If I run ArcGIS with administrator privileges, then everything runs OK.  The tool is now registered and can be accessed from another tool.

Is there anything I can do to get around this? 

Note, that running ArcGIS with administrator privileges is not an option for all of the intended users of the extension.

cheers
shawn
0 Kudos
NeilClemmons
Regular Contributor III
When Visual Studio compiles your ESRI components, it registers them in the ESRI component categories.  In order to do this, it must have write access to the system registry.  You have a couple of options - run Visual Studio as an administrator every time you start it up or turn off UAC on your machine.  If you're registering your component via Add from File on the Customize dialog in ArcMap (not the optimal way of doing it if you're actively developing) then ArcMap must be running as an administrator (or turn off UAC).  This will not impact your users.  When your application is deployed, the Windows installer will kick off the registration.  Of course, it must be running with elevated privileges but that is standard.  Installing software is a task that should only be performed by an administrator.

The only way around all of this is to rewrite your application as an addin.  Addins do not require admin privileges to deploy.
0 Kudos
AlexanderGray
Occasional Contributor III
We are confronted with the same situation.  If you are allowed to run vs as admin to compile, if your application needs any network resources, the admin user will need them too.  Good luck, it is a major pain.
0 Kudos
shawnstanley
New Contributor III
When Visual Studio compiles your ESRI components, it registers them in the ESRI component categories.  In order to do this, it must have write access to the system registry.  You have a couple of options - run Visual Studio as an administrator every time you start it up or turn off UAC on your machine.  If you're registering your component via Add from File on the Customize dialog in ArcMap (not the optimal way of doing it if you're actively developing) then ArcMap must be running as an administrator (or turn off UAC).  This will not impact your users.  When your application is deployed, the Windows installer will kick off the registration.  Of course, it must be running with elevated privileges but that is standard.  Installing software is a task that should only be performed by an administrator.

The only way around all of this is to rewrite your application as an addin.  Addins do not require admin privileges to deploy.


hello Neil and Agray1

It wasn't the running of Visual Studio as an administrator, or installing the extension as an administrator which was a problem.  As the UAC policy is controlled centrally here I don't have any ability to control that.  What the problem was, and my apologies for not being clear, is that a tool in the extension which brought up a window and allowed a number of things to be done.  One of those things calls another tool (the second tool is not visible in the tool bar).  This second tool was not working.  I tried adding it to the extensions toolbar - and it worked.  I tried running ArcGIS with administrator rights (when the second tool was not in the extensions toolbar - and it worked).

Neither of these were acceptable.

This morning I looked back at the setup project and then started comparing it to what it should look like - Neil, your comment in another thread make me think about this option
http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#/How_to_deploy_a_custom_...

For some reason I had stopped before the Registering the CustomComponent .dll file using ESRIRegAsm.exe step of the process.  So I did this step of the process.

And now it works.

cheers
shawn
0 Kudos