Split off the Serialization namespace into a new assembly.
diff --git a/src/ProtoBench/ProtoBench.csproj b/src/ProtoBench/ProtoBench.csproj
index 7722f8d..d2c526d 100644
--- a/src/ProtoBench/ProtoBench.csproj
+++ b/src/ProtoBench/ProtoBench.csproj
@@ -72,6 +72,11 @@
     <Compile Include="Properties\AssemblyInfo.cs" />

   </ItemGroup>

   <ItemGroup>

+    <ProjectReference Include="..\ProtocolBuffers.Serialization\ProtocolBuffers.Serialization.csproj">

+      <Project>{231391AF-449C-4a39-986C-AD7F270F4750}</Project>

+      <Name>ProtocolBuffers.Serialization</Name>

+      <Private>True</Private>

+    </ProjectReference>

     <ProjectReference Include="..\ProtocolBuffers\ProtocolBuffers.csproj">

       <Project>{6908BDCE-D925-43F3-94AC-A531E6DF2591}</Project>

       <Name>ProtocolBuffers</Name>

diff --git a/src/ProtocolBuffers/Serialization/AbstractReader.cs b/src/ProtocolBuffers.Serialization/AbstractReader.cs
similarity index 95%
rename from src/ProtocolBuffers/Serialization/AbstractReader.cs
rename to src/ProtocolBuffers.Serialization/AbstractReader.cs
index bc1fa6c..f54c270 100644
--- a/src/ProtocolBuffers/Serialization/AbstractReader.cs
+++ b/src/ProtocolBuffers.Serialization/AbstractReader.cs
@@ -12,8 +12,20 @@
     /// </summary>

     public abstract class AbstractReader : ICodedInputStream

     {

-        private const int MaxDepth = CodedInputStream.DefaultRecursionLimit;

-        protected int Depth;

+        private const int DefaultMaxDepth = 64;

+        private int _depth;

+        

+        /// <summary> Constructs a new reader </summary>

+        protected AbstractReader() { MaxDepth = DefaultMaxDepth; }

+        /// <summary> Constructs a new child reader </summary>

+        protected AbstractReader(AbstractReader copyFrom)

+        {

+            _depth = copyFrom._depth + 1;

+            MaxDepth = copyFrom.MaxDepth;

+        }

+

+        /// <summary> Gets or sets the maximum recursion depth allowed </summary>

+        public int MaxDepth { get; set; }

 

         /// <summary>

         /// Merges the contents of stream into the provided message builder

@@ -395,12 +407,12 @@
 

         void ICodedInputStream.ReadGroup(int fieldNumber, IBuilderLite builder, ExtensionRegistry extensionRegistry)

         {

-            if (Depth++ > MaxDepth)

+            if (_depth++ > MaxDepth)

             {

-                throw InvalidProtocolBufferException.RecursionLimitExceeded();

+                throw new RecursionLimitExceededException();

             }

             ReadGroup(builder, extensionRegistry);

-            Depth--;

+            _depth--;

         }

 

         void ICodedInputStream.ReadUnknownGroup(int fieldNumber, IBuilderLite builder)

@@ -410,12 +422,12 @@
 

         void ICodedInputStream.ReadMessage(IBuilderLite builder, ExtensionRegistry extensionRegistry)

         {

-            if (Depth++ > MaxDepth)

+            if (_depth++ > MaxDepth)

             {

-                throw InvalidProtocolBufferException.RecursionLimitExceeded();

+                throw new RecursionLimitExceededException();

             }

             ReadMessage(builder, extensionRegistry);

-            Depth--;

+            _depth--;

         }

 

         bool ICodedInputStream.ReadBytes(ref ByteString value)

@@ -566,23 +578,23 @@
         void ICodedInputStream.ReadMessageArray<T>(uint fieldTag, string fieldName, ICollection<T> list, T messageType,

                                                    ExtensionRegistry registry)

         {

-            if (Depth++ > MaxDepth)

+            if (_depth++ > MaxDepth)

             {

-                throw InvalidProtocolBufferException.RecursionLimitExceeded();

+                throw new RecursionLimitExceededException();

             }

             ReadMessageArray(fieldName, list, messageType, registry);

-            Depth--;

+            _depth--;

         }

 

         void ICodedInputStream.ReadGroupArray<T>(uint fieldTag, string fieldName, ICollection<T> list, T messageType,

                                                  ExtensionRegistry registry)

         {

-            if (Depth++ > MaxDepth)

+            if (_depth++ > MaxDepth)

             {

-                throw InvalidProtocolBufferException.RecursionLimitExceeded();

+                throw new RecursionLimitExceededException();

             }

             ReadGroupArray(fieldName, list, messageType, registry);

-            Depth--;

+            _depth--;

         }

 

         bool ICodedInputStream.ReadPrimitiveField(FieldType fieldType, ref object value)

diff --git a/src/ProtocolBuffers/Serialization/AbstractTextReader.cs b/src/ProtocolBuffers.Serialization/AbstractTextReader.cs
similarity index 94%
rename from src/ProtocolBuffers/Serialization/AbstractTextReader.cs
rename to src/ProtocolBuffers.Serialization/AbstractTextReader.cs
index 83a8dca..59b9057 100644
--- a/src/ProtocolBuffers/Serialization/AbstractTextReader.cs
+++ b/src/ProtocolBuffers.Serialization/AbstractTextReader.cs
@@ -9,6 +9,13 @@
     /// </summary>

     public abstract class AbstractTextReader : AbstractReader

     {

+        /// <summary> Constructs a new reader </summary>

+        protected AbstractTextReader() { }

+        /// <summary> Constructs a new child reader </summary>

+        protected AbstractTextReader(AbstractTextReader copyFrom)

+            : base(copyFrom)

+        { }

+

         /// <summary>

         /// Reads a typed field as a string

         /// </summary>

diff --git a/src/ProtocolBuffers/Serialization/AbstractTextWriter.cs b/src/ProtocolBuffers.Serialization/AbstractTextWriter.cs
similarity index 100%
rename from src/ProtocolBuffers/Serialization/AbstractTextWriter.cs
rename to src/ProtocolBuffers.Serialization/AbstractTextWriter.cs
diff --git a/src/ProtocolBuffers/Serialization/AbstractWriter.cs b/src/ProtocolBuffers.Serialization/AbstractWriter.cs
similarity index 100%
rename from src/ProtocolBuffers/Serialization/AbstractWriter.cs
rename to src/ProtocolBuffers.Serialization/AbstractWriter.cs
diff --git a/src/ProtocolBuffers/Serialization/DictionaryReader.cs b/src/ProtocolBuffers.Serialization/DictionaryReader.cs
similarity index 99%
rename from src/ProtocolBuffers/Serialization/DictionaryReader.cs
rename to src/ProtocolBuffers.Serialization/DictionaryReader.cs
index 7002895..cc5c680 100644
--- a/src/ProtocolBuffers/Serialization/DictionaryReader.cs
+++ b/src/ProtocolBuffers.Serialization/DictionaryReader.cs
@@ -161,7 +161,7 @@
             byte[] rawbytes = null;

             if (GetValue(ref rawbytes))

             {

-                value = ByteString.AttachBytes(rawbytes);

+                value = ByteString.CopyFrom(rawbytes);

                 return true;

             }

             return false;

diff --git a/src/ProtocolBuffers/Serialization/DictionaryWriter.cs b/src/ProtocolBuffers.Serialization/DictionaryWriter.cs
similarity index 100%
rename from src/ProtocolBuffers/Serialization/DictionaryWriter.cs
rename to src/ProtocolBuffers.Serialization/DictionaryWriter.cs
diff --git a/src/ProtocolBuffers.Serialization/Extensions.cs b/src/ProtocolBuffers.Serialization/Extensions.cs
new file mode 100644
index 0000000..2050c91
--- /dev/null
+++ b/src/ProtocolBuffers.Serialization/Extensions.cs
@@ -0,0 +1,100 @@
+using System;

+using System.Text;

+using System.IO;

+using System.Xml;

+using Google.ProtocolBuffers.Serialization;

+

+namespace Google.ProtocolBuffers

+{

+    /// <summary>

+    /// Extension methods for using serializers on instances of IMessageLite/IBuilderLite

+    /// </summary>

+    public static class Extensions

+    {

+        #region IMessageLite Extension

+        /// <summary>

+        /// Serializes the message to JSON text.  This is a trivial wrapper

+        /// around Serialization.JsonFormatWriter.WriteMessage.

+        /// </summary>

+        public static string ToJson(this IMessageLite message)

+        {

+            JsonFormatWriter w = JsonFormatWriter.CreateInstance();

+            w.WriteMessage(message);

+            return w.ToString();

+        }

+        /// <summary>

+        /// Serializes the message to XML text.  This is a trivial wrapper

+        /// around Serialization.XmlFormatWriter.WriteMessage.

+        /// </summary>

+        public static string ToXml(this IMessageLite message)

+        {

+            StringWriter w = new StringWriter(new StringBuilder(4096));

+            XmlFormatWriter.CreateInstance(w).WriteMessage(message);

+            return w.ToString();

+        }

+        /// <summary>

+        /// Serializes the message to XML text using the element name provided.

+        /// This is a trivial wrapper around Serialization.XmlFormatWriter.WriteMessage.

+        /// </summary>

+        public static string ToXml(this IMessageLite message, string rootElementName)

+        {

+            StringWriter w = new StringWriter(new StringBuilder(4096));

+            XmlFormatWriter.CreateInstance(w).WriteMessage(rootElementName, message);

+            return w.ToString();

+        }

+

+        #endregion

+        #region IBuilderLite Extensions

+        /// <summary>

+        /// Merges a JSON object into this builder and returns

+        /// </summary>

+        public static TBuilder MergeFromJson<TBuilder>(this TBuilder builder, string jsonText) where TBuilder : IBuilderLite

+        {

+            return JsonFormatReader.CreateInstance(jsonText)

+                .Merge(builder);

+        }

+        /// <summary>

+        /// Merges a JSON object into this builder and returns

+        /// </summary>

+        public static TBuilder MergeFromJson<TBuilder>(this TBuilder builder, TextReader reader) where TBuilder : IBuilderLite

+        {

+            return MergeFromJson(builder, reader, ExtensionRegistry.Empty);

+        }

+        /// <summary>

+        /// Merges a JSON object into this builder using the extensions provided and returns

+        /// </summary>

+        public static TBuilder MergeFromJson<TBuilder>(this TBuilder builder, TextReader reader, ExtensionRegistry extensionRegistry) where TBuilder : IBuilderLite

+        {

+            return JsonFormatReader.CreateInstance(reader)

+                .Merge(builder, extensionRegistry);

+        }

+

+        /// <summary>

+        /// Merges an XML object into this builder and returns

+        /// </summary>

+        public static TBuilder MergeFromXml<TBuilder>(this TBuilder builder, XmlReader reader) where TBuilder : IBuilderLite

+        {

+            return MergeFromXml(builder, XmlFormatReader.DefaultRootElementName, reader, ExtensionRegistry.Empty);

+        }

+

+        /// <summary>

+        /// Merges an XML object into this builder and returns

+        /// </summary>

+        public static TBuilder MergeFromXml<TBuilder>(this TBuilder builder, string rootElementName, XmlReader reader) where TBuilder : IBuilderLite

+        {

+            return MergeFromXml(builder, rootElementName, reader, ExtensionRegistry.Empty);

+        }

+

+        /// <summary>

+        /// Merges an XML object into this builder using the extensions provided and returns

+        /// </summary>

+        public static TBuilder MergeFromXml<TBuilder>(this TBuilder builder, string rootElementName, XmlReader reader,

+                                            ExtensionRegistry extensionRegistry) where TBuilder : IBuilderLite

+        {

+            return XmlFormatReader.CreateInstance(reader)

+                .Merge(rootElementName, builder, extensionRegistry);

+        }

+

+        #endregion

+    }

+}

diff --git a/src/ProtocolBuffers/Serialization/JsonFormatReader.cs b/src/ProtocolBuffers.Serialization/JsonFormatReader.cs
similarity index 100%
rename from src/ProtocolBuffers/Serialization/JsonFormatReader.cs
rename to src/ProtocolBuffers.Serialization/JsonFormatReader.cs
diff --git a/src/ProtocolBuffers/Serialization/JsonFormatWriter.cs b/src/ProtocolBuffers.Serialization/JsonFormatWriter.cs
similarity index 100%
rename from src/ProtocolBuffers/Serialization/JsonFormatWriter.cs
rename to src/ProtocolBuffers.Serialization/JsonFormatWriter.cs
diff --git a/src/ProtocolBuffers/Serialization/JsonTextCursor.cs b/src/ProtocolBuffers.Serialization/JsonTextCursor.cs
similarity index 100%
rename from src/ProtocolBuffers/Serialization/JsonTextCursor.cs
rename to src/ProtocolBuffers.Serialization/JsonTextCursor.cs
diff --git a/src/ProtocolBuffers.Serialization/Properties/AssemblyInfo.cs b/src/ProtocolBuffers.Serialization/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..fdae52b
--- /dev/null
+++ b/src/ProtocolBuffers.Serialization/Properties/AssemblyInfo.cs
@@ -0,0 +1,76 @@
+// Protocol Buffers - Google's data interchange format

+// Copyright 2008 Google Inc.  All rights reserved.

+// http://github.com/jskeet/dotnet-protobufs/

+// Original C++/Java/Python code:

+// http://code.google.com/p/protobuf/

+//

+// Redistribution and use in source and binary forms, with or without

+// modification, are permitted provided that the following conditions are

+// met:

+//

+//     * Redistributions of source code must retain the above copyright

+// notice, this list of conditions and the following disclaimer.

+//     * Redistributions in binary form must reproduce the above

+// copyright notice, this list of conditions and the following disclaimer

+// in the documentation and/or other materials provided with the

+// distribution.

+//     * Neither the name of Google Inc. nor the names of its

+// contributors may be used to endorse or promote products derived from

+// this software without specific prior written permission.

+//

+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS

+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT

+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR

+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT

+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,

+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT

+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,

+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY

+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT

+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE

+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

+using System;

+using System.Reflection;

+using System.Runtime.InteropServices;

+using System.Runtime.CompilerServices;

+

+// General Information about an assembly is controlled through the following 

+// set of attributes. Change these attribute values to modify the information

+// associated with an assembly.

+

+[assembly: AssemblyTitle("ProtocolBuffers")]

+[assembly: AssemblyDescription("")]

+[assembly: AssemblyConfiguration("")]

+[assembly: AssemblyCompany("")]

+[assembly: AssemblyProduct("ProtocolBuffers")]

+[assembly: AssemblyCopyright("Copyright ©  2008")]

+[assembly: AssemblyTrademark("")]

+[assembly: AssemblyCulture("")]

+// Setting ComVisible to false makes the types in this assembly not visible 

+// to COM components.  If you need to access a type in this assembly from 

+// COM, set the ComVisible attribute to true on that type.

+

+[assembly: ComVisible(false)]

+

+// The following GUID is for the ID of the typelib if this project is exposed to COM

+

+[assembly: Guid("279b643d-70e8-47ae-9eb1-500d1c48bab6")]

+

+// Version information for an assembly consists of the following four values:

+//

+//      Major Version

+//      Minor Version 

+//      Build Number

+//      Revision

+//

+// You can specify all the values or you can default the Build and Revision Numbers 

+// by using the '*' as shown below:

+// [assembly: AssemblyVersion("2.3.0.277")]

+

+[assembly: AssemblyVersion("2.3.0.277")]

+#if !COMPACT_FRAMEWORK_35

+

+[assembly: AssemblyFileVersion("2.3.0.277")]

+#endif

+

+[assembly: CLSCompliant(true)]
\ No newline at end of file
diff --git a/src/ProtocolBuffers.Serialization/ProtocolBuffers.Serialization.csproj b/src/ProtocolBuffers.Serialization/ProtocolBuffers.Serialization.csproj
new file mode 100644
index 0000000..0c53577
--- /dev/null
+++ b/src/ProtocolBuffers.Serialization/ProtocolBuffers.Serialization.csproj
@@ -0,0 +1,152 @@
+<?xml version="1.0" encoding="utf-8"?>

+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

+  <PropertyGroup>

+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>

+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>

+    <ProductVersion>9.0.30729</ProductVersion>

+    <SchemaVersion>2.0</SchemaVersion>

+    <ProjectGuid>{231391AF-449C-4A39-986C-AD7F270F4750}</ProjectGuid>

+    <OutputType>Library</OutputType>

+    <AppDesignerFolder>Properties</AppDesignerFolder>

+    <RootNamespace>Google.ProtocolBuffers.Serialization</RootNamespace>

+    <AssemblyName>Google.ProtocolBuffers.Serialization</AssemblyName>

+    <TargetFrameworkVersion>v2.0</TargetFrameworkVersion>

+    <FileAlignment>512</FileAlignment>

+    <SignAssembly>true</SignAssembly>

+    <AssemblyOriginatorKeyFile>..\..\keys\Google.ProtocolBuffers.snk</AssemblyOriginatorKeyFile>

+    <FileUpgradeFlags>

+    </FileUpgradeFlags>

+    <UpgradeBackupLocation>

+    </UpgradeBackupLocation>

+    <OldToolsVersion>3.5</OldToolsVersion>

+    <PublishUrl>publish\</PublishUrl>

+    <Install>true</Install>

+    <InstallFrom>Disk</InstallFrom>

+    <UpdateEnabled>false</UpdateEnabled>

+    <UpdateMode>Foreground</UpdateMode>

+    <UpdateInterval>7</UpdateInterval>

+    <UpdateIntervalUnits>Days</UpdateIntervalUnits>

+    <UpdatePeriodically>false</UpdatePeriodically>

+    <UpdateRequired>false</UpdateRequired>

+    <MapFileExtensions>true</MapFileExtensions>

+    <ApplicationRevision>0</ApplicationRevision>

+    <ApplicationVersion>1.0.0.%2a</ApplicationVersion>

+    <IsWebBootstrapper>false</IsWebBootstrapper>

+    <UseApplicationTrust>false</UseApplicationTrust>

+    <BootstrapperEnabled>true</BootstrapperEnabled>

+  </PropertyGroup>

+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">

+    <DebugSymbols>true</DebugSymbols>

+    <DebugType>full</DebugType>

+    <Optimize>false</Optimize>

+    <OutputPath>bin\Debug\</OutputPath>

+    <DocumentationFile>$(OutputPath)\$(AssemblyName).xml</DocumentationFile>

+    <NoWarn>1591, 1570, 1571, 1572, 1573, 1574</NoWarn>

+    <DefineConstants>DEBUG;TRACE</DefineConstants>

+    <ErrorReport>prompt</ErrorReport>

+    <WarningLevel>4</WarningLevel>

+    <NoStdLib>true</NoStdLib>

+    <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>

+  </PropertyGroup>

+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">

+    <DebugType>pdbonly</DebugType>

+    <Optimize>true</Optimize>

+    <OutputPath>bin\Release\</OutputPath>

+    <DocumentationFile>$(OutputPath)\$(AssemblyName).xml</DocumentationFile>

+    <NoWarn>1591, 1570, 1571, 1572, 1573, 1574</NoWarn>

+    <DefineConstants>TRACE</DefineConstants>

+    <ErrorReport>prompt</ErrorReport>

+    <WarningLevel>4</WarningLevel>

+    <NoStdLib>true</NoStdLib>

+    <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>

+  </PropertyGroup>

+  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug_Silverlight2|AnyCPU'">

+    <DebugSymbols>true</DebugSymbols>

+    <DebugType>full</DebugType>

+    <Optimize>false</Optimize>

+    <OutputPath>bin\Debug_Silverlight2\</OutputPath>

+    <DocumentationFile>$(OutputPath)\$(AssemblyName).xml</DocumentationFile>

+    <NoWarn>1591, 1570, 1571, 1572, 1573, 1574</NoWarn>

+    <DefineConstants>DEBUG;TRACE;SILVERLIGHT2</DefineConstants>

+    <ErrorReport>prompt</ErrorReport>

+    <WarningLevel>4</WarningLevel>

+    <NoStdLib>true</NoStdLib>

+    <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>

+  </PropertyGroup>

+  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release_Silverlight2|AnyCPU'">

+    <DebugType>pdbonly</DebugType>

+    <Optimize>true</Optimize>

+    <OutputPath>bin\Release_Silverlight2\</OutputPath>

+    <DocumentationFile>$(OutputPath)\$(AssemblyName).xml</DocumentationFile>

+    <NoWarn>1591, 1570, 1571, 1572, 1573, 1574</NoWarn>

+    <DefineConstants>TRACE;SILVERLIGHT2</DefineConstants>

+    <ErrorReport>prompt</ErrorReport>

+    <WarningLevel>4</WarningLevel>

+    <NoStdLib>true</NoStdLib>

+    <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>

+  </PropertyGroup>

+  <ItemGroup>

+    <Reference Include="mscorlib" />

+    <Reference Include="System" />

+    <Reference Include="System.Xml" />

+    <!-- Only for 2.x compatibility of extension methods -->

+    <Reference Include="System.Core">

+      <SpecificVersion>False</SpecificVersion>

+      <HintPath>..\..\lib\System.Core\System.Core.dll</HintPath>

+      <Private>False</Private>

+    </Reference>

+  </ItemGroup>

+  <ItemGroup>

+    <Compile Include="Extensions.cs" />

+    <Compile Include="Properties\AssemblyInfo.cs" />

+    <Compile Include="AbstractReader.cs" />

+    <Compile Include="AbstractTextReader.cs" />

+    <Compile Include="AbstractTextWriter.cs" />

+    <Compile Include="AbstractWriter.cs" />

+    <Compile Include="DictionaryReader.cs" />

+    <Compile Include="DictionaryWriter.cs" />

+    <Compile Include="JsonFormatReader.cs" />

+    <Compile Include="JsonFormatWriter.cs" />

+    <Compile Include="JsonTextCursor.cs" />

+    <Compile Include="RecursionLimitExceeded.cs" />

+    <Compile Include="XmlFormatReader.cs" />

+    <Compile Include="XmlFormatWriter.cs" />

+    <Compile Include="XmlReaderOptions.cs" />

+    <Compile Include="XmlWriterOptions.cs" />

+  </ItemGroup>

+  <ItemGroup>

+    <BootstrapperPackage Include="Microsoft.Net.Client.3.5">

+      <Visible>False</Visible>

+      <ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>

+      <Install>false</Install>

+    </BootstrapperPackage>

+    <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">

+      <Visible>False</Visible>

+      <ProductName>.NET Framework 3.5 SP1</ProductName>

+      <Install>true</Install>

+    </BootstrapperPackage>

+    <BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">

+      <Visible>False</Visible>

+      <ProductName>Windows Installer 3.1</ProductName>

+      <Install>true</Install>

+    </BootstrapperPackage>

+  </ItemGroup>

+  <ItemGroup>

+    <ProjectReference Include="..\ProtocolBuffers\ProtocolBuffers.csproj">

+      <Project>{6908BDCE-D925-43F3-94AC-A531E6DF2591}</Project>

+      <Name>ProtocolBuffers</Name>

+      <Private>False</Private>

+    </ProjectReference>

+  </ItemGroup>

+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" Condition=" '$(Configuration)' == 'Debug' " />

+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" Condition=" '$(Configuration)' == 'Release' " />

+  <Import Project="$(MSBuildExtensionsPath)\Microsoft\Silverlight\v2.0\Microsoft.Silverlight.CSharp.targets" Condition=" '$(Configuration)' == 'Debug_Silverlight2' " />

+  <Import Project="$(MSBuildExtensionsPath)\Microsoft\Silverlight\v2.0\Microsoft.Silverlight.CSharp.targets" Condition=" '$(Configuration)' == 'Release_Silverlight2' " />

+  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 

+       Other similar extension points exist, see Microsoft.Common.targets.

+  <Target Name="BeforeBuild">

+  </Target>

+  <Target Name="AfterBuild">

+  </Target>

+  -->

+</Project>
\ No newline at end of file
diff --git a/src/ProtocolBuffers.Serialization/RecursionLimitExceeded.cs b/src/ProtocolBuffers.Serialization/RecursionLimitExceeded.cs
new file mode 100644
index 0000000..cdecb52
--- /dev/null
+++ b/src/ProtocolBuffers.Serialization/RecursionLimitExceeded.cs
@@ -0,0 +1,28 @@
+using System;

+using System.Collections.Generic;

+using System.Text;

+

+namespace Google.ProtocolBuffers.Serialization

+{

+    /// <summary>

+    /// The exception raised when a recursion limit is reached while parsing input.

+    /// </summary>

+#if !SILVERLIGHT2

+    [Serializable]

+#endif

+    public sealed class RecursionLimitExceededException : FormatException

+    {

+        const string message = "Possible malicious message had too many levels of nesting.";

+        

+        internal RecursionLimitExceededException() : base(message)

+        {

+        }

+

+#if !SILVERLIGHT2

+        private RecursionLimitExceededException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)

+            : base(info, context)

+        {

+        }

+#endif

+    }

+}

diff --git a/src/ProtocolBuffers/Serialization/XmlFormatReader.cs b/src/ProtocolBuffers.Serialization/XmlFormatReader.cs
similarity index 95%
rename from src/ProtocolBuffers/Serialization/XmlFormatReader.cs
rename to src/ProtocolBuffers.Serialization/XmlFormatReader.cs
index 112910a..cb2cb2e 100644
--- a/src/ProtocolBuffers/Serialization/XmlFormatReader.cs
+++ b/src/ProtocolBuffers.Serialization/XmlFormatReader.cs
@@ -76,6 +76,17 @@
         }

 

         /// <summary>

