X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2Fcorlib%2FSystem.Runtime.Serialization.Formatters.Binary%2FBinaryFormatter.cs;h=4d4756e150d5a16689db6d7109feaaad950c38eb;hb=dd4a7237548f86e97a613983827f57db2bcd81e2;hp=57f770516d2ce76cc1d12bda500da9410d38a447;hpb=92f60fbffa1187be7dedf6a9286b5c35b2082815;p=mono.git diff --git a/mcs/class/corlib/System.Runtime.Serialization.Formatters.Binary/BinaryFormatter.cs b/mcs/class/corlib/System.Runtime.Serialization.Formatters.Binary/BinaryFormatter.cs index 57f770516d2..4d4756e150d 100644 --- a/mcs/class/corlib/System.Runtime.Serialization.Formatters.Binary/BinaryFormatter.cs +++ b/mcs/class/corlib/System.Runtime.Serialization.Formatters.Binary/BinaryFormatter.cs @@ -37,7 +37,11 @@ using System.Security.Permissions; namespace System.Runtime.Serialization.Formatters.Binary { [ComVisible (true)] - public sealed class BinaryFormatter : IRemotingFormatter, IFormatter + public sealed class BinaryFormatter : +#if !FULL_AOT_RUNTIME + IRemotingFormatter, +#endif + IFormatter { private FormatterAssemblyStyle assembly_format = FormatterAssemblyStyle.Simple; private SerializationBinder binder; @@ -48,7 +52,7 @@ namespace System.Runtime.Serialization.Formatters.Binary { public BinaryFormatter() { - surrogate_selector=null; + surrogate_selector=DefaultSurrogateSelector; context=new StreamingContext(StreamingContextStates.All); } @@ -57,7 +61,17 @@ namespace System.Runtime.Serialization.Formatters.Binary { surrogate_selector=selector; this.context=context; } + + // Deserializing objects of type Dictionary<,> List<> and friends does not work in a CoreCLR sandbox, because + // the default deserialization code uses reflection to do its job, and the fields being reflected on live in mscorlib.dll. + // DefaultSurrogateSelector enables embedders to provide an alternative method of deserializing specific types in a way + // that does not violate the CoreCLR rules. See https://gist.github.com/878267 for some actual code that provides CoreCLR safe + // deserialization code for List<> and Dictionary<,>. + // DefaultSurrogateSelector is private, and needs to be set by the embedder trough reflection, so we do not expose any public + // API point that is not present in .NET + static ISurrogateSelector DefaultSurrogateSelector { get; set; } + public FormatterAssemblyStyle AssemblyFormat { get {