pticrix
pticrix
CC#
Created by pticrix on 1/13/2023 in #help
✅ JSON Contract : modifying the value of a property, using System.Text.Json 7
Hello! I'm trying to encrypt only certain fields in a DTO before serializing them, using an attribute in the class definition. The attribute part I got the hang of, however I'm uncertain about how to go about modifying the value of a given property. Here's what I've been doing, trying to follow the tips from this dev blog : https://devblogs.microsoft.com/dotnet/system-text-json-in-dotnet-7/ - extend the DefaultJsonTypeInfoResolver class - override the GetTypeInfo(Type, JsonSerializerOptions) method - in that method, 'reject' anything that isn't of Kind JsonTypeInfoKind.Object - iterate on the JsonPropertyInfo list returned by JsonTypeInfo.Properties  - check each of the JsonPropertyInfo.AttributeProvider to see if they are ICustomAttributeProvider and if my custom attribute is defined in it. Once I've confirmed that, that is where I'm kinda lost. It's probably dumb, but I haven't managed yet to find what to do from here. I'm thinking either : - I need to change the delegate method of JsonPropertyInfo.Get and JsonPropertyInfo.Set or - I need to tell it here and there to take the property value and to pass it through my encryption method. Anyone here could point me to the correct way to proceed? Current code :
public override JsonTypeInfo GetTypeInfo(Type type, JsonSerializerOptions options)
{
JsonTypeInfo typeInfo = base.GetTypeInfo(type, options);
if (typeInfo.Kind != JsonTypeInfoKind.Object) return typeInfo;

foreach (JsonPropertyInfo propertyInfo in typeInfo.Properties)
{
if (propertyInfo.AttributeProvider is ICustomAttributeProvider provider &&
provider.IsDefined(typeof(JsonEncryptAttribute), inherit: true))
{
# todo : Unsure how to proceed here.
}
}
return typeInfo;
}
public override JsonTypeInfo GetTypeInfo(Type type, JsonSerializerOptions options)
{
JsonTypeInfo typeInfo = base.GetTypeInfo(type, options);
if (typeInfo.Kind != JsonTypeInfoKind.Object) return typeInfo;

foreach (JsonPropertyInfo propertyInfo in typeInfo.Properties)
{
if (propertyInfo.AttributeProvider is ICustomAttributeProvider provider &&
provider.IsDefined(typeof(JsonEncryptAttribute), inherit: true))
{
# todo : Unsure how to proceed here.
}
}
return typeInfo;
}
Any insight appreciated.
4 replies
CC#
Created by pticrix on 9/28/2022 in #help
System.Net.Sockets spookyness
Hello! : I've been tasked with updating our web app backend to .net 6 and I am almost done. However, while it was working fine locally and on our Dev environment, I've hit a wall when trying to deploy in our QA environment. Here's what's happening : - Running our app on our QA environment gives me an error I don't get on other environment - OSes : - Dev environment runs on Windows Server 2012 R2 ; - QA runs on Windows Server 2016 ; - Local is Windows 10 Pro - When trying to connect to other processes, I get the following exception : System.PlatformNotSupportedException: 'Operation is not supported on this platform.' - Exception is triggered by System.Net.Sockets.UnixDomainSocketEndPoint - My research seems to indicate that Windows Server 2016 does not support UDS. But it isn't supported by Windows Server 2012 R2 either, where the build runs without any problem I can't get try to run in debug on WS2012 R2, since VS 2022 isn't compatible with it. But I guess this is due to what it decides to try and call via the Kestrel Server, which only has port registration on Listen(int 32) if the config specifies IP and Port, and ListenAnyIP if the config has a port, but no specific IP. So, Listen UnixSocket(...) is never explicitly called. Anyone faced something similar and know what could be happening here? Thanks!
87 replies