+        /// Constructs the XmlFormatReader with the XmlReader and options

+        /// </summary>

+        protected XmlFormatReader(XmlFormatReader copyFrom, XmlReader input)

+            : base(copyFrom)

+        {

+            _input = input;

+            _rootElementName = copyFrom._rootElementName;

+            Options = copyFrom.Options;

+        }

+

+        /// <summary>

         /// Gets or sets the options to use when reading the xml

         /// </summary>

         public XmlReaderOptions Options { get; set; }

@@ -104,9 +115,7 @@
 

         private XmlFormatReader CloneWith(XmlReader rdr)

         {

-            XmlFormatReader copy = new XmlFormatReader(rdr).SetOptions(Options);

-            copy._rootElementName = _rootElementName;

-            copy.Depth = Depth;

+            XmlFormatReader copy = new XmlFormatReader(this, rdr);

             return copy;

         }

 

diff --git a/src/ProtocolBuffers/Serialization/XmlFormatWriter.cs b/src/ProtocolBuffers.Serialization/XmlFormatWriter.cs
similarity index 100%
rename from src/ProtocolBuffers/Serialization/XmlFormatWriter.cs
rename to src/ProtocolBuffers.Serialization/XmlFormatWriter.cs
diff --git a/src/ProtocolBuffers/Serialization/XmlReaderOptions.cs b/src/ProtocolBuffers.Serialization/XmlReaderOptions.cs
similarity index 100%
rename from src/ProtocolBuffers/Serialization/XmlReaderOptions.cs
rename to src/ProtocolBuffers.Serialization/XmlReaderOptions.cs
diff --git a/src/ProtocolBuffers/Serialization/XmlWriterOptions.cs b/src/ProtocolBuffers.Serialization/XmlWriterOptions.cs
similarity index 100%
rename from src/ProtocolBuffers/Serialization/XmlWriterOptions.cs
rename to src/ProtocolBuffers.Serialization/XmlWriterOptions.cs
diff --git a/src/ProtocolBuffers.Test/ProtocolBuffers.Test.csproj b/src/ProtocolBuffers.Test/ProtocolBuffers.Test.csproj
index 5e31987..bf22426 100644
--- a/src/ProtocolBuffers.Test/ProtocolBuffers.Test.csproj
+++ b/src/ProtocolBuffers.Test/ProtocolBuffers.Test.csproj
@@ -124,6 +124,10 @@
     <Compile Include="WireFormatTest.cs" />

   </ItemGroup>

   <ItemGroup>

