Cannot insert images without Word error

Jan 29, 2014 at 2:37 PM
I'm getting the following error when trying to insert a logo. My code looks for the paragraph containing <logo> and then attempts to replace it with a dynamically loaded image.
        private static void InsertLogo(DocX doc, string rootPath)
            var placeholder = doc.Paragraphs.First(p => p.Text.Contains("<logo>"));

            var logo = doc.AddImage(Path.Combine(rootPath, "logo.jpg"));

Upon opening the saved doc, Word 2013 gives me this:


and then this:


If I click Yes it appears to have inserted it correctly, but I do not want my users thinking that their generated documents are corrupt.
Jan 29, 2014 at 3:28 PM
Hi rmbrown,

Are you using the latest version of DocX?
If yes and you are still having this problem then please email me the original document and the piece of code that generates the broken document.
If not then please try your code with the newest version of DocX.

Thanks and happy coding,
Jan 29, 2014 at 5:04 PM
Thanks. I think I've found the problem.

My code uses InsertDocument to build up the main document to save. One of the documents that are inserted contains an arrow shape:


If I remove the arrow shape from the document it works.
Jan 29, 2014 at 8:12 PM

is the arrow shape smart art or something very fancy?

Can you send me the document with the arrow? I would still like to try and fix the merge issue.

By the way which version of DocX are you using?

Kind regards,
Jan 30, 2014 at 9:54 AM

The arrow shape is just a Word shape.

Here's a link to an Example Word doc.

This is with version
Jan 30, 2014 at 9:57 AM
Have you tried using the source code version rather then provided binary?

Nov 22, 2016 at 9:27 AM

I am getting exactly the same error, but only after I insert a second image in the document.

I am using the same code to insert both images.

the code:
                    using (MemoryStream ms = new MemoryStream())
                        System.Drawing.Image myImg = System.Drawing.Image.FromFile(imagePath);
                        myImg.Save(ms, myImg.RawFormat);
                        ms.Seek(0, SeekOrigin.Begin);

                        Novacode.Image img = doc.AddImage(ms);
                        Picture auxImage= img.CreatePicture();
                        p.InsertPicture(auxImage, 0);
Is this a known problem or is something wrong with the code?

Best regards