Select to view content in your preferred language

Pro Addins not working anymore once built with MSVS 2019

2912
7
Jump to solution
07-18-2022 03:19 PM
Labels (1)
BillSmith
Regular Contributor

Hello,

I have a toolbar Addin which stopped working once we moved from Visual Studio 2017 to VS 2019.  It basically sends all features over to another photogrammetry software package for editing and then sends them back.  After I rebuilt it, it stopped sending over features.  I'm trying to debug it, but was wondering if anyone else has had this issue.

The output from the build is below.  The target was AnyCPU, which caused the first 4 warnings.  I changed it to 64 bit, which eliminated those warnings, but to no avail.  It still doesn't work.

Rebuild started...
1>------ Rebuild All started: Project: SfaProClient, Configuration: Debug Any CPU ------
1> Clean Addin...
1> Execute RegisterAddIn.exe "{97281cd9-589c-421b-8106-95484b67c7b7}" /u...
1>C:\TrustedApps\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2203,5): warning MSB3270: There was a mismatch between the processor architecture of the project being built "MSIL" and the processor architecture of the reference "ArcGIS.Desktop.Catalog", "AMD64". This mismatch may cause runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architectures between your project and references, or take a dependency on references with a processor architecture that matches the targeted processor architecture of your project.
1>C:\TrustedApps\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2203,5): warning MSB3270: There was a mismatch between the processor architecture of the project being built "MSIL" and the processor architecture of the reference "ArcGIS.Desktop.Core", "AMD64". This mismatch may cause runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architectures between your project and references, or take a dependency on references with a processor architecture that matches the targeted processor architecture of your project.
1>C:\TrustedApps\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2203,5): warning MSB3270: There was a mismatch between the processor architecture of the project being built "MSIL" and the processor architecture of the reference "ArcGIS.Desktop.Framework", "AMD64". This mismatch may cause runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architectures between your project and references, or take a dependency on references with a processor architecture that matches the targeted processor architecture of your project.
1>C:\TrustedApps\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2203,5): warning MSB3270: There was a mismatch between the processor architecture of the project being built "MSIL" and the processor architecture of the reference "ArcGIS.Desktop.GeoProcessing", "AMD64". This mismatch may cause runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architectures between your project and references, or take a dependency on references with a processor architecture that matches the targeted processor architecture of your project.
1>C:\TrustedApps\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2203,5): warning MSB3270: There was a mismatch between the processor architecture of the project being built "MSIL" and the processor architecture of the reference "ArcGIS.Desktop.Mapping", "AMD64". This mismatch may cause runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architectures between your project and references, or take a dependency on references with a processor architecture that matches the targeted processor architecture of your project.
1> SfaProClient -> V:\Repos\socetgxp\BuildOut\Config\Esri\SfaProClient.dll
1> ZipIntermediatePath Name: obj\Debug\temp_archive\...
1> IntermediateOutputPath Name: obj\Debug\...
1> CleanFile Name: SfaProClient.csproj.FileListAbsolute.txt...
1> ProjectDir Name: V:\Repos\socetgxp\tap_source\CscSrc\SfaCap\SfaProClient\...
1> AssemblyName Name: SfaProClient...
1> TargetFileName Name: SfaProClient.dll...
1> RootNamespace: SfaProClient...
1> TargetFolder Name: ..\..\..\..\BuildOut\Config\Esri\...
1> PackageType Name: Addin...
1> Install dir: C:\Program Files\ArcGIS\Pro\
1> RelativePaths: SfaProClient.dll
1> RelativePaths: SfaProClient.pdb
1> ConvertToRelativePath Task, TargetDir: V:\Repos\socetgxp\BuildOut\Config\Esri\
1> Deploying Addin...
1> ArcGISFolder Name: C:\Program Files\ArcGIS\Pro\...
1> Execute RegisterAddIn.exe "V:\Repos\socetgxp\BuildOut\Config\Esri\SfaProClient.esriAddinX" /s...
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========

 

