OkOk
OkOk
CC#
Created by OkOk on 11/25/2023 in #help
JsonSerializer.Deserialize will not translate number to string
I am trying to deserialize JSON into an object and one of the JSON values is a is sometimes a string and sometimes a number which will not translate into a string property of an object. Previous forum questions recommend using the attribute JsonNumberHandling to translate possible numbers into strings but it doesn't seem to work in my simple example. My usage:
public class Extensions
{
[JsonNumberHandling(JsonNumberHandling.WriteAsString)]
public string position { get; set; }
}


HttpResponseMessage response = await client.GetAsync(urlTjänsteDomän);
PageResponse? page = JsonSerializer.Deserialize<PageResponse>(await response.Content.ReadAsStringAsync());
public class Extensions
{
[JsonNumberHandling(JsonNumberHandling.WriteAsString)]
public string position { get; set; }
}


HttpResponseMessage response = await client.GetAsync(urlTjänsteDomän);
PageResponse? page = JsonSerializer.Deserialize<PageResponse>(await response.Content.ReadAsStringAsync());
My error: System.InvalidOperationException: ''JsonNumberHandlingAttribute' is only valid on a number or a collection of numbers when applied to a property or field. See member 'position' on type 'Confluence.Domain.Info.Generator.Extensions'.'
20 replies
CC#
Created by OkOk on 11/25/2023 in #help
✅ "Paste JSON as classes" functionality in VS
If your JSON has two keys of the same name with different values inside, should you let VS create multiple classes called "exampleClass" and "exampleClass1" or should you create one single class that contains all of these properties? Example JSON: "{ "results": [ { "id": "73827820", "_links": { "webui": "/pages/viewpage.action?pageId=73827820", "edit": "/pages/resumedraft.action?draftId=73827820&draftShareId=f7777609-f3b9-4875-8904-e3b99c6870b4", "tinyui": "/x/7IVmB", "self": "https://confluence.vll.se/rest/api/content/73827820" }, } ], "start": 0, "limit": 25, "size": 1, "_links": { "self": "https://confluence.vll.se/rest/api/content?spaceKey=~LONO05&title=Tj%C3%A4nstedom%C3%A4ner2", "base": "https://confluence.vll.se", "context": "" } }" Pasting this will make VS generate the classes public class _Links { public string self { get; set; } public string _base { get; set; } public string context { get; set; } } and public class _Links1 { public string webui { get; set; } public string edit { get; set; } public string tinyui { get; set; } public string self { get; set; } } Should I instead create only the class "_Links" and have it contain all of the combined properties like so? public class _Links { public string self { get; set; } public string _base { get; set; } public string context { get; set; } public string webui { get; set; } public string edit { get; set; } public string tinyui { get; set; } public string self { get; set; } }
5 replies
CC#
Created by OkOk on 10/19/2023 in #help
❔ Possible to copy value of object in debugger and generate code which will recreate this object
No description
3 replies
CC#
Created by OkOk on 10/16/2023 in #help
❔ EF Migration successful but nothing changes
No description
59 replies
CC#
Created by OkOk on 10/13/2023 in #help
❔ Visual Studio - How to write out all properties when instansiating a class?
I would like to write out all properties automatically when creating an object Seems like something VS would have a solution for? (Could not find my answer on stackoverflow/chatgpt)
24 replies
CC#
Created by OkOk on 10/4/2023 in #help
❔ Program can't find folder
No description
38 replies
CC#
Created by OkOk on 9/29/2023 in #help
❔ ✅ C# program can't find folder in the very same directory
No description
60 replies
CC#
Created by OkOk on 9/26/2023 in #help
❔ Has anyone used the API for Confluence?
I'm noticing some buggy behavior, successful PUT-requests that do not change some pages, anyone who knows if I've officially lost my mind?
4 replies
CC#
Created by OkOk on 9/7/2023 in #help
❔ Why are most tests choosing not to run in Visual Studio?
2 replies
CC#
Created by OkOk on 8/30/2023 in #help
❔ Smart Regex
Is there some general Regex that websites apply to find the most matching alternative from a list of words? Example: A customer searches for "DogService.v1.Google" Now the regex needs to be able to determine if that is closer to one of these two alternatives: "CatService.V1" "DogSvc.Google"
9 replies
CC#
Created by OkOk on 8/11/2023 in #help
✅ Simple string formatting
14 replies
CC#
Created by OkOk on 7/9/2023 in #help
❔ What makes two Controllers work differently?
70 replies
CC#
Created by OkOk on 6/19/2023 in #help
❔ ✅ Search for specific value that is contained inside some variable while debugging VS
When debugging a large project, I know that one of my many variables will contain a string valled "ValueX". I need to find what the name of the variable that contains the value "ValueX". There are so many objects and nestings that I need to "Search" for the value, it is not good enough to manually look at every local variable.
3 replies
CC#
Created by OkOk on 5/26/2023 in #help
❔ Enabling "Always Encrypted" created a clash of datatypes
My normal working code
_dbContext.MyClass.Add(MyObject);
_dbContext.MyClass.Add(MyObject);
crashes when enabling encryption and saving. Operand type clash: nvarchar is incompatible with nvarchar(4000) encrypted.. I tried changing forcing the nvarchar to 4000 and I enabled everything I saw in the docs.
28 replies