Clara's Notes on Technology
Notes to me and the world

The maximum nametable character count quota (16384) has been exceeded

Monday, August 20, 2007 6:36 PM

It has been a while since I last posted, but I haven't stopped working :) I am currently on a project involving WPF and WCF. While I am not a big fan of WPF, but I quite like WCF.

During the development of our project we run into a very annoying problem with WCF. After some help from Microsoft, we found a solution at last.

The problem is very easy to describe. On the one side, we have a WCF service running. On the other side, we have a client with a reference with to this service. Now and then, we need to update the service reference (because the service includes new features, for example). You can do this with svcutil or by right clicking on the reference in VisualStudio and choosing the "Update Service Reference" option.

One day, when updating the reference (with svcutil) we got this message:

Error: Cannot obtain Metadata from http://localhost:8000/businessservice/service/mex

The maximum nametable character count quota (16384) has been exceeded whilereading XML data. The nametable is a data structure used to store strings encountered during XML processing - long XML documents with non-repeating element names, attribute names and attribute values may trigger this quota. This quota may be increased by changing the MaxNameTableCharCount property on the XmlDictionaryReaderQuotas object used when creating the XML reader.

After several Google searches, I thought this could be solved by increasing the reader quotas parameters for the metadata exchange binding. This implied some minor changes in the service config file since the the mexBinding configuration section does not provide any properties: you have to use a wsHttpBinding without any security. This is explained here and Michele Leroux Bustamante (an expert on WCF) even provides a couple of samples (config-based sample here, and code-based sample here).

However, this did not help at all. Even setting the reader quotas to the maximum possible values made no difference at all. In the end, Microsoft told me what was wrong: the message refers to the svcutil reader quotas not the service ones! Svcutil has a limit on how much metadata it can read. This limit can be changed with a config file.

The solution is to create a config file for svcutil (see below) and place it in the same folder as the tool. Next time you run svcutil, the config file values will be taken into account.

 

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.serviceModel>
        <bindings>
            <customBinding>
                <binding name="MyBinding">
                    <textMessageEncoding>
                        <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
                            maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
                    </textMessageEncoding>
                    <httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
                </binding>
            </customBinding>
        </bindings>
        <client>
            <endpoint binding="customBinding" bindingConfiguration="MyBinding"
                contract="IMetadataExchange"
                name="http" />
        </client>
    </system.serviceModel>
</configuration>

 

The MSDN WCF samples contain an example of creating this config file, although the main issue is a different one (how to configure svcutil to fetch metadata from a custom endpoint), so it wasn't so obvious to make the connection.

 

Technorati tags: ,


  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Feedback

# re: The maximum nametable character count quota (16384) has been exceeded

Thanks, you saved my a$$ today!!! 11/20/2008 10:29 PM | Guy Barrette

# re: The maximum nametable character count quota (16384) has been exceeded

So you HAVE to use an HTTP binding?? You can't make this work with NetTCPBinding?? 12/15/2008 10:12 PM | Joe Krueger

# re: The maximum nametable character count quota (16384) has been exceeded

Hi, really good post, I spent with this problem 2 days until finally I got it, another solution is to update the config for devenv. 1/14/2009 9:03 PM | Diadiora Alexandru

# re: The maximum nametable character count quota (16384) has been exceeded

This will not solve the issue on NET.TCP binding.
I just tried it 4/9/2009 7:10 PM | Mirzet

# re: The maximum nametable character count quota (16384) has been exceeded

Thanks a lot!! 7/27/2009 5:10 PM | Raul Pereda

# re: The maximum nametable character count quota (16384) has been exceeded

I have figured out how to exchange the Net.tcp.

You have to put in BasicHttp binding, together with Net.TCP, so that Mex can use Http for data exchange, but also able to find out the end point for Net.TCP.

You then remove the endpoint for BasicHttp on both server and client's config. 8/5/2009 8:16 PM | Ken Han

# re: The maximum nametable character count quota (16384) has been exceeded

This is the gift that keeps on giving. In one minute you've saved me from a multi-day ordeal. Deeply grateful! 8/6/2009 5:12 PM | Evan Stein

# re: The maximum nametable character count quota (16384) has been exceeded

I ran into this problem when my WCF service reached a large size.
I could no longer right click on the service in Visual Studio and select Update service reference.

I also could not run svcutil.exe without an error when my WCF service was large.
When I commented out some of the functions to get the size smaller, everything would work, but when I added even one function after that point, it would fail. No matter what the function was.

I found out which files needed to be changed by using process monitor while doing various operations.

To fix these problems I had to do 5 things:

