Using FeatureSet in C# script
Trying to add a feature in a C# Script activity but it is failing with an exception - it happens even with a simple line like updatedFeatures = new FeatureSet();
Does this mean that FeatureSet class cannot be used with C# activities ?
Error details
---------------------------
---------------------------
Unhandled exception: 'Type 'ESRI.ArcGIS.Client.Tasks.FeatureSet' in assembly 'ESRI.ArcGIS.Client, Version=10.2.5.0, Culture=neutral, PublicKeyToken=29c6dd6e8553d944' is not marked as serializable.' in activity '1.29: CSharpScript'.
---------------------------
OK
---------------------------
0
-
I suspect that the featureset created at the server cannot be sent to the client, as it cannot be serialized.
C# script activity is a server side activity. If you want to use a client side object such as a featureset then the object must be serialized (https://en.wikipedia.org/wiki/Serialization) to a datastream This object must have a serialization attribute ('marked') in order to allow this to happen. And, as the error message states, a featureset (an object defined by esri code) does not have this attribute.
If you do not need the FeatureSet itself when the code in the C# script activity is completed, then actively destroy the object by setting it to null in the code. For example, in the small snippet below, the created FeatureSet is written to a json string before the FeatureSet itself is set to null. As a string object is marked as serializable, it can be passed back to the client side of the workflow and used there to re-instantiate the featureset geometries.fstest = new FeatureSet(string1); test = fstest.ToJson(); fstest = null;0 -
Hi Darko,
Arjan is correct. This issue is not that the class cannot be used by the script activity, it is due to the transfer of state from server to client.
We do not recommend using the C# Script or VB Script activities for anything beyond proof-of-concept tests or development. In production, please convert your activities to use native Invoke Method and Assign activities, or compile a custom assembly to do your owrk. The Script activities will consume memory and files every time they are loaded and we have no way to recover; evenutally the app pool will crash.
Regards,
-Malcolm0
Du måste logga in om du vill lämna en kommentar.
Kommentarer
2 kommentarer