internal bool ReadWordFrequencyMap() { bool result; using (UserConfiguration userConfiguration = this.OpenMessage(true)) { if (userConfiguration == null) { TopNConfiguration.Tracer.TraceError <TopNConfiguration>((long)this.GetHashCode(), "{0}: FAI could not be opened or created.", this); result = false; } else { using (Stream stream = userConfiguration.GetStream()) { Exception ex = null; try { Type[] allowList = new Type[] { typeof(KeyValuePair <string, int>) }; this.wordFrequency = (KeyValuePair <string, int>[])SafeSerialization.SafeBinaryFormatterDeserializeWithAllowList(stream, allowList, null); } catch (SafeSerialization.BlockedTypeException ex2) { ex = ex2; } catch (ArgumentNullException ex3) { ex = ex3; } catch (SerializationException ex4) { ex = ex4; } catch (Exception ex5) { ex = ex5; } if (ex != null) { TopNConfiguration.Tracer.TraceError <TopNConfiguration, Exception>((long)this.GetHashCode(), "{0}: FAI message is corrupt. Exception: {1}", this, ex); result = false; } else { result = true; } } } } return(result); }
public static bool IsSafeBinaryFormatterStreamWithAllowList(Stream serializationStream, IEnumerable <Type> allowList, SafeSerialization.TypeEncounteredDelegate typeEncounteredCallback = null) { return(SafeSerialization.IsSafeBinaryFormatterStreamCommon(new SafeSerialization.ValidatingBinder(new SafeSerialization.AllowList(allowList), typeEncounteredCallback), serializationStream)); }