Thanks in advance,

-Bill

Tags (1)
2 Solutions

Accepted Solutions
Wolf
by Esri Regular Contributor
Esri Regular Contributor

If the AddIn builds without errors and it still doesn't work, you should debug the addin with the following Exceptions Settings for "Common Language Runtime" checked (to get the Exception Settings dockpane in Visual Studio you click on "Debug" | "Windows" | "Exceptions Settings").  

Wolf_0-1658237159402.png

If you don't get any exceptions when debugging or you can't figure out the cause for the exception, send us the code snippet that doesn't work anymore (the sending of the features) so we can take a look at it.  In the past i found that many times the cause of such problems is that API code is not running from within the context of QueuedTask.Run().   See more here:  

https://github.com/Esri/arcgis-pro-sdk/wiki/ProConcepts-Asynchronous-Programming-in-ArcGIS-Pro#threa... 

If your Addin buttons stay disabled when you first click a button, that's usually a sign that the Pro API Framework cannot find your executable (did you rename the Dll?) or some code in your constructors throw an exception in which case the debugging steps above will help.

View solution in original post

BillSmith
Regular Contributor

I'm not sure what happened, but I just added a bunch more logging statements, rebuilt, and the stupid thing worked.  I'm sure I will have future posts when we re-arch to get this working with ArcGIS Pro 3.0

View solution in original post

7 Replies
CharlesMacleod
Esri Regular Contributor

I suspect that this is the issue:

https://support.esri.com/en/Technical-Article/000025544 

The sdk faq may help also: https://github.com/esri/arcgis-pro-sdk/wiki/FAQ#diagnosing-issues-in-arcgis-pro-28-and-29

Bottom line, changing the Platform Target from "Any CPU" to "x64" should do the trick

 

 

BillSmith
Regular Contributor

Thanks Charles,

I did try that and it does eliminate the warning messages, but it still didn't work.  I am on 2.9.3, so this change was made at 2.8 I see.  I will give it another look tomorrow though and check out the sdk FAQ.

Thanks!

0 Kudos
CharlesMacleod
Esri Regular Contributor

sure thing.

FWIW, I do not see any errors in the output, just CPU processor mismatch warnings. If you are having build errors can u post those or is the addin building successfully?

Wolf
by Esri Regular Contributor
Esri Regular Contributor

If the AddIn builds without errors and it still doesn't work, you should debug the addin with the following Exceptions Settings for "Common Language Runtime" checked (to get the Exception Settings dockpane in Visual Studio you click on "Debug" | "Windows" | "Exceptions Settings").  

Wolf_0-1658237159402.png

If you don't get any exceptions when debugging or you can't figure out the cause for the exception, send us the code snippet that doesn't work anymore (the sending of the features) so we can take a look at it.  In the past i found that many times the cause of such problems is that API code is not running from within the context of QueuedTask.Run().   See more here:  

https://github.com/Esri/arcgis-pro-sdk/wiki/ProConcepts-Asynchronous-Programming-in-ArcGIS-Pro#threa... 

If your Addin buttons stay disabled when you first click a button, that's usually a sign that the Pro API Framework cannot find your executable (did you rename the Dll?) or some code in your constructors throw an exception in which case the debugging steps above will help.

BillSmith
Regular Contributor

Thanks Wolf,

I usually have that exception on and nothing is being thrown.  It did step over all of my code to send the features though.  Let me be clear that we didn't change anything except for rebuilding.  Name and location of dll is the same. Our apps are talking to each other via RPC.  No exceptions being thrown.  I can paste the code below for the heck of it, but I don't think we need to worry about this right now since we have a workaround.  What we are doing is updating all Z's that aren't valid from our DTM.  They are updating just not being sent back to us, since we changed some logic to "smartly refresh" graphics. LOL.  We have a button in ArcGISPro  that sends them all over with brute force and that works.

I think we will hold off this issue for now and soon start working on making changes to work with ArcGIS Pro 3.0.  A little birdy told me that all Addins are going to break in that version.  I really appreciate having 2 senior developers weighing in on this.  Thanks Charles and Wolf!!

 

