I am trying to persist a custom dimension style in ArcMap with Arcobjects, I am getting this error when adding the style from the Stream in the Load method.
at ESRI.Carto.IDimensionStyles.AddStyle() as DimToolbar.ApplicationExtension1.Load() in ...\DimToolbar
ApplicationExtension1.cs: line 254
Here is the Load method line 254 is line 59 below.
<SPAN class="keyword token">public</SPAN> <SPAN class="keyword token">void</SPAN> <SPAN class="token function">Load</SPAN><SPAN class="punctuation token">(</SPAN>IVariantStream Stream<SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="comment token">//TODO: Load persisted data from document stream</SPAN>
<SPAN class="keyword token">if</SPAN><SPAN class="punctuation token">(</SPAN>Stream<SPAN class="operator token">!=</SPAN><SPAN class="keyword token">null</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">var</SPAN> count <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">int</SPAN><SPAN class="punctuation token">)</SPAN>Stream<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Read</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
MessageBox<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Show</SPAN><SPAN class="punctuation token">(</SPAN>count<SPAN class="punctuation token">.</SPAN><SPAN class="token function">ToString</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>count <SPAN class="operator token">></SPAN> c_Version <SPAN class="operator token">||</SPAN> count <SPAN class="operator token"><=</SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">throw</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">Exception</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Wrong version!"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">string</SPAN> sName <SPAN class="operator token">=</SPAN> <SPAN class="string token">""</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">int</SPAN> iRefScale <SPAN class="operator token">=</SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">string</SPAN> sExpression <SPAN class="operator token">=</SPAN> <SPAN class="string token">""</SPAN><SPAN class="punctuation token">;</SPAN>
ITextSymbol pTextSymbol <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">null</SPAN><SPAN class="punctuation token">;</SPAN>
ILineSymbol pLineSymbol <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">null</SPAN><SPAN class="punctuation token">;</SPAN>
IMarkerSymbol pMrkrSymbol <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">null</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>count <SPAN class="operator token">==</SPAN> <SPAN class="number token">2</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
sName <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">string</SPAN><SPAN class="punctuation token">)</SPAN>Stream<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Read</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
iRefScale <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">int</SPAN><SPAN class="punctuation token">)</SPAN>Stream<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Read</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
sExpression <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">string</SPAN><SPAN class="punctuation token">)</SPAN>Stream<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Read</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
pTextSymbol <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN>ITextSymbol<SPAN class="punctuation token">)</SPAN>Stream<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Read</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
pLineSymbol <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN>ILineSymbol<SPAN class="punctuation token">)</SPAN>Stream<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Read</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
pMrkrSymbol <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN>IMarkerSymbol<SPAN class="punctuation token">)</SPAN>Stream<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Read</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
ILayer pLayer <SPAN class="operator token">=</SPAN> <SPAN class="token function">ReturnLayerByName</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"DIM"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
IFeatureLayer pFeatureLayer <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN>IFeatureLayer<SPAN class="punctuation token">)</SPAN>pLayer<SPAN class="punctuation token">;</SPAN>
IFeatureClass pFeatureClass <SPAN class="operator token">=</SPAN> pFeatureLayer<SPAN class="punctuation token">.</SPAN>FeatureClass<SPAN class="punctuation token">;</SPAN>
ISchemaLock pSchemaLock <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN>ISchemaLock<SPAN class="punctuation token">)</SPAN>pFeatureClass<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">try</SPAN>
<SPAN class="punctuation token">{</SPAN>
pSchemaLock<SPAN class="punctuation token">.</SPAN><SPAN class="token function">ChangeSchemaLock</SPAN><SPAN class="punctuation token">(</SPAN>esriSchemaLock<SPAN class="punctuation token">.</SPAN>esriExclusiveSchemaLock<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
IDimensionClassExtension pDimExt <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN>IDimensionClassExtension<SPAN class="punctuation token">)</SPAN>pFeatureClass<SPAN class="punctuation token">.</SPAN>Extension<SPAN class="punctuation token">;</SPAN>
pDimExt<SPAN class="punctuation token">.</SPAN>ReferenceScale <SPAN class="operator token">=</SPAN> iRefScale<SPAN class="punctuation token">;</SPAN>
pDimExt<SPAN class="punctuation token">.</SPAN>ReferenceScaleUnits <SPAN class="operator token">=</SPAN> esriUnits<SPAN class="punctuation token">.</SPAN>esriFeet<SPAN class="punctuation token">;</SPAN>
IDimensionStyle pDimStyle <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">DimensionStyleClass</SPAN>
<SPAN class="punctuation token">{</SPAN>
Name <SPAN class="operator token">=</SPAN> sName
<SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">;</SPAN>
IDimensionStyleDisplay pNewDimDisplay <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN>IDimensionStyleDisplay<SPAN class="punctuation token">)</SPAN>pDimStyle<SPAN class="punctuation token">;</SPAN>
pNewDimDisplay<SPAN class="punctuation token">.</SPAN>MarkerDisplay <SPAN class="operator token">=</SPAN> esriDimensionDisplay<SPAN class="punctuation token">.</SPAN>esriDimensionDisplayBoth<SPAN class="punctuation token">;</SPAN>
pNewDimDisplay<SPAN class="punctuation token">.</SPAN>DimensionLineSymbol <SPAN class="operator token">=</SPAN> pLineSymbol<SPAN class="punctuation token">;</SPAN>
pNewDimDisplay<SPAN class="punctuation token">.</SPAN>BeginMarkerSymbol <SPAN class="operator token">=</SPAN> pMrkrSymbol<SPAN class="punctuation token">;</SPAN>
pNewDimDisplay<SPAN class="punctuation token">.</SPAN>EndMarkerSymbol <SPAN class="operator token">=</SPAN> pMrkrSymbol<SPAN class="punctuation token">;</SPAN>
pNewDimDisplay<SPAN class="punctuation token">.</SPAN>MarkerFit <SPAN class="operator token">=</SPAN> esriDimensionMarkerFit<SPAN class="punctuation token">.</SPAN>esriDimensionMarkerFitText<SPAN class="punctuation token">;</SPAN>
pNewDimDisplay<SPAN class="punctuation token">.</SPAN>MarkerDisplay <SPAN class="operator token">=</SPAN> esriDimensionDisplay<SPAN class="punctuation token">.</SPAN>esriDimensionDisplayBoth<SPAN class="punctuation token">;</SPAN>
pNewDimDisplay<SPAN class="punctuation token">.</SPAN>DrawLineOnFit <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">false</SPAN><SPAN class="punctuation token">;</SPAN>
IDimensionStyleText pNewDimText <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN>IDimensionStyleText<SPAN class="punctuation token">)</SPAN>pDimStyle<SPAN class="punctuation token">;</SPAN>
pNewDimText<SPAN class="punctuation token">.</SPAN>Expression <SPAN class="operator token">=</SPAN> sExpression<SPAN class="punctuation token">;</SPAN>
pNewDimText<SPAN class="punctuation token">.</SPAN>ExpressionParserName <SPAN class="operator token">=</SPAN> <SPAN class="string token">"Python"</SPAN><SPAN class="punctuation token">;</SPAN>
pNewDimText<SPAN class="punctuation token">.</SPAN>TextDisplay <SPAN class="operator token">=</SPAN> esriDimensionTextDisplay<SPAN class="punctuation token">.</SPAN>esriDimensionTDExpression<SPAN class="punctuation token">;</SPAN>
pNewDimText<SPAN class="punctuation token">.</SPAN>TextSymbol <SPAN class="operator token">=</SPAN> pTextSymbol<SPAN class="punctuation token">;</SPAN>
IDimensionStyles pDimStyles <SPAN class="operator token">=</SPAN> pDimExt<SPAN class="punctuation token">.</SPAN>DimensionStyles<SPAN class="punctuation token">;</SPAN>
pDimExt<SPAN class="punctuation token">.</SPAN><SPAN class="token function">UpdateProperties</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
pDimStyles<SPAN class="punctuation token">.</SPAN><SPAN class="token function">AddStyle</SPAN><SPAN class="punctuation token">(</SPAN>pDimStyle<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="keyword token">catch</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="token class-name">COMException</SPAN> comExcept<SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
MessageBox<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Show</SPAN><SPAN class="punctuation token">(</SPAN>comExcept<SPAN class="punctuation token">.</SPAN>StackTrace<SPAN class="punctuation token">.</SPAN><SPAN class="token function">ToString</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="keyword token">finally</SPAN>
<SPAN class="punctuation token">{</SPAN>
pSchemaLock<SPAN class="punctuation token">.</SPAN><SPAN class="token function">ChangeSchemaLock</SPAN><SPAN class="punctuation token">(</SPAN>esriSchemaLock<SPAN class="punctuation token">.</SPAN>esriSharedSchemaLock<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="punctuation token">}</SPAN>
Marshal<SPAN class="punctuation token">.</SPAN><SPAN class="token function">ReleaseComObject</SPAN><SPAN class="punctuation token">(</SPAN>Stream<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>I am reading the stream in the same order it was written the dimension style seems to be added but there is something wrong with the text, the expression is in the dimension style after Load method runs but the text is not displayed, Here is screenshot of the python expression in the extension.

