Summary
When consuming Casper.Network.SDK from a .NET file-based application, JSON serialization fails with:
Reflection-based serialization has been disabled for this application.
Either use the source generator APIs or explicitly configure the
'JsonSerializerOptions.TypeInfoResolver' property.
The failure originates from RpcMethod.Serialize(), which assumes reflection-based System.Text.Json serialization is available.
Why this matters
Modern .NET applications (including trimmed, Native AOT, and some file-based app scenarios) may disable reflection-based JSON serialization by default. As a result, the SDK cannot be used without consumers explicitly changing their application configuration.
A reusable SDK should ideally not depend on this application-level setting.
Proposed solution
Preferred (long-term)
Adopt System.Text.Json source generation (JsonSerializerContext) for all request and response types used by the SDK.
Benefits:
- Supports trimmed applications.
- Supports Native AOT.
- Removes the SDK's dependency on reflection-based serialization.
- Improves startup performance.
- Follows Microsoft's recommended approach for modern .NET libraries.
Possible short-term workaround
Where JsonSerializerOptions are created, configure a DefaultJsonTypeInfoResolver when no resolver has been supplied by the application.
Reproduction
- Create a .NET file-based application.
- Reference the SDK using
#:project.
- Invoke an RPC method such as
GetAccountInfo().
- Observe the exception during request serialization:
Reflection-based serialization has been disabled for this application.
Either use the source generator APIs or explicitly configure the
'JsonSerializerOptions.TypeInfoResolver' property.
Additional notes
Although this was first encountered from a .NET file-based app, the underlying issue is not specific to file-based apps. It can affect any application that disables reflection-based System.Text.Json serialization (for example, trimmed or Native AOT applications).
Summary
When consuming
Casper.Network.SDKfrom a .NET file-based application, JSON serialization fails with:The failure originates from
RpcMethod.Serialize(), which assumes reflection-basedSystem.Text.Jsonserialization is available.Why this matters
Modern .NET applications (including trimmed, Native AOT, and some file-based app scenarios) may disable reflection-based JSON serialization by default. As a result, the SDK cannot be used without consumers explicitly changing their application configuration.
A reusable SDK should ideally not depend on this application-level setting.
Proposed solution
Preferred (long-term)
Adopt
System.Text.Jsonsource generation (JsonSerializerContext) for all request and response types used by the SDK.Benefits:
Possible short-term workaround
Where
JsonSerializerOptionsare created, configure aDefaultJsonTypeInfoResolverwhen no resolver has been supplied by the application.Reproduction
#:project.GetAccountInfo().Additional notes
Although this was first encountered from a .NET file-based app, the underlying issue is not specific to file-based apps. It can affect any application that disables reflection-based
System.Text.Jsonserialization (for example, trimmed or Native AOT applications).