Anyways, here is the method that just steps to the end in the debugger.  All formatting is gone and everything is left justified. LOL.

 

public void SendFeatureGraphics(
Coordinate2D ll, Coordinate2D ur, bool xform = false, int index = -1)
{
QueuedTask.Run(() => {
MapView mapview = MapView.Active;
if (mapview == null) {
SfaLogger.Log("Unable to send feature graphics - mapview is null.");
return;
}
SfaSettings.FeaturesRequested = false; // processing request

int command = SfaConstants.API_SFA_DRAW_GRAPHICS;
int select = 0;
int data_len = 0;
bool features_sent = false;
int total_features_sent = 0;

Envelope extent =
EnvelopeBuilder.CreateEnvelope(ll, ur, (xform) ? GeoCS : MapCS);

if (xform) {
extent = GeometryEngine.Instance.Project(extent, MapCS) as Envelope;
}

CIMMap map = mapview.Map.GetDefinition();

ClippingMode clipping_mode = map.ClippingMode;
string clip_uri_str = map.CustomClippingShapeURI;

string[] layers_excluded = map.LayersExcludedFromClipping;

Polygon clip_poly = null;

if (clipping_mode.Equals(ClippingMode.CustomShape)) {
try {
// find the clipping custom shape file in the temporary directory for now

string temp_directory = Path.GetTempPath();

string clip_folder_path = clip_uri_str.Substring(clip_uri_str.IndexOf("=") + 1);

string[] sub_directories = Directory.GetDirectories(temp_directory);

string full_file_path = "";
foreach (string sub_folder in sub_directories) {
if (File.Exists((sub_folder + "\\" + clip_folder_path))) {
full_file_path = sub_folder + "\\" + clip_folder_path;
}
}

if (full_file_path.Length != 0) {

byte[] buffer = File.ReadAllBytes(full_file_path);

EsriShapeImportFlags importFlags = EsriShapeImportFlags.esriShapeImportDefaults;

clip_poly = GeometryEngine.Instance.ImportFromEsriShape(importFlags, buffer, SpatialReferences.WGS84) as Polygon;
}

} catch (Exception ex) {
SfaLogger.Log(ex.Message);
}
}
else if (clipping_mode.Equals(ClippingMode.MapExtent)) {
// get the custom extent from the Map Extent
clip_poly = PolygonBuilder.CreatePolygon(mapview.Map.GetCustomFullExtent());
}

Polygon sgxp_polygon = PolygonBuilder.CreatePolygon(extent);
Polygon polygon_intersection = sgxp_polygon;

// only send feature that are within the intersect regions
if (clip_poly != null && sgxp_polygon != null) {
// check to see if the clipping extent in Pro intersects with
// the extent in SGXP
if (!GeometryEngine.Instance.Intersects(sgxp_polygon, clip_poly)) {
return;
}

// get the intersecting extent where the custom extent
// and SGXP intersect
polygon_intersection = GeometryEngine.Instance.Intersection(sgxp_polygon, clip_poly) as Polygon;

if (polygon_intersection == null) {
return;
}
}

IEnumerable<FeatureLayer> layers =
mapview.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>();

foreach (FeatureLayer fl in layers) {
using (FeatureClass fc = fl.GetFeatureClass()) {

// Test for valid layer index
int layer_index = GetSfaLayerIndex(fc);
if (layer_index < 0) continue;
if (index >= 0 && layer_index != index) continue;

SfaLayer layer = SfaSettings.Layers[layer_index];

layer.IsVisible = fl.IsVisible;
layer.IsDrawn = fl.IsVisible;

if (!layer.IsDrawn) {
SfaLogger.Log(
"Skipping feature graphics for layer: " + layer.Name);
continue;
}

bool selectable = fl.IsSelectable;
bool editable = fl.IsEditable;

SpatialQueryFilter spatial_filter = new SpatialQueryFilter();

spatial_filter.FilterGeometry = polygon_intersection;

spatial_filter.SpatialRelationship =
SpatialRelationship.Intersects;

if (!clipping_mode.Equals(ClippingMode.None)) {
foreach (string lay in layers_excluded) {
// if layer is excluded, send all features for that layer
if (lay == fl.URI) {
spatial_filter.FilterGeometry = sgxp_polygon;
}
}
}

List<int> features_to_send = new List<int>();
List<int> features_already_present = new List<int>();

using (RowCursor rows = fl.Search(spatial_filter)) {
int i = 1;

do {
int reserve = 3 * sizeof(int);
SfaBuffer.BeginFeatureBlock(true, true, reserve);

try {
while (rows.MoveNext()) {
using (Feature feature = rows.Current as Feature) {

int feature_id = (int)feature.GetObjectID();

if (layer.FeaturesSent.Contains(feature_id)) {
features_already_present.Add(feature_id);
continue;
}

features_to_send.Add(feature_id);

if (!layer.HasSymbol) {
layer.LookupSymbol(feature);
}

SfaBuffer.PackFeature(
layer_index, feature, true, editable, selectable);

feature.Dispose();
}

if (SfaBuffer.DataLength >
(SfaBuffer.GetBuffer().Length - SfaConstants.BUFFER_CUSHION)) {
// We are close to filling the buffer, send what we have.
//rows.Current.Dispose();
break;
}
}
} catch (Exception e) {
SfaLogger.Log("Exception occured: " + e.Message);
}

if (SfaBuffer.NumFeatures > 0) {
features_sent = true;
total_features_sent += SfaBuffer.NumFeatures;

SfaBuffer.EndFeatureBlock();
int ftr_data_len = SfaBuffer.DataLength;

// We reserved space at the beginning of the buffer for these.
SfaBuffer.PrependBuffer(BitConverter.GetBytes(command), sizeof(int));
SfaBuffer.PrependBuffer(BitConverter.GetBytes(select), sizeof(int));
SfaBuffer.PrependBuffer(BitConverter.GetBytes(ftr_data_len), sizeof(int));

data_len = ftr_data_len + reserve;

if (SfaSettings.FeaturesRequested) {
// If a new reload request is made, need to stop this request
SfaLogger.Log("Starting new feature refresh query");
return;
}

SendMessage(SfaBuffer.GetBuffer(), data_len);
}

i++;

} while (rows.Current != null);

foreach (var ftr_id in features_to_send) {
SfaSettings.Layers[layer_index].FeaturesSent.Add(ftr_id);
}
}
}
}

if (!features_sent) {
// Inform SOCET GXP that refresh graphics is finished. Needed
// when nothing is sent in order to reset a flag in SOCET GXP.
SfaLogger.Log("There were no features to send for current extent.");
select = 99;

ResetBuffer();
AppendBuffer(BitConverter.GetBytes(command), sizeof(int));
AppendBuffer(BitConverter.GetBytes(select), sizeof(int));
AppendBuffer(BitConverter.GetBytes(data_len), sizeof(int));

SendMessage(_buf, _buf_pos);

} else {
Dictionary<MapMember, List<long>> selection = mapview.Map.GetSelection();
// Preserve any selections in the ArcMap canvas

if (selection.Count > 0) {
Thread.Sleep(500); //07-21-2022 BillSmith - this looks suspect, why are we sleeping?
SendSelection(mapview.Map.GetSelection());
}
}
});
}

0 Kudos
BillSmith
Regular Contributor

I'm not sure what happened, but I just added a bunch more logging statements, rebuilt, and the stupid thing worked.  I'm sure I will have future posts when we re-arch to get this working with ArcGIS Pro 3.0

Wolf
by Esri Regular Contributor
Esri Regular Contributor

Thanks Bill, I found similar issues before where introducing additional logging changed the timing and hence the execution sequence of threads that caused similar issues.   I will look over your code snippet and let you know if i see anything suspicious.