ArcMap.Application is null when Addin is loaded

3155
10
Jump to solution
06-19-2014 12:21 AM
SiqinWANG
New Contributor
Hello,

I've a problem in the installation of an Add-in that we've developed for our client. The Add-in does not work correctly because the ArcMap.Application value is null when loaded.  The type of this Add-in is an Extension.

The Add-In is developed with ArcObjects in the version of 10.2.1. We don't have any problem when it is tested on our environment with an ArcMap 10.2.1. Our client has a version of 10.2.0.

Does any one has an idea of this error ?

Thank you very much.

Siqin
0 Kudos
1 Solution

Accepted Solutions
DuncanHornby
MVP Notable Contributor
I've always understood development with ArcObjects should use be using the 3.5 .Net Framework, I see you have yours set to 4.5. You can change this under project properties > Compile > Advanced Compile Options.

Also  make sure platform Target CPU is x86.

View solution in original post

10 Replies
DuncanHornby
MVP Notable Contributor
Can't really help unless we see the code.

I suggest you upload a sample of code where this null is being returned.
SiqinWANG
New Contributor
Can't really help unless we see the code.

I suggest you upload a sample of code where this null is being returned.


Hello Hornbydd,

Thank you for your message.

Here is the code :
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Reflection;
using System.Windows.Forms;

namespace TestChargementAddIn {
    public class ExtensionChargement : ESRI.ArcGIS.Desktop.AddIns.Extension {
        public ExtensionChargement() {
        }

        protected override void OnStartup() {
            //
            // TODO: Uncomment to start listening to document events
            //
            // WireDocumentEvents();

            
            if (ArcMap.Application == null) {
                // relative path est par rapport au répertoire de Debug ou Release

               MessageBox.Show("Erreur : ArcMap.Application est nul !!");
            } else {
                MessageBox.Show("OK: L'AddIn est chargé normalement. ArcMap.Application : " + ArcMap.Application.Caption.ToString());
                if (ArcMap.Document == null) {
                    MessageBox.Show("Erreur : ArcMap.Document est nul !!");
                } else {
                    MessageBox.Show("OK : ArcMap.Document non nul");
                }
            }
        }

        private void WireDocumentEvents() {
            //
            // TODO: Sample document event wiring code. Change as needed
            //

            // Named event handler
            ArcMap.Events.NewDocument += delegate() { ArcMap_NewDocument(); };

            // Anonymous event handler
            ArcMap.Events.BeforeCloseDocument += delegate() {
                // Return true to stop document from closing
                ESRI.ArcGIS.Framework.IMessageDialog msgBox = new ESRI.ArcGIS.Framework.MessageDialogClass();
                return msgBox.DoModal("BeforeCloseDocument Event", "Abort closing?", "Yes", "No", ArcMap.Application.hWnd);
            };

        }

        void ArcMap_NewDocument() {
            // TODO: Handle new document event
        }

    }

}


I've also uploaded the packaged Add-In in the post in order that you could test it.

Thanks.

Siqin
0 Kudos
DuncanHornby
MVP Notable Contributor
OK here is an idea, go to the the Config.esriaddinx file in Visual Studio and set the autoLoad to equal "true" for your <Extension>.
SiqinWANG
New Contributor
OK here is an idea, go to the the Config.esriaddinx file in Visual Studio and set the autoLoad to equal "true" for your <Extension>.


Hornbydd,

Thank you for your reply. I've checked in my Config.esriaddinx file. The value of the "autoLoad" option is already set to "true".
Is there something else can be wrong in the configuration ? Or some configuration to change on ArcMap ?


Thanks.

<ESRI.Configuration xmlns="http://schemas.esri.com/Desktop/AddIns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <Name>TestChargementAddIn</Name>
  <AddInID>{b60275b3-d9ad-48fe-90ad-d7f43adfbb6c}</AddInID>
  <Description>C'est un test sur le chargement d'un AddIn.</Description>
  <Version>1.0</Version>
  <Image>Images\TestChargementAddIn.png</Image>
  <Author>siwang</Author>
  <Company>Kleegroup</Company>
  <Date>18/06/2014</Date>
  <Targets>
    <Target name="Desktop" version="10.2" />
  </Targets>
  <AddIn language="CLR4.5" library="TestChargementAddIn.dll" namespace="TestChargementAddIn">
    <ArcMap>
      <Extensions>
        <Extension id="Kleegroup_TestChargementAddIn_ExtensionChargement" class="ExtensionChargement" productName="Extension du Chargement" showInExtensionDialog="true" autoLoad="true">
          <Description>Test sur l'extension</Description>
        </Extension>
      </Extensions>
    </ArcMap>
  </AddIn>
</ESRI.Configuration>

0 Kudos
NeilClemmons
Regular Contributor III
You said you compiled the addin in 10.2.1 and are trying to run it on 10.2.0.  I don't know about addins but that doesn't typically work for standard COM extensions since ArcObjects are not backwards compatible.
DuncanHornby
MVP Notable Contributor
I've always understood development with ArcObjects should use be using the 3.5 .Net Framework, I see you have yours set to 4.5. You can change this under project properties > Compile > Advanced Compile Options.

Also  make sure platform Target CPU is x86.
SiqinWANG
New Contributor
You said you compiled the addin in 10.2.1 and are trying to run it on 10.2.0.  I don't know about addins but that doesn't typically work for standard COM extensions since ArcObjects are not backwards compatible.


Thank you for this important information. Effectively, we have also a doubt on the compatibility.
Our client finally agrees to update their application to the version of 10.2.1. However, we have to assure that there is nothing else which could go wrong beside the version problem.
0 Kudos
SiqinWANG
New Contributor
I've always understood development with ArcObjects should use be using the 3.5 .Net Framework, I see you have yours set to 4.5. You can change this under project properties > Compile > Advanced Compile Options.

Also  make sure platform Target CPU is x86.


That's something that we've not thought of !! Maybe the machines of our client don't have the 4.5 version of .Net Framework. I'll verify that. As the Add-in is developed with the 4.5 .Net Framework, we have to check if there is some incompatibility problems in the code.

Thank you for your advice !
0 Kudos
SiqinWANG
New Contributor
Thank you for this important information. Effectively, we have also a doubt on the compatibility.
Our client finally agrees to update their application to the version of 10.2.1. However, we have to assure that there is nothing else which could go wrong beside the version problem.


Hornbydd,

We've checked the version of client's machine : They don't have the 4.5 version of .Net. Only on 4.0. I've sent them an Add-In of thest compiled on 4.0. They have succeeded in loading it. So the problem comes exactly from the installed .net version.

Thank you very much for your help 🙂
0 Kudos