AppROT code worked for 10.1 SP1, but no longer works in 10.4.1

1188
3
10-17-2016 09:09 AM
deleted-user-VeC5jUIlNXtq
Occasional Contributor III

Hi,

I have a program that checks a raster catalog against view extent, copies any files to the project folder, and then the final step is to either:

1. Navigate to the project folder where the raster files are saved, if ArcCatalog is open.

or

2. Open ArcCatalog, then perform step 1.

This worked perfectly fine in ArcGIS 10.1, but after having upgraded to 10.4.1, this no longer works.

I'm using .NET, the code is below. I'm curious why this no longer works (serious application error crash).

' Application Running Object Table to access applications.
 Dim pAppROT As IAppROT
 pAppROT = New AppROT
' Cycle until ArcCatalog is found.
 Dim pGxApplication As IGxApplication
 Dim bCatalog As Boolean
 Dim iAppCount As Integer
pGxApplication = Nothing
' Get the total number of ESRI "Arc" processes running.
 iAppCount = pAppROT.Count

 If iAppCount > 0 Then
   Dim i As Integer
   For i = 0 To iAppCount - 1
       If pAppROT.Item(i).Name <> "ArcCatalog" Then
          bCatalog = False
       Else
          bCatalog = True
          Exit For
       End If
    Next i
   ' If catalog doesn't exist, launch one. Go to destination folder.
    If Not bCatalog Then
       Dim iCount As Integer
       iCount = 1
       Shell("C:\Program Files (x86)\ArcGIS\Desktop10.4\bin\ArcCatalog.exe", AppWinStyle.NormalFocus)
       Do While pAppROT.Count = iAppCount
          Thread.Sleep(500)
       Loop
      
      For i = 0 To pAppROT.Count - 1
          If pAppROT.Item(i).Name = "ArcCatalog" Then
             pGxApplication = pAppROT.Item(i)
             With pGxApplication
                .Location = sImageryDestination
               .Refresh(sImageryDestination)
             End With
          End If
       Next i
   Else
       pGxApplication = pAppROT.Item(i)
       With pGxApplication
          .Refresh("Y:\01_GISProject")
          .Location = sImageryDestination
          .Refresh(sImageryDestination)
       End With
   End If
End If‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
Tags (1)
0 Kudos
3 Replies
DuncanHornby
MVP Notable Contributor

Here is a mini video showing you how to set the formatting of code in geonet. You can ALWAYS go back and edit your post, suggest you do it as it makes your question more readable.

https://community.esri.com/blogs/sergent/2015/02/18/formatting-your-code-in-geonet-for-the-visual-le...

At what point is it crashing? Have you run it in debug mode and stepped through to find the offending line of code?

deleted-user-VeC5jUIlNXtq
Occasional Contributor III

Sorry for the delayed response, have been busy with project work and this doesn't fall under that category.

Thanks for that video! I don't know how I wasn't able to find it googling, but I've made my code look slightly better. It didn't give me a .NET option, but it looks better than before.

Anyway, I did more testing today and got myself back into this, and it turns out that an exception is thrown for 

pAppROT = New AppROT‍

In the meantime, I'll be doing more digging as to why this worked before, but no longer works. The only thing that has changed, has been the version of ArcGIS as stated originally.

Thanks,

Edit: I should've mentioned, the exception is an invalid cast exception to a COM object.

0 Kudos
LuisAcedo
New Contributor

Hello,

Sorry, I do get the same error. I cannot get the ArcMap app open on PC. It stops on the same place of code sending an error. 

I´m trying to get user running ArcMap and create a SLD file from map document. It is simple process, and it works for ArcMap 10.1 with AppROT. However in ArcMap 10.4 does not work when creating AppROT object

m_appObj = new AppROT

is there a solution for this problem? Do I need to check PC system to see ArcMap running? From here how do I get the map document?

Thanks

Luis Acedo

0 Kudos