+    <ProjectReference Include="..\ProtocolBuffers.Serialization\ProtocolBuffers.Serialization.csproj">

+      <Project>{231391AF-449C-4a39-986C-AD7F270F4750}</Project>

+      <Name>ProtocolBuffers.Serialization</Name>

+    </ProjectReference>

     <ProjectReference Include="..\ProtocolBuffers\ProtocolBuffers.csproj">

       <Project>{6908BDCE-D925-43F3-94AC-A531E6DF2591}</Project>

       <Name>ProtocolBuffers</Name>

diff --git a/src/ProtocolBuffers.Test/TestWriterFormatJson.cs b/src/ProtocolBuffers.Test/TestWriterFormatJson.cs
index fe6c22b..3f534fc 100644
--- a/src/ProtocolBuffers.Test/TestWriterFormatJson.cs
+++ b/src/ProtocolBuffers.Test/TestWriterFormatJson.cs
@@ -38,7 +38,7 @@
             TestAllTypes msg = new TestAllTypes.Builder().SetDefaultBool(true).Build();

             string json = msg.ToJson();

             Assert.AreEqual("{\"default_bool\":true}", json);

-            TestAllTypes copy = TestAllTypes.ParseFromJson(json);

+            TestAllTypes copy = new TestAllTypes.Builder().MergeFromJson(json).Build();

             Assert.IsTrue(copy.HasDefaultBool && copy.DefaultBool);

             Assert.AreEqual(msg, copy);

         }

