Question

System.Text and System.Text.Json -Assembly reference missing

I am getting this error in my Business Process "The type or namespace name 'Json' does not exist in the namespace 'System.Text' (are you missing an assembly reference?)". 

Briefly- The Business Process connects to a REST API, reads a Collection of Objects and stores the data in Creatio Object. 

using System;

using System.IO;

using System.Net;

using System.Linq;

using System.Net.Http;

using System.Text;

using System.Text.Json;

using Newtonsoft.Json.Linq;

using Newtonsoft.Json;

using Terrasoft.Core;

using Terrasoft.Core.DB;

using Terrasoft.Core.Entities;

using Terrasoft.Core.Configuration;



public void ProcessDataFromAPIResponse()

{

    var stuff = UserConnection.EntitySchemaManager.GetInstanceByName("UsrEntity_Schema").CreateEntity(UserConnection);

    HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://**************************************");

            request.Method = "POST";

            request.ContentType = "application/json";

            string postData = "";

            byte[] bytes = Encoding.UTF8.GetBytes(postData);

            request.ContentLength = bytes.Length;

            Stream requestStream = request.GetRequestStream();

            requestStream.Write(bytes, 0, bytes.Length);

            

    var httpResponse = (HttpWebResponse) request.GetResponse();

    var streamReader = new StreamReader(httpResponse.GetResponseStream());

            

                string result = streamReader.ReadToEnd().ToString();

                var doc = System.Text.Json.JsonDocument.Parse(result);

                System.Text.Json.JsonElement root = doc.RootElement;

                var applns = root.EnumerateArray();

                while (applns.MoveNext())

                {

                    var appln = applns.Current;

                    //Console.WriteLine(appln);

                    var props = appln.EnumerateObject();

                    while(props.MoveNext())

                    {

                        var prop = props.Current;

                        if(prop.Name=="FirstName" )

                        {

                                staffing.SetDefColumnValues();

                                stuff.SetColumnValue("UsrFirstName", prop.value);

                        }

                        if(prop.Name == "LastName" )

                        {

                                stuff.SetDefColumnValues();

                                stuff.SetColumnValue("UsrLastName", prop.value);

                        

                        }

                        if(prop.Name == "BusinessPhone")

                        {

                                stuff.SetDefColumnValues();

                                stuff.SetColumnValue("UsrBusPhone",prop.value);

                        

                        }

                        if(prop.Name == "EmployeesCanada")

                        {

                                stuff.SetDefColumnValues();

                                stuff.SetColumnValue("UsrCAEmployees", Convert.ToInt32(prop.value));

                        

                        }

                        if( prop.Name == "TotalGrossRevenueCurrent" )

                        {

                                stuff.SetDefColumnValues();

                                stuff.SetColumnValue("UsrSalesRevenue", Convert.ToDecimal(prop.value));

                        

                        }

                       if( prop.Name == "id" )

                        {

                                stuff.SetDefColumnValues();

                                stuff.SetColumnValue("UsrApplnId", Convert.ToDecimal(prop.value));

                        

                        }

                        

                        

                            stuff.Save(false, false);

                    }

                }

            streamReader.Dispose();

            

}

Like 0

Like

4 comments

I don't believe Creatio uses the necessary .NET version to include System.Text.Json - IIRC I believe that is in .NET 6 and for earlier versions the NuGet package is available. 

You could change the JSON handling to use the Newtonsoft Json.Net library which is included in Creatio or try adding the assembly from the NuGet package as a DLL in your package (I'd go the route of using the Newtonsoft library)

Ryan

Ryan Farley,

Ok, I will try with 

Newtonsoft Json.Net library. Thanks Ryan

 

I don't know if you are still watching this thread Ryan, but if you are can ask a quick question, what is the namespace for Newtonsoft to add to the process Process > Methods > Using list?

Gareth Osler writes:

I don't know if you are still watching this thread Ryan, but if you are can ask a quick question, what is the namespace for Newtonsoft to add to the process Process > Methods > Using list?

Hi Can you please share how did you managed to use Newtonsoft.

Show all comments