1) Replace the svcutil.exe.config file with:
My file was located here: SvcUtil.exe.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<client>
<endpoint name="net.tcp" binding="netTcpBinding" bindingConfiguration="GenericBinding"
contract="IMetadataExchange" />
<endpoint name="http" binding="wsHttpBinding" bindingConfiguration="SecureBinding" contract="IMetadataExchange" />
</client>
<bindings>
<netTcpBinding>
<binding name="GenericBinding" maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647" >
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
<security mode="None"/>
</binding>
</netTcpBinding>
<wsHttpBinding>
<binding name="SecureBinding" maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647" >
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
<security mode="Message">
<transport clientCredentialType="Windows" />
</security>
</binding>
</wsHttpBinding>
</bindings>
</system.serviceModel>
</configuration>


2) Add the client endpoints and the <bindings> element to your machine.config.
My file was located here: C:\Windows\Microsoft.NET\Framework\v2.0.50727\CONFIG\machine.config

3) Add the whole <System.ServiceModel> inside your devenv.exe.config
My file was located here: C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe.config

4) Modify the endpoint and bindings of my client app. (myapp.exe.config)

5) Modify the endpoints and bindings of my WCF service. (mywcfservice.exe.config) 11/20/2009 10:51 PM | Brian R. Bondy

# re: The maximum nametable character count quota (16384) has been exceeded

WOW... I spent so much time trying to fix this.
Gave up then it snuck up on me again.
I was so happy when your solution worked. Fabulous!! 1/20/2010 2:51 AM | Willhunting

# re: The maximum nametable character count quota (16384) has been exceeded

Brian, thank you so much for your solution! Really made my day, thanks! 2/22/2010 3:58 PM | Mike S.

# re: The maximum nametable character count quota (16384) has been exceeded

Thanks so much for your solution! It works perfectly! By the way, this issue has not yet been addressed in VS2010, poor... 4/22/2010 8:19 PM | Eddie Chu

# re: The maximum nametable character count quota (16384) has been exceeded

Diadiora, thank you very much, this solution worked very and saved me much frustration! 4/28/2010 1:57 PM | Zac Horn

# re: The maximum nametable character count quota (16384) has been exceeded

Thank you for taking time to blog this. This has saved my day. 7/6/2010 8:54 AM | krish

# re: The maximum nametable character count quota (16384) has been exceeded

In Machine.Config, 1'st write in XML
<bindings>
<netTcpBinding>
<binding name="GenericBinding" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" >
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647"
maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode="None"/>
</binding>
</netTcpBinding>
</bindings>

then

<client>
<endpoint name="net.tcp" binding="netTcpBinding" bindingConfiguration="GenericBinding" contract="IMetadataExchange" />
<metadata>
<policyImporters>
<extension type="System.ServiceModel.Channels.ContextBindingElementImporter, system.workflowservices, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"/>
</policyImporters>
<wsdlImporters>
<extension type="System.ServiceModel.Channels.ContextBindingElementImporter, system.workflowservices, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"/>
</wsdlImporters>
</metadata>
</client>

under
<system.serviceModel> tag,


now i am cooL, and its working really GooD in my case :)

Thanks for publishing such helping stuff. 3/31/2011 9:44 AM | Muhammad Niaz

# re: The maximum nametable character count quota (16384) has been exceeded

Thanks a lot for this. I spent more than 4 hours before i stumbled upon your link, Muhammad Niaz's svcutil.exe.config was a life saver.
4/14/2011 9:24 PM | Senthil

# re: The maximum nametable character count quota (16384) has been exceeded

Your name shall be etched in digital stone for all time. 6/14/2011 5:00 PM | WhiskeyDelta

# re: The maximum nametable character count quota (16384) has been exceeded

I've modified a lot of svcutil.exe generated cs code, then met this issue.
is there any workaround without re-run svcutil.exe using the new config file? 6/29/2011 6:39 AM | charles

# re: The maximum nametable character count quota (16384) has been exceeded

you have to change maxReceivedMessageSize only really it seems. For net.tcp this is enough:

<configuration>
<system.serviceModel>
<bindings>
<netTcpBinding>

<binding name="texMex" maxReceivedMessageSize="1024000"><!-- increase this one-->
<readerQuotas maxNameTableCharCount="163840" /><!-- never touch this-->
<security mode="None" />
</binding>
....
<client>
<endpoint binding="netTcpBinding" bindingConfiguration="texMex"
contract="IMetadataExchange" name="net.tcp" />

9/22/2011 4:47 PM | Stian

Post a comment