@@ -49,7 +49,7 @@
             TestAllTypes msg = new TestAllTypes.Builder().SetDefaultBool(true).Build();

             string json = msg.ToJson();

             Assert.AreEqual("{\"default_bool\":true}", json);

-            TestAllTypes copy = TestAllTypes.ParseFromJson(new StringReader(json));

+            TestAllTypes copy = new TestAllTypes.Builder().MergeFromJson(new StringReader(json)).Build();

             Assert.IsTrue(copy.HasDefaultBool && copy.DefaultBool);

             Assert.AreEqual(msg, copy);

         }

@@ -337,13 +337,13 @@
             Assert.AreEqual(3, ordinal);

             Assert.AreEqual(3, builder.TextlinesCount);

         }

-        [Test,ExpectedException(typeof(InvalidProtocolBufferException))]

+        [Test,ExpectedException(typeof(RecursionLimitExceededException))]

         public void TestRecursiveLimit()

         {

             StringBuilder sb = new StringBuilder(8192);

             for (int i = 0; i < 80; i++)

                 sb.Append("{\"child\":");

-            TestXmlRescursive msg = TestXmlRescursive.ParseFromJson(sb.ToString());

+            TestXmlRescursive msg = new TestXmlRescursive.Builder().MergeFromJson(sb.ToString()).Build();

         }

         [Test, ExpectedException(typeof(FormatException))]

         public void FailWithEmptyText()

