Add richtextcontentcontrol from word document throw exception

34 views Asked by At

I try to add a richtext content control to my word document but the richtext content control object is faulty and I am not able to apply for e.g tag to this object

the code to add a richtext content control at specific range selection is

using (var range = new ReleaseComObject<Range>(myRange))
{
    var contentControl = vstoDocument.Controls.AddRichTextContentControl(range.ComObject, $"PROPERTY{Guid.NewGuid()}");
    contentControl.PlaceholderText = propertyContentControl.Key; //  exception here
}

It works flawlessly in some places of the document. For example I create a textbox and in the textbox I have some text. When I select a text and try apply tag to it I call the method above. But for some reason, when the textbox is place in header part of document and at specific position, I received exception.

The exception I received was:

This document might not function as expected because the following control is missing: MYCONTROL. Data that relies on this control will not be automatically displayed or updated, and other custom functionality will not be available. Contact your administrator or the author of this document for further assistance.

I inspect the generated control and found that its faulty. Some of its properties show error

enter image description here

btw: ReleaseComObject is a wrapper class to hold the actual object. this class is disposable. // Definition of eleasecomobject, implement Idisposable

public sealed class ReleaseComObject<T> : IDisposable
public ReleaseComObject(T comObject) => this.myComObject = comObject;

Any idea ?

0

There are 0 answers