Knowledge Base

Error related to deserializing object graph

Problem:

The following error occurs in one of the WCF services used by CodeTwo software:

The InnerException message was 'Maximum number of items that can be serialized or deserialized in an object graph is '65536'. 

This problem is related to the default WCF service limits that your CodeTwo program has reached. This may happen in some scenarios, especially when you are trying to:

  • Import rules configuration file of a very large size in CodeTwo Exchange Rules and CodeTwo Exchange Rules Pro
    Error: The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:DownloadRulesResult. The InnerException message was 'Maximum number of items that can be serialized or deserialized in an object graph is '65536'. Change the object graph or increase the MaxItemsInObjectGraph quota. '.  Please see InnerException for more details. Failed to download latest rules settings version. module: CommonLanguageRuntimeLibrary
  • Migrate very large files in CodeTwo Exchange Migration or CodeTwo Office 365 Migration
    There was an error reading from the pipe: The pipe has been ended. (109, 0x6d).
    

Solution:

CodeTwo migration software

If you are still experiencing this problem while using your CodeTwo backup and migration software, it means you are using an older version of the program. Make sure to upgrade your software to its latest version first. Use one of the links below to download the new installation file for:

If the problem persists, apply the solution described in this article.

Every WCF service comes with its own bindings, behaviors and other preferences, and applying appropriate changes requires technical knowledge of every single WCF service. However, instead of modifying dozens of .configuration files, you can change .NET Framework configuration globally for your system. This solution should permanently solve your problem for all CodeTwo and third-party applications using WCF services. To do so, follow all steps provided below.

Applying the outlined changes requires basic knowledge of XML. It is strongly recommended to create a backup copy of every file that you are about to modify. Also, we strongly advise to use a third-party XML editor which allows you to selectively expand/collapse the nodes or elements. Be aware that saving corrupted configuration files will result in your .NET applications failure.

  1. Open the following directory on every machine where you are experiencing this problem.
    %windir%\Microsoft.NET\
    
  2. Within this directory, you should see folders: Framework and Framework64 (in 64-bit environments). Both of those contain a few folders with names of particular .NET versions (e.g. v2.0.50727). You need to browse through every folder and see if it contains CONFIG directory and inside a file named machine.config. Open each machine.config file for editing.
  3. Under the system.serviceModel node add the following subnode:
    <commonBehaviors>
          <endpointBehaviors>
            <dataContractSerializer maxItemsInObjectGraph="2147483647" />
          </endpointBehaviors>
          <serviceBehaviors>
             <dataContractSerializer maxItemsInObjectGraph="2147483647" />
          </serviceBehaviors>
    </commonBehaviors> 
    
  4. After applying the changes, your machine.config file should looks as below:
    <system.serviceMode>
       (...)
        <extensions>
          (...)
        </extensions>
        <tracking>
          (...)
        </tracking>
        <commonBehaviors>
          <endpointBehaviors>
            <dataContractSerializer maxItemsInObjectGraph="2147483647" />
          </endpointBehaviors>
          <serviceBehaviors>
             <dataContractSerializer maxItemsInObjectGraph="2147483647" />
          </serviceBehaviors>
        </commonBehaviors> 
        (...)
    </system.serviceModel>
    

    Important

    If the system.serviceModel node is missing in the configuration file, you need to create this node manually.

  5. Repeat steps 3 and 4 for every machine.config file.
  6. Perform a full reboot of each machine.