diff --git a/src/ProtocolBuffers.Test/TestWriterFormatXml.cs b/src/ProtocolBuffers.Test/TestWriterFormatXml.cs
index acad6f1..2ffca9f 100644
--- a/src/ProtocolBuffers.Test/TestWriterFormatXml.cs
+++ b/src/ProtocolBuffers.Test/TestWriterFormatXml.cs
@@ -18,7 +18,7 @@
             TestAllTypes msg = new TestAllTypes.Builder().SetDefaultBool(true).Build();

             string xml = msg.ToXml();

             Assert.AreEqual("<root><default_bool>true</default_bool></root>", xml);

-            TestAllTypes copy = TestAllTypes.ParseFromXml(XmlReader.Create(new StringReader(xml)));

+            TestAllTypes copy = new TestAllTypes.Builder().MergeFromXml(XmlReader.Create(new StringReader(xml))).Build();

             Assert.IsTrue(copy.HasDefaultBool && copy.DefaultBool);

             Assert.AreEqual(msg, copy);

         }

@@ -29,7 +29,7 @@
             TestAllTypes msg = new TestAllTypes.Builder().SetDefaultBool(true).Build();

             string xml = msg.ToXml("message");

             Assert.AreEqual("<message><default_bool>true</default_bool></message>", xml);

