cannot send tamplateUpdate(...)

Dec 22, 2010 at 2:39 AM

when i run templateUpdate(...), i see this following error:

MailChimp.Types.MCException: -1: Failed to deserialize data ---> System.Runtime.Serialization.SerializationException: There was an error deserializing the object of type System.Boolean. ReadElementContentAs() methods cannot be called on an element that has child elements. Line 1, position 22. ---> System.Xml.XmlException: ReadElementContentAs() methods cannot be called on an element that has child elements. Line 1, position 22. at System.Xml.XmlReader.SetupReadElementContentAsXxx(String methodName) at System.Xml.XmlReader.ReadElementContentAsBoolean() at System.Runtime.Serialization.XmlReaderDelegator.ReadElementContentAsBoolean() at System.Runtime.Serialization.BooleanDataContract.ReadXmlValue(XmlReaderDelegator reader, XmlObjectSerializerReadContext context) at System.Runtime.Serialization.DataContractSerializer.InternalReadObject(XmlReaderDelegator xmlReader, Boolean verifyObjectName) at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName) --- End of inner exception stack trace --- at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName) at System.Runtime.Serialization.DataContractSerializer.ReadObject(XmlReader reader, Boolean verifyObjectName) at MailChimp.Types.Common.deserializeXml[T](String x) at MailChimp.MCHelper.deserialize[T](String x) --- End of inner exception stack trace --- at MailChimp.MCHelper.deserializeFail[a](Exception ex) at MailChimp.MCHelper.deserialize[T](String x) at MailChimp.MCApiModule.callServer[T](MCApi m, String name, FSharpOption`1 p) at MailChimp.MCApiModule.Template.update(MCApi m, Int32 templateID, IEnumerable`1 values) at MailChimp.MCApi.TemplateUpdate(Int32 templateID, IEnumerable`1 values) at MailChimpManager.AddTemplate.UpdateTemplate() in F:\My Dropbox\MailChimpManager\MailChimpManager\Template_Manager.aspx.cs:line 83


this is my code


protected void UpdateTemplate()
                MailChimp.Types.Template.Value value = new MailChimp.Types.Template.Value(txtTemplateName.Value, txtBody.Value);
                MCList<MailChimp.Types.Template.Value> lst = new MCList<MailChimp.Types.Template.Value>();
                mc = new MCApi(key, true);

                bool sttUpdate;

                sttUpdate = mc.TemplateUpdate(int.Parse(Request.QueryString["ID"]), lst);


please, reply for me soon, thanks!!!

Dec 22, 2010 at 10:52 AM
Edited Dec 22, 2010 at 10:57 AM

Hi lovekiller30,


THNX for pointing this out.  templateUpdate method is fixed now.

The mailchimp documentation is misleading. It suggests supplying values array parameter while all U need is just "name" and/or "html".

So now u can use this:


protected void UpdateTemplate()

 mc = new MCApi(key, true);

 bool sttUpdate = mc.TemplateUpdate(int.Parse(Request.QueryString["ID"]), txtTemplateName.Value, txtBody.Value);


Note that "name"/"html" parameters are optional. So if U want to update only one of them, set the other null (it will be automatically removed from request):

mc.TemplateUpdate(int.Parse(Request.QueryString["ID"]), "XXX", null);

Dec 22, 2010 at 11:57 AM
Edited Dec 22, 2010 at 12:04 PM

thank for reply.

i have a question more.

when i use CampaignUpdate(...), i can not update Tracking and Template  although return value is true from MailChimp server


My Code:

protected void mcCampaignUpdate()

            string name = txtOption.value;
            mc = new MCApi(key, true);
            get_campaignUpdate1.campaignId = Request.QueryString["ID"];
            bool sttUp;
            sttUp = mc.CampaignUpdate<object>(campaignId, name, value);

return sttUp is true

type of "value" is Campaign.Tracking with Tracking

and string with Template


Can you do Tutorial about CampaignUpdate?

and i thank you very much

Dec 22, 2010 at 12:09 PM

ah! FromName of return value "MCApiModule.Campaign.campaigns(mc, fsCampFilter, start, lim)" is null

Dec 22, 2010 at 1:10 PM
Edited Dec 22, 2010 at 1:45 PM


1) There was typo in "from_name" parameter. So now it's ok

2) It seems that campaignUpdate method works fine with single value parameters like title, subject etc:


mc = new MCApi(key, true);

mc.CampaignUpdate(cid, "title", "XXX")

mc.CampaignUpdate(cid, "authenticate", true)

U'll see these parameters changed.


It also works with segment_opts:

var s_opt = Campaign.SegmentOptions.Parse(Campaign.Match.AND, new string[] {"date => gt => 2010-01-01"});

mc.CampaignUpdate(cid, "segment_opts", s_opt);


 But it fails to update  tracking. I'll contact the mailchimp support and reply asap.

(it seems to be their issue. check this post)

Dec 22, 2010 at 1:51 PM

In general all the methods throw exceptions when receiving error response.

So it may be useful to enclose api calls in try catch blocks and handle exceptions when thrown.

Dec 22, 2010 at 1:56 PM

thank for your Answers