Replies: 3 comments 1 reply
-
Can you share the stack trace and your data provider configuration? |
Beta Was this translation helpful? Give feedback.
-
Using the Cosmos Data Provider.
Apologize for the formatting, doesnt seem to maintain the new lines on a quote/codeblock. Also just doing a var test = JsonSerializer.Serialize(entity); works just fine for our bitArray. |
Beta Was this translation helpful? Give feedback.
-
The problem is that System.Text.Json cannot properly deserialize BitArray, please check this SO answer. One option is to use Audit.NET's Newtonsoft.Json adapter with the custom JsonConverter from that answer:
Audit.Core.Configuration.Setup()
.JsonNewtonsoftAdapter(new JsonSerializerSettings()
{
Converters = new List<JsonConverter>() { new BitArrayConverter() }
}); |
Beta Was this translation helpful? Give feedback.
-
For us, running an AuditScope on our EF models runs fine on an entity that doesn't have a BitArray in it, but throws an exception on the entity that does have a BitArray that is attempted to be serialized into an audit event.
Exception we are getting after running an audit scope through our entity
The collection type 'System.Collections.BitArray is abstract, an interface, or is read only, and could not be instantiated and populated. Path: $.PrivilegeSet | LineNumber: 0 | BytePositionInLine: 17."
Our entity setup for PrivilegeSet
`
public Role ( BitArray privilegeSet )
{
this.privilegeSet = privilegeSet;
}
private BitArray privilegeSet;
public BitArray PrivilegeSet
{
get => privilegeSet;
set => Set(ref this.privilegeSet, value, RoleField.PrivilegeSet);
}`
We tried serializing a basic BitArray using both Json.NET and NewtonSoft.JSON and both worked without issue. Our project using Audit.NET is targeting NET 7.0. Any ideas on why we are getting this error with the BitArray property here when running it through an audit scope?
Thank you.
Beta Was this translation helpful? Give feedback.
All reactions