-            TestAllTypes copy = TestAllTypes.ParseFromXml("message", XmlReader.Create(new StringReader(xml)));

+            TestAllTypes copy = new TestAllTypes.Builder().MergeFromXml("message", XmlReader.Create(new StringReader(xml))).Build();

             Assert.IsTrue(copy.HasDefaultBool && copy.DefaultBool);

             Assert.AreEqual(msg, copy);

         }

@@ -324,13 +324,13 @@
             TestXmlMessage copy = rdr.Merge(TestXmlMessage.CreateBuilder(), registry).Build();

             Assert.AreEqual(message, copy);

         }

-        [Test, ExpectedException(typeof(InvalidProtocolBufferException))]

+        [Test, ExpectedException(typeof(RecursionLimitExceededException))]

         public void TestRecursiveLimit()

         {

             StringBuilder sb = new StringBuilder(8192);

             for (int i = 0; i < 80; i++)

                 sb.Append("<child>");

-            TestXmlRescursive msg = TestXmlRescursive.ParseFromXml("child", XmlReader.Create(new StringReader(sb.ToString())));

+            TestXmlRescursive msg = new TestXmlRescursive.Builder().MergeFromXml("child", XmlReader.Create(new StringReader(sb.ToString()))).Build();

         }

     }

 }

diff --git a/src/ProtocolBuffers.sln b/src/ProtocolBuffers.sln
index a7323db..04e1c9c 100644
--- a/src/ProtocolBuffers.sln
+++ b/src/ProtocolBuffers.sln
@@ -1,5 +1,4 @@
-

-Microsoft Visual Studio Solution File, Format Version 11.00

+Microsoft Visual Studio Solution File, Format Version 11.00

 # Visual Studio 2010

 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "proto", "proto", "{1F896D5C-5FC2-4671-9216-781CB8187EC7}"

 	ProjectSection(SolutionItems) = preProject

