Please review my projects and let me know if you have any further questions.
Please run the testField App and then run the TFConsoleApp to replicate the issue of FieldDictionary that we are facing
Please suggest if there are any modifications to be made
Nothingâs changed, youâre still trying to do everything Iâve said to avoid doing in my previous answer, i.e. youâre creating a custom Dictionary and youâre using interfaces in types:
[CollectionDataContract(Name = "Field", ItemName = "Field")]
[SDKObjectAttribute]
public partial class FieldDictionary : Dictionary<string, ITProperty>
{
}
Donât. Get rid of the whole concept of FieldDictionary and all other Custom Types that tries to inherit a Dictionary.
Use dictionaries with concrete types instead:
public class Dto
{
public Dictionary<string,string> StringDictionary { get; set; }
public Dictionary<string,Poco> PocoDictionary { get; set; }
}
If you absolutely need to, you can use an object dictionary:
public class Dto
{
public Dictionary<string,object> ObjectDictionary { get; set; }
}
But this has all the issues of using object and interfaces in DTOs, i.e. it wont work in non .NET Add ServiceStack Reference languages.
I have got rid of inheritance like you told but still response.Fields.StringDictionary is null on running my console app
Below is my modified project and the console app
Please run the app âtestField.slnâ and the console app âTFConsoleApp.slnâ to replicate the issue.
You can find my modfications that you had mentioned to change in the below 2 files
JSON payload i am trying to deserialize is the âHelloResponseâ object i.e the âFieldsâ property of type âDtoâ class, which contains a dictionary of string key-value pair.
In my Dto class i have added a âStringDictionaryâ property
public class Dto
{
public Dictionary<string, string> StringDictionary { get; set; }
}
In the Get method of my service, I have a HelloResponse object and its Fields property with a new instance of the Dto class. Inside the Dto class, I have initialized the StringDictionary property with some predefined key-value pairs for demonstration purpose.
Below is the code
public object Get(Hello request)
{
var response = new HelloResponse
{
Fields = new Dto
{
StringDictionary = new Dictionary<string, string>
{
{ "Key1", "value1" },
{ "Key2", "value2" }
}
}
};
return response;
}
Note sure what issue Iâm meant to be looking at, the GitHub - sahanar28/TFConsoleApp_2 project doesnât compile, but Iâve copied/pasted the sample source code into a test project in ApptestField, had to fix the Base URL, but otherwise runs without issue:
[Test]
public void Test_Hello_Api()
{
// Should only contain the **BaseUrl** of the ServiceStack Server
var client = new JsonServiceClient("https://localhost:5001");
ServicePointManager.ServerCertificateValidationCallback += (_, _, _, _) => true;
Hello request = new Hello() { Name = "World" };
HelloResponse response = client.Get<HelloResponse>(request);
if (response != null)
{
response.Fields.PrintDump();
var fields = response.Fields;
}
else
{
Console.WriteLine("No response received.");
}
}
Yes what you have tried will work for us as well but what is not working is when we run the console app for the ApptestField__2 application by referencing the ServiceStack dlls of version 6.9 and try to retrieve the Fields property, response.Fields.StringDictionary is null
After opening my ApptestField__2 project in visual studio, In the Solution Explorer > TFConsoleApp > Dependencies > Assemblies > Can you please remove the existing Assemblies. Though i have referenced them not sure after extracting it is not loading properly
[MyApp.dll, MyApp.ServiceInterface.dll, MyApp.ServiceModel.dll, ServiceStack.dll, ServiceStack.Client.dll, ServiceStack.Common.dll, ServiceStack.Interfaces.dll, ServiceStack.Text.dll, System.Data.SQLite.dll]
So could you please add these above mentioned assemblies again from \ApptestField__2-master\ApptestField__2-master\MyApp\bin\Debug\net6.0
You should not be uploading binaries to source projects or including internal references to them, replace them with Package References so they can be built and run by others.
Your issue is due to your custom configuration breaking the deserialization, youâre even suppressing the Exception thatâs thrown with an empty catch block so you must already know about the issue your code is causing.