Only one instance of the type is allowed for this parent, but drawing part is null
<p>I have this code</p>

<pre><code>ImagePartType ipt = ImagePartType.Jpeg;
DrawingsPart drawingsPart1;
ImagePart imagePart1;

WorksheetDrawing worksheetDrawing1;
if (sheet1.DrawingsPart == null)
   {
        drawingsPart1 = sheet1.AddNewPart&lt;DrawingsPart&gt;();
        imagePart1 = drawingsPart1.AddImagePart(ipt, sheet1.GetIdOfPart(drawingsPart1));
        worksheetDrawing1 = new WorksheetDrawing();
   }
</code></pre>

<p>but at</p>

<pre><code>drawingsPart1 = sheet1.AddNewPart&lt;DrawingsPart&gt;();
</code></pre>

<p>it throws an Exception " Only one instance of the type is allowed for this parent"</p>

<p>and </p>

<p>sheet1.DrawingsPart is null, so there is no other Drawing part. Any idea how to solve this? This exact code is working in my second project, with same excel file! Thank you.</p>

<pre><code>using (SpreadsheetDocument document = SpreadsheetDocument.Open(outputDocumentStream, true))
                    {
                        wbPart = document.WorkbookPart;
                        document.Close();
                    }      
sheet1 = GetWorksheetPart(wbPart, "Sheet1")
</code></pre>

<p>and</p>

<pre><code>public WorksheetPart GetWorksheetPart(WorkbookPart workbookPart, string sheetName)
        {
            string relId = workbookPart.Workbook.Descendants&lt;Sheet&gt;().First(s =&gt; sheetName.Equals(s.Name)).Id;

            return (WorksheetPart)workbookPart.GetPartById(relId);
        }
</code></pre>

<p>I can't write more codes, because it is not open source project. Basically I get worksheet and worksheet part by typing sheet name, and after that i have to insert picture in some cell.</p>