@@ -67,6 +66,8 @@
 		..\build\RunBenchmarks.bat = ..\build\RunBenchmarks.bat

 	EndProjectSection

 EndProject

+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProtocolBuffers.Serialization", "ProtocolBuffers.Serialization\ProtocolBuffers.Serialization.csproj", "{231391AF-449C-4a39-986C-AD7F270F4750}"

+EndProject

 Global

 	GlobalSection(SolutionConfigurationPlatforms) = preSolution

 		Debug_Silverlight2|Any CPU = Debug_Silverlight2|Any CPU

@@ -145,6 +146,14 @@
 		{EEFFED24-3750-4567-9A23-1DB676A15610}.Release_Silverlight2|Any CPU.ActiveCfg = Release|Any CPU

 		{EEFFED24-3750-4567-9A23-1DB676A15610}.Release|Any CPU.ActiveCfg = Release|Any CPU

 		{EEFFED24-3750-4567-9A23-1DB676A15610}.Release|Any CPU.Build.0 = Release|Any CPU

+		{231391AF-449C-4a39-986C-AD7F270F4750}.Debug_Silverlight2|Any CPU.ActiveCfg = Debug_Silverlight2|Any CPU

+		{231391AF-449C-4a39-986C-AD7F270F4750}.Debug_Silverlight2|Any CPU.Build.0 = Debug_Silverlight2|Any CPU

+		{231391AF-449C-4a39-986C-AD7F270F4750}.Debug|Any CPU.ActiveCfg = Debug|Any CPU

+		{231391AF-449C-4a39-986C-AD7F270F4750}.Debug|Any CPU.Build.0 = Debug|Any CPU

+		{231391AF-449C-4a39-986C-AD7F270F4750}.Release_Silverlight2|Any CPU.ActiveCfg = Release_Silverlight2|Any CPU

+		{231391AF-449C-4a39-986C-AD7F270F4750}.Release_Silverlight2|Any CPU.Build.0 = Release_Silverlight2|Any CPU

+		{231391AF-449C-4a39-986C-AD7F270F4750}.Release|Any CPU.ActiveCfg = Release|Any CPU

+		{231391AF-449C-4a39-986C-AD7F270F4750}.Release|Any CPU.Build.0 = Release|Any CPU

 	EndGlobalSection

 	GlobalSection(SolutionProperties) = preSolution

 		HideSolutionNode = FALSE

diff --git a/src/ProtocolBuffers/AbstractMessage.cs b/src/ProtocolBuffers/AbstractMessage.cs
index 0c898c7..13443b1 100644
--- a/src/ProtocolBuffers/AbstractMessage.cs
+++ b/src/ProtocolBuffers/AbstractMessage.cs
@@ -40,7 +40,6 @@
 using System.Text;

 using Google.ProtocolBuffers.Collections;

 using Google.ProtocolBuffers.Descriptors;

-using Google.ProtocolBuffers.Serialization;

 

 namespace Google.ProtocolBuffers

 {

@@ -123,27 +122,6 @@
             return TextFormat.PrintToString(this);

         }

 

-        public string ToJson()

-        {

-            JsonFormatWriter w = JsonFormatWriter.CreateInstance();

-            w.WriteMessage(this);

-            return w.ToString();

-        }

-

-        public string ToXml()

-        {

-            StringWriter w = new StringWriter(new StringBuilder(4096));

-            XmlFormatWriter.CreateInstance(w).WriteMessage(this);

-            return w.ToString();

-        }

-

-        public string ToXml(string rootElementName)

-        {

-            StringWriter w = new StringWriter(new StringBuilder(4096));

-            XmlFormatWriter.CreateInstance(w).WriteMessage(rootElementName, this);

-            return w.ToString();

-        }

-

         public override sealed void PrintTo(TextWriter writer)

         {

             TextFormat.Print(this, writer);

diff --git a/src/ProtocolBuffers/GeneratedMessage.cs b/src/ProtocolBuffers/GeneratedMessage.cs
index 8147a88..ce755be 100644
--- a/src/ProtocolBuffers/GeneratedMessage.cs
+++ b/src/ProtocolBuffers/GeneratedMessage.cs
@@ -42,7 +42,6 @@
 using Google.ProtocolBuffers.Collections;

 using Google.ProtocolBuffers.Descriptors;

 using Google.ProtocolBuffers.FieldAccess;

-using Google.ProtocolBuffers.Serialization;

 

 namespace Google.ProtocolBuffers

 {

@@ -178,42 +177,5 @@
         {

             unknownFields = fieldSet;

         }

-

-        public static TMessage ParseFromJson(string jsonText)

-        {

-            return JsonFormatReader.CreateInstance(jsonText)

-                .Merge(new TBuilder())

-                .Build();

-        }

-

-        public static TMessage ParseFromJson(TextReader reader)

-        {

-            return ParseFromJson(reader, ExtensionRegistry.Empty);

-        }

-

-        public static TMessage ParseFromJson(TextReader reader, ExtensionRegistry extensionRegistry)

-        {

-            return JsonFormatReader.CreateInstance(reader)

-                .Merge(new TBuilder(), extensionRegistry)

-                .Build();

-        }

-

-        public static TMessage ParseFromXml(XmlReader reader)

-        {

-            return ParseFromXml(XmlFormatReader.DefaultRootElementName, reader, ExtensionRegistry.Empty);

-        }

-

-        public static TMessage ParseFromXml(string rootElementName, XmlReader reader)

-        {

-            return ParseFromXml(rootElementName, reader, ExtensionRegistry.Empty);

-        }

-

-        public static TMessage ParseFromXml(string rootElementName, XmlReader reader,

-                                            ExtensionRegistry extensionRegistry)

-        {

-            return XmlFormatReader.CreateInstance(reader)

-                .Merge(rootElementName, new TBuilder(), extensionRegistry)

-                .Build();

-        }

     }

 }
