<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Why does CIMSqlQueryDataConnection.FromJson choke on queryFields? in ArcGIS Pro SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/why-does-cimsqlquerydataconnection-fromjson-choke/m-p/1026292#M6174</link>
    <description>&lt;P&gt;I was under the impression that I can always deserialize CIM objects using json copied from a .lyrx file.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is this true?&lt;/P&gt;&lt;P&gt;I created an SQL Query Layer with the UI, then saved it to a .lyrx file (see attached).&lt;/P&gt;&lt;P&gt;I then created a new file, sqldataconn1.json (see attached), with this json copied from the lyrx file:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;{
    "type" : "CIMSqlQueryDataConnection",
	"workspaceConnectionString" : "SERVER=localhost;INSTANCE=sde:...",
	"workspaceFactory" : "SDE",
	"dataset" : "db1.DBO.%mytest2",
	"datasetType" : "esriDTFeatureClass",
	"sqlQuery" : "select OBJECTID,SHAPE,GDB_GEOMATTR_DATA from db1.dbo.TEST2",
	"srid" : "3857",
	"spatialReference" : {
	"wkid" : 102100,
	"latestWkid" : 3857
	},
	"oIDFields" : "OBJECTID",
	"geometryType" : "esriGeometryPolygon",
	"extent" : {
	"xmin" : -11607361.9631999992,
	"ymin" : 3260858.89570000023,
	"xmax" : -10527607.362,
	"ymax" : 3930306.748499997,
	"spatialReference" : {
	  "wkid" : 102100,
	  "latestWkid" : 3857
	}
	},
	"queryFields" : [
	{
	  "name" : "OBJECTID",
	  "type" : "esriFieldTypeInteger",
	  "alias" : "OBJECTID"
	},
	{
	  "name" : "SHAPE",
	  "type" : "esriFieldTypeGeometry",
	  "alias" : "SHAPE",
	  "geometryDef" : {
		"avgNumPoints" : 0,
		"geometryType" : "esriGeometryPolygon",
		"hasM" : false,
		"hasZ" : false,
		"spatialReference" : {
		  "wkid" : 102100,
		  "latestWkid" : 3857
		}
	  }
	},
	{
	  "name" : "GDB_GEOMATTR_DATA",
	  "type" : "esriFieldTypeBlob",
	  "alias" : "GDB_GEOMATTR_DATA"
	}
	],
	"spatialStorageType" : 2
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However I get an exception:&lt;/P&gt;&lt;P&gt;"&lt;FONT face="courier new,courier"&gt;Cannot cast Newtonsoft.Json.Linq.JArray to Newtonsoft.Json.Linq.JToken.&lt;/FONT&gt;"&lt;/P&gt;&lt;P&gt;If I remove the queryFields element from the json, sqldataconn2.json (see attached), it runs without error.&lt;/P&gt;</description>
    <pubDate>Fri, 12 Feb 2021 18:21:58 GMT</pubDate>
    <dc:creator>KirkKuykendall1</dc:creator>
    <dc:date>2021-02-12T18:21:58Z</dc:date>
    <item>
      <title>Why does CIMSqlQueryDataConnection.FromJson choke on queryFields?</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/why-does-cimsqlquerydataconnection-fromjson-choke/m-p/1026292#M6174</link>
      <description>&lt;P&gt;I was under the impression that I can always deserialize CIM objects using json copied from a .lyrx file.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is this true?&lt;/P&gt;&lt;P&gt;I created an SQL Query Layer with the UI, then saved it to a .lyrx file (see attached).&lt;/P&gt;&lt;P&gt;I then created a new file, sqldataconn1.json (see attached), with this json copied from the lyrx file:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;{
    "type" : "CIMSqlQueryDataConnection",
	"workspaceConnectionString" : "SERVER=localhost;INSTANCE=sde:...",
	"workspaceFactory" : "SDE",
	"dataset" : "db1.DBO.%mytest2",
	"datasetType" : "esriDTFeatureClass",
	"sqlQuery" : "select OBJECTID,SHAPE,GDB_GEOMATTR_DATA from db1.dbo.TEST2",
	"srid" : "3857",
	"spatialReference" : {
	"wkid" : 102100,
	"latestWkid" : 3857
	},
	"oIDFields" : "OBJECTID",
	"geometryType" : "esriGeometryPolygon",
	"extent" : {
	"xmin" : -11607361.9631999992,
	"ymin" : 3260858.89570000023,
	"xmax" : -10527607.362,
	"ymax" : 3930306.748499997,
	"spatialReference" : {
	  "wkid" : 102100,
	  "latestWkid" : 3857
	}
	},
	"queryFields" : [
	{
	  "name" : "OBJECTID",
	  "type" : "esriFieldTypeInteger",
	  "alias" : "OBJECTID"
	},
	{
	  "name" : "SHAPE",
	  "type" : "esriFieldTypeGeometry",
	  "alias" : "SHAPE",
	  "geometryDef" : {
		"avgNumPoints" : 0,
		"geometryType" : "esriGeometryPolygon",
		"hasM" : false,
		"hasZ" : false,
		"spatialReference" : {
		  "wkid" : 102100,
		  "latestWkid" : 3857
		}
	  }
	},
	{
	  "name" : "GDB_GEOMATTR_DATA",
	  "type" : "esriFieldTypeBlob",
	  "alias" : "GDB_GEOMATTR_DATA"
	}
	],
	"spatialStorageType" : 2
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However I get an exception:&lt;/P&gt;&lt;P&gt;"&lt;FONT face="courier new,courier"&gt;Cannot cast Newtonsoft.Json.Linq.JArray to Newtonsoft.Json.Linq.JToken.&lt;/FONT&gt;"&lt;/P&gt;&lt;P&gt;If I remove the queryFields element from the json, sqldataconn2.json (see attached), it runs without error.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Feb 2021 18:21:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/why-does-cimsqlquerydataconnection-fromjson-choke/m-p/1026292#M6174</guid>
      <dc:creator>KirkKuykendall1</dc:creator>
      <dc:date>2021-02-12T18:21:58Z</dc:date>
    </item>
    <item>
      <title>Re: Why does CIMSqlQueryDataConnection.FromJson choke on queryFields?</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/why-does-cimsqlquerydataconnection-fromjson-choke/m-p/1027670#M6204</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;How are you using the JSON strings to create the new layer?&lt;/P&gt;&lt;P&gt;It is best to use the LayerDocument to accomplish this . LayerDocument gives you the ability to work with an "in-memory" representation of the layer. You can configure it (data connection, SQL query, renderers, etc) and then add it to the map. You can use an existing LayerX file to create a layer document object, and then access its CIM Definition to configure it.&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt; QueuedTask.Run( () =&amp;gt; {
        //Creates an in memory copy of the existing lyrx file
        ArcGIS.Desktop.Mapping.LayerDocument lyrDoc = new ArcGIS.Desktop.Mapping.LayerDocument(@"C:\pathtoLayerXFile\layer.lyrx");
        var cimLayerDoc = lyrDoc.GetCIMLayerDocument();
        //Configure any aspects of the layer you want here. Query definitions, etc.
        cimLayerDoc.LayerDefinitions[0].Name = "MyNewLayer";
        //Create the layer in the active map using the layer document.
        var layerParams = new LayerCreationParams(cimLayerDoc);
        LayerFactory.Instance.CreateLayer&amp;lt;FeatureLayer&amp;gt;(layerParams, MapView.Active.Map,
                                                                         LayerPosition.AddToTop);
      });&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is a ProSnippet that also addresses this:&lt;/P&gt;&lt;P&gt;&lt;A title="Create layer from a lyrx file" href="https://github.com/Esri/arcgis-pro-sdk/wiki/ProSnippets-MapAuthoring#create-layer-from-a-lyrx-file" target="_self"&gt;Create layer from a lyrx file&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Feb 2021 16:45:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/why-does-cimsqlquerydataconnection-fromjson-choke/m-p/1027670#M6204</guid>
      <dc:creator>UmaHarano</dc:creator>
      <dc:date>2021-02-17T16:45:24Z</dc:date>
    </item>
    <item>
      <title>Re: Why does CIMSqlQueryDataConnection.FromJson choke on queryFields?</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/why-does-cimsqlquerydataconnection-fromjson-choke/m-p/1027759#M6205</link>
      <description>&lt;P&gt;Hi Uma -&lt;/P&gt;&lt;P&gt;Thanks for responding.&amp;nbsp; My question is mainly how CIM deserialization works. I am able to create a featurelayer from an lyrx file as you describe.&lt;/P&gt;&lt;P&gt;So far I have assumed that any json found in a file (aprx, lyrx, etc.) could be deserialized by the FromJson static method on the CIM class.&amp;nbsp;&lt;/P&gt;&lt;P&gt;For this specific use case though, suppose I have a 3rd party (non-Esri) table with geometry columns, and want to dynamically create an SQL query layer.&amp;nbsp; Can I safely do that without writing out an lyrx file?&lt;/P&gt;&lt;P&gt;If so, how does the absence of the queryFields array impact the resulting layer?&lt;/P&gt;&lt;P&gt;Kirk&lt;/P&gt;</description>
      <pubDate>Wed, 17 Feb 2021 18:55:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/why-does-cimsqlquerydataconnection-fromjson-choke/m-p/1027759#M6205</guid>
      <dc:creator>KirkKuykendall1</dc:creator>
      <dc:date>2021-02-17T18:55:15Z</dc:date>
    </item>
    <item>
      <title>Re: Why does CIMSqlQueryDataConnection.FromJson choke on queryFields?</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/why-does-cimsqlquerydataconnection-fromjson-choke/m-p/1027897#M6206</link>
      <description>&lt;P&gt;Hi Kirk&lt;/P&gt;&lt;P&gt;I see the issue you are experiencing. Adding the queryFields array causes the exception. The workflow is successful if I remove the queryFields array (the SQL query is still successfully executed).&amp;nbsp; The table gets successfully added to the map. I couldn't see any impact in the table added to the map.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please remove the queryFields array in your JSON. In the meantime, I will follow-up and see why queryFields inclusion is causing the crash.&lt;/P&gt;&lt;P&gt;Thanks for reporting this!&lt;/P&gt;&lt;P&gt;Uma&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Feb 2021 00:27:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/why-does-cimsqlquerydataconnection-fromjson-choke/m-p/1027897#M6206</guid>
      <dc:creator>UmaHarano</dc:creator>
      <dc:date>2021-02-18T00:27:54Z</dc:date>
    </item>
  </channel>
</rss>

