This project has moved and is read-only. For the latest updates, please go here.

Picture id must be unique, with Code to fix

Apr 14, 2015 at 2:27 PM
Hi all,

I had a certain document where adding a Picture using CreatePicture resulted in a corrupted document when opened in Word 2013/2010. The reason was that the docPr id="" attribute was duplicated. A bookmark already had id="7". So extending the code in Paragraph.cs after the existing lines
foreach (var docPrId in document.Xml.Descendants(XName.Get("docPr", DocX.wp.NamespaceName)))
                existingIds.Add(docPrId.Attributes().FirstOrDefault(x => x.Name == "id").Value);
with the following solved the problem:
foreach (var bookmarkId in document.Xml.Descendants(XName.Get("bookmarkStart", DocX.w.NamespaceName))) {
                var idAtt = bookmarkId.Attributes().FirstOrDefault(x => x.Name.LocalName == "id");
                if (idAtt != null)
Maybe this can be added to the next release.

Apr 14, 2015 at 2:38 PM
I will apply it in a moment. Can you take a look at charts generation? They seem to be broken and most likely the cause is similar to yours. If not it's fine :)
Apr 15, 2015 at 7:32 AM
Charts do not work in my document. Word is also not possible to repair the document. I do not know if the problem is related to the ids, but in my opinion it is necessary to implement a GetUniqueId function. Because it seems that at least bookmarks, all docPr and charts need to have a document wide unique id.

I will keep you updated, if I can fix the issue.
Apr 15, 2015 at 7:35 AM
Charts should work in Office 2010. For some reason they don't work in 2013. Not sure why. But if you can make adjustments for benefit of this community that would be great. Charts are kind of a an ongoing issue from version to version.
Apr 15, 2015 at 9:38 AM
What I can tell right now is, that Office 2013 is much more restrictive on the order of the elements inside the XML and it stops processing the chart if required elements/attributes are missing. For example:
inside of <c:numref> and <c:strRef> an <c:f> tag must exist. Also barseries must have an <c:idx> and <c:order> element.
When I have a working code, I will post it here.
Apr 16, 2015 at 8:01 AM
I do now have working charts in Word 2007/2010/2013. Can I send you the file?
Apr 16, 2015 at 8:12 AM
You can send the file via the patch upload (just pack it as .zip or so). ( and choose upload patch). I will take a look and apply after testing.

It's Great NEWS! Thank you. I'm sure this will get us close to stable release.
Apr 16, 2015 at 8:23 AM
I submitted the file.
Apr 16, 2015 at 8:29 AM
System.NullReferenceException was unhandled
Message=Object reference not set to an instance of an object.
   at Novacode.Chart..ctor() in c:\Projects\DocX\DocX\Charts\Chart.cs:line 226
   at Novacode.LineChart..ctor()
   at Examples.Program.LineChart()
   at Examples.Program.Main(String[] args)
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()

When running Examples :-)
Apr 16, 2015 at 8:43 AM
I fixed that, but there is another issue with y-axis. You know about this?
Apr 16, 2015 at 8:48 AM
Haven't seen this before. I wonder if it behaves the same in Word 2010. I've also updated the Examples with proper console output for charts so that it was visible it crashed on LineCharts. Source commited.
Apr 16, 2015 at 8:56 AM
It looks the same in all my Word installations. Only bar chart and 3d bar chart are wrong.
I will investigate this issue.
Apr 16, 2015 at 2:28 PM
Uploaded the fixed chart.cs file.
Apr 16, 2015 at 2:53 PM
Thanks. Applied sources, released! Thank you very much.