You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In restricted CAS environment including browser based SIlverlight Application,
non-public member access via reflection causes runtime error.
This should be opt-out because:
* Some people may decide to grant reflection permission for interoperability.
* But many people should decide to use public entities/DTOs instead of permission grant.
This option gives selection for app developers.
This commit also adds unit test in full trust mode.
Copy file name to clipboardExpand all lines: CHANGES.txt
+2Lines changed: 2 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -623,6 +623,7 @@ Release 0.9.0 (planned)
623
623
* Users of serializer code generator API can specify TextWriter to output. This may improve tooling chain.
624
624
* Users of serializer code generator API can suppress [DebuggerNonUserCode] attribute to enable debugger step in.
625
625
* SerializerRepository API now expose ContainsFor and GetRegisteredSerializers methods to investigate registered serializers.
626
+
* SerializationContext.DisablePrivilegedAccess for restricted environment like Silverlight to select between granting permission or relinquish non-public access.
626
627
627
628
BUG FIXES
628
629
* The generated code for the type which has Tuple typed member uses old PackHelper API.
@@ -633,4 +634,5 @@ Release 0.9.0 (planned)
633
634
* Fix some built-in serializers throws InvalidOperationException instead of SerializationException for type errors. Issue #204
634
635
* Fix a combination of readonly members and collection members incorrect code generation when the type also have deserialization constructor. Issue #207.
635
636
* Fix Windows Native build error. Issue #206.
637
+
* Fix built-in collection serializers such as List<T> serializer causes SecurityException when the program run in restricted environment like Silverlight. Issue #205.
thrownewSerializationException(String.Format(CultureInfo.CurrentCulture,"Cannot serialize type '{0}' because it is not public to the serializer.",targetType));
thrownewSerializationException(String.Format(CultureInfo.CurrentCulture,"Cannot serialize type '{0}' because it does not have any serializable fields nor properties.",targetType));
Copy file name to clipboardExpand all lines: src/MsgPack/Serialization/SerializerOptions.cs
+41Lines changed: 41 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -137,6 +137,47 @@ public bool DisableRuntimeCodeGeneration
137
137
}
138
138
#endif // !AOT
139
139
140
+
#if !FEATURE_CONCURRENT
141
+
privatevolatilebool_isNonPublicAccessDisabled;
142
+
#else
143
+
privatebool_isNonPublicAccessDisabled;
144
+
#endif // !FEATURE_CONCURRENT
145
+
146
+
/// <summary>
147
+
/// Gets or sets a value indicating whether generated and/or reflection serializers should not access non public members via privileged reflection.
148
+
/// </summary>
149
+
/// <value>
150
+
/// <c>true</c> if privileged reflection access is disabled; otherwise, <c>false</c>. Defaults to <c>false</c>.
151
+
/// </value>
152
+
/// <remarks>
153
+
/// The privileged reflection means:
154
+
/// <list type="bullet">
155
+
/// <item>Access for non-public fields or property accessors via reflection. This operation requires <c>ReflectionPermission</c> of <c>MemberAccess</c> or <c>RestrictedMemberAccess</c>.</item>
156
+
/// <item>Writing values for init only fields via reflection. This operation requires <c>SecurityPermission</c> of <c>SerializationFormatter</c>.</item>
157
+
/// </list>
158
+
/// If the program run on non-privileged Silverlight environment or restricted desktop CLR,
159
+
/// serialization and deserialization should fail with <c>SecurityException</c>.
0 commit comments