ArcObjects C#

3536
2
Jump to solution
07-16-2015 08:16 PM
martywalters
New Contributor III

I'm coverting Hussein Nasser VB code to C# but I'm having problems.

it's from his session:

Extending ArcObjects with .NET (IGeometry) - 02 - Working with Layers

The Vb code works but my converted C# crashes

here is my onclick code from form1 : Form

ERROR ->

System.NullReferenceException: Object reference not set to an instance of

OCCURS during the Assignment of pMap.

        private void button1_Click(object sender, EventArgs e)

        {

            IMxDocument pMxDoc = (IMxDocument)_application.Document;

            IMap pMap = pMxDoc.FocusMap;

        }

vb code : 

Private _application As IApplication

    Public Property ArcMapApplication() As IApplication

        Get

            Return _application

        End Get

        Set(ByVal value As IApplication)

            _application = value

        End Set

    End Property

c# code:

        private IApplication _application;

        public IApplication ArcMapApplication

        {

            get { return _application; }

            set { _application = value; }

        }

0 Kudos
1 Solution

Accepted Solutions
martywalters
New Contributor III

Hussein Nasser himself solved it for me

Hussein, thanks for the Great Video series on Extending ArcObjects.

Double Thanks for providing me help.

View solution in original post

2 Replies
martywalters
New Contributor III

Hussein Nasser himself solved it for me

Hussein, thanks for the Great Video series on Extending ArcObjects.

Double Thanks for providing me help.

OwenEarley
Occasional Contributor III

In what context are you running this code? - for example within an Add-In, old style COM extension, etc.

Has your _application object already been set or is it null?

EDIT - I got side-tracked and should have refreshed before posting to see if an answer had already been posted

0 Kudos