\ No newline at end of file
diff --git a/src/ProtocolBuffers/IMessage.cs b/src/ProtocolBuffers/IMessage.cs
index 514c4bf..c23bc3f 100644
--- a/src/ProtocolBuffers/IMessage.cs
+++ b/src/ProtocolBuffers/IMessage.cs
@@ -185,24 +185,6 @@
         new byte[] ToByteArray();

 

         /// <summary>

-        /// Serializes the message to JSON text.  This is a trivial wrapper 

-        /// around Serialization.JsonFormatWriter.WriteMessage.

-        /// </summary>

-        string ToJson();

-

-        /// <summary>

-        /// Serializes the message to XML text.  This is a trivial wrapper 

-        /// around Serialization.XmlFormatWriter.WriteMessage.

-        /// </summary>

-        string ToXml();

-

-        /// <summary>

-        /// Serializes the message to XML text using the element name provided.

-        /// This is a trivial wrapper around Serialization.XmlFormatWriter.WriteMessage.

-        /// </summary>

-        string ToXml(string rootElementName);

-

-        /// <summary>

         /// Serializes the message and writes it to the given stream.

         /// This is just a wrapper around WriteTo(ICodedOutputStream). This

         /// does not flush or close the stream.

diff --git a/src/ProtocolBuffers/ProtocolBuffers.csproj b/src/ProtocolBuffers/ProtocolBuffers.csproj
index d278d8a..336b387 100644
--- a/src/ProtocolBuffers/ProtocolBuffers.csproj
+++ b/src/ProtocolBuffers/ProtocolBuffers.csproj
@@ -88,7 +88,6 @@
   <ItemGroup>

     <Reference Include="mscorlib" />

     <Reference Include="System" />

-    <Reference Include="System.Data" />

     <Reference Include="System.Xml" />

   </ItemGroup>

   <ItemGroup>

@@ -181,19 +180,6 @@
     <Compile Include="NameHelpers.cs" />

     <Compile Include="Properties\AssemblyInfo.cs" />

     <Compile Include="RpcUtil.cs" />

-    <Compile Include="Serialization\AbstractReader.cs" />

-    <Compile Include="Serialization\AbstractTextReader.cs" />

-    <Compile Include="Serialization\AbstractTextWriter.cs" />

-    <Compile Include="Serialization\AbstractWriter.cs" />

-    <Compile Include="Serialization\DictionaryReader.cs" />

-    <Compile Include="Serialization\DictionaryWriter.cs" />

-    <Compile Include="Serialization\JsonFormatReader.cs" />

-    <Compile Include="Serialization\JsonFormatWriter.cs" />

-    <Compile Include="Serialization\JsonTextCursor.cs" />

-    <Compile Include="Serialization\XmlFormatReader.cs" />

-    <Compile Include="Serialization\XmlFormatWriter.cs" />

-    <Compile Include="Serialization\XmlReaderOptions.cs" />

-    <Compile Include="Serialization\XmlWriterOptions.cs" />

     <Compile Include="SilverlightCompatibility.cs" />

     <Compile Include="SortedList.cs" />

     <Compile Include="TextFormat.cs" />

diff --git a/src/ProtocolBuffers2008.sln b/src/ProtocolBuffers2008.sln
index 8172c7b..fc0bf81 100644
--- a/src/ProtocolBuffers2008.sln
+++ b/src/ProtocolBuffers2008.sln
@@ -67,6 +67,8 @@
 		..\build\RunBenchmarks.bat = ..\build\RunBenchmarks.bat

 	EndProjectSection

 EndProject

+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProtocolBuffers.Serialization", "ProtocolBuffers.Serialization\ProtocolBuffers.Serialization.csproj", "{231391AF-449C-4a39-986C-AD7F270F4750}"

+EndProject

 Global

 	GlobalSection(SolutionConfigurationPlatforms) = preSolution

 		Debug_Silverlight2|Any CPU = Debug_Silverlight2|Any CPU

@@ -145,6 +147,14 @@
 		{EEFFED24-3750-4567-9A23-1DB676A15610}.Release_Silverlight2|Any CPU.ActiveCfg = Release|Any CPU

 		{EEFFED24-3750-4567-9A23-1DB676A15610}.Release|Any CPU.ActiveCfg = Release|Any CPU

 		{EEFFED24-3750-4567-9A23-1DB676A15610}.Release|Any CPU.Build.0 = Release|Any CPU

+		{231391AF-449C-4a39-986C-AD7F270F4750}.Debug_Silverlight2|Any CPU.ActiveCfg = Debug_Silverlight2|Any CPU

+		{231391AF-449C-4a39-986C-AD7F270F4750}.Debug_Silverlight2|Any CPU.Build.0 = Debug_Silverlight2|Any CPU

+		{231391AF-449C-4a39-986C-AD7F270F4750}.Debug|Any CPU.ActiveCfg = Debug|Any CPU

+		{231391AF-449C-4a39-986C-AD7F270F4750}.Debug|Any CPU.Build.0 = Debug|Any CPU

+		{231391AF-449C-4a39-986C-AD7F270F4750}.Release_Silverlight2|Any CPU.ActiveCfg = Release_Silverlight2|Any CPU

+		{231391AF-449C-4a39-986C-AD7F270F4750}.Release_Silverlight2|Any CPU.Build.0 = Release_Silverlight2|Any CPU

+		{231391AF-449C-4a39-986C-AD7F270F4750}.Release|Any CPU.ActiveCfg = Release|Any CPU

+		{231391AF-449C-4a39-986C-AD7F270F4750}.Release|Any CPU.Build.0 = Release|Any CPU

 	EndGlobalSection

 	GlobalSection(SolutionProperties) = preSolution

 		HideSolutionNode = FALSE