/// <devdoc> /// <para>Deserializes a LOS formatted object from a string.</para> /// </devdoc> public object Deserialize(string input) { #if NO_BASE64 char[] data = input.ToCharArray(); #else byte[] dataBytes = Convert.FromBase64String(input); int dataLength = -1; if (EnableViewStateMac) { try { dataBytes = MachineKeySection.GetDecodedData(dataBytes, _macKey, 0, dataBytes.Length, ref dataLength); } catch (Exception e) { PerfCounters.IncrementCounter(AppPerfCounter.VIEWSTATE_MAC_FAIL); ViewStateException.ThrowMacValidationError(e, input); } } if (dataLength == -1) { dataLength = dataBytes.Length; } char[] data = EncodingInstance.GetChars(dataBytes, 0, dataLength); #endif // clear or allocate name and type tables. // if (_deserializedTypeTable == null) { _deserializedTypeTable = new ArrayList(); _deserializedConverterTable = new ListDictionary(); } else { _deserializedTypeTable.Clear(); _deserializedConverterTable.Clear(); } _builder = (char[])_charBufferAllocator.GetBuffer(); _recyclable = true; // DeserializeValueInternal is recursive, so we just kick this off // starting at 0 _current = 0; _deserializationData = data; object ret = DeserializeValueInternal(); if (_recyclable) { _charBufferAllocator.ReuseBuffer(_builder); } return(ret); }
public object Deserialize(string inputString) { if (string.IsNullOrEmpty(inputString)) { throw new ArgumentNullException("inputString"); } byte[] buf = Convert.FromBase64String(inputString); int length = buf.Length; try { if ((this._page != null) && this._page.ContainsEncryptedViewState) { buf = MachineKeySection.EncryptOrDecryptData(false, buf, this.GetMacKeyModifier(), 0, length); length = buf.Length; } else if (((this._page != null) && this._page.EnableViewStateMac) || (this._macKeyBytes != null)) { buf = MachineKeySection.GetDecodedData(buf, this.GetMacKeyModifier(), 0, length, ref length); } } catch { PerfCounters.IncrementCounter(AppPerfCounter.VIEWSTATE_MAC_FAIL); ViewStateException.ThrowMacValidationError(null, inputString); } object obj2 = null; MemoryStream memoryStream = GetMemoryStream(); try { memoryStream.Write(buf, 0, length); memoryStream.Position = 0L; obj2 = this.Deserialize(memoryStream); } finally { ReleaseMemoryStream(memoryStream); } return(obj2); }