-Handle partial trust when creating uninitialized objects

This commit is contained in:
James Newton-King
2012-07-14 11:56:38 +12:00
parent cfb2499a35
commit 55a09d2f73
6 changed files with 57 additions and 9 deletions
@@ -24,9 +24,11 @@
#endregion
using System;
using System.Globalization;
using System.Reflection;
using System.Runtime.Serialization;
using System.Security;
using Newtonsoft.Json.Utilities;
namespace Newtonsoft.Json.Serialization
{
@@ -118,9 +120,15 @@ namespace Newtonsoft.Json.Serialization
}
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE)
#if !(NET20 || NET35)
[SecuritySafeCritical]
#endif
internal object GetUninitializedObject()
{
// we should never get here if the environment is not fully trusted, check just in case
if (!JsonTypeReflector.FullyTrusted)
throw new JsonException("Insufficient permissions. Creating an uninitialized '{0}' type requires full trust.".FormatWith(CultureInfo.InvariantCulture, NonNullableUnderlyingType));
return FormatterServices.GetUninitializedObject(NonNullableUnderlyingType);
}
#endif