dotnet / dotnet/dotnet-api-docs

Document correct serialization of exceptions in security-transparent assemblies

Open
#3,595 3 comments 0 reactions 0 assignees View on GitHub
area-System.Runtime Pri3 untriaged
Dominant language
C#
Stars
949
Forks
1.7k
Avg merge
3d 27m
Merged PRs (30d)
49

Description

When implementing exceptions with state, it's necessary to implement serialization in order to allow such exceptions to pass AppDomain boundaries. Up to .NET 4, this was done simply by overriding `GetObjectData` and providing a deserialization constructor.

Starting with .NET 4 and its security model, this is no longer possible with assemblies that have the `AllowPartiallyTrustedCallersAttribute`. As these are loaded to be security-transparent, they cannot override `GetObjectData`. .NET 4 therefore added `Exception.SerializeObjectState` (https://docs.microsoft.com/de-de/dotnet/api/system.exception.serializeobjectstate?view=netframework-4.7.1), thus defining a new pattern for serializable exceptions.

This new pattern is however insufficiently documented. It should be explained in the "Remarks" sections of both the `System.Exception` class (https://docs.microsoft.com/de-de/dotnet/api/system.exception?view=netframework-4.7.1) and the `Exception.GetObjectData` method (https://docs.microsoft.com/de-de/dotnet/api/system.exception.getobjectdata?view=netframework-4.7.1#System_Exception_GetObjectData_System_Runtime_Serialization_SerializationInfo_System_Runtime_Serialization_StreamingContext_).

Contributor guide

Open the contributing guide

Research direction

Start with the System.Exception and Exception.GetObjectData API reference pages named in the issue, then read the Exception.SerializeObjectState documentation for the .NET 4 security-transparent assembly pattern. Update the Remarks sections on both pages to explain the correct serialization approach; the work is done when the pattern and its limitations are clearly documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.