0
Answer

System.AccessViolationException C#

Ask a question
sri

sri

15y
9.6k
1
Hi guys,

I want to open ArcMap (ArcGIS) attributes table and for that I am using C# code. In this process I get an error message as IsDockable = 'pTableWindow2.IsDockable' threw an exception of type 'System.AccessViolationException'. I searched a lot on the internet and found that it's a very frequent problem but I couldn't figure it out. I do not understand what's the problem with it. I would appreciate if anyone can help me with this issue. The code is given below.

        public override void OnClick()
        {           
            IMxDocument pMxDoc;           
            ILayer pLayer;
            IFeatureLayer pFeatureLayer;
            IStandaloneTable pStandaloneTable;
            ITableWindow2 pTableWindow2;
            ITableWindow pExistingTableWindow;
           
            try
            {               
                pMxDoc = m_application.Document as IMxDocument;
                pTableWindow2 = new TableWindowClass();
                pFeatureLayer = (IFeatureLayer)pMxDoc.
SelectedItem;
                pLayer = pFeatureLayer;
                pExistingTableWindow = pTableWindow2.FindViaLayer(pLayer);
                pTableWindow2.Layer = pLayer;        
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

Thank you in advance