I am exploring using NetOffice.Visio for my project VisioAuaomtion: https://github.com/saveenr/VisioAutomation
Here's some code which works with Microsoft.Office.Interop.Visio
// using IVisio = Microsoft.Office.Interop.Visio;
var app = new IVisio.Application();
var doc = app.Documents.Add("");
var page = app.ActivePage;
var shape = page.DrawRectangle(0, 0, 2, 3);
shape.Text = "With Microsoft.Office.Interop.Visio";
var SID_SRCStream = new short[4];
SID_SRCStream[0] = (short)shape.ID16;
SID_SRCStream[1] = (short)IVisio.VisSectionIndices.visSectionObject;
SID_SRCStream[2] = (short)IVisio.VisRowIndices.visRowFill;
SID_SRCStream[3] = (short)IVisio.VisCellIndices.visFillForegnd;
System.Array a;
page.GetFormulasU(SID_SRCStream, out a);
But the same code throws an exception with NetOffice.Visio (for .NET 4.0)
// using IVisioNetOffice = NetOffice.VisioApi;
var app = new IVisioNetOffice.Application();
var doc = app.Documents.Add("");
var page = app.ActivePage;
var shape = page.DrawRectangle(0, 0, 2, 3);
shape.Text = "With NetOffice";
var SID_SRCStream = new short[4];
SID_SRCStream[0] = (short)shape.ID16;
SID_SRCStream[1] = (short)IVisioNetOffice.Enums.VisSectionIndices.visSectionObject;
SID_SRCStream[2] = (short)IVisioNetOffice.Enums.VisRowIndices.visRowFill;
SID_SRCStream[3] = (short)IVisioNetOffice.Enums.VisCellIndices.visFillForegnd;
object[] a;
page.GetFormulasU(SID_SRCStream, out a);
The exception occurs in GetFormulas the inner exception says "{"Type mismatch. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))"}".
I suspect the problem is with the second parameter because setformulas seems to work with the same SID_SRCStream.
Any ideas what is wrong in my code?
Comments: I must to ask for it . It is definitely the same kind of exception? BTW: Any kind of stack trace want very helpful here. I see 2 more possible reasons here. 1) NetOffice failed to marshal(back) an array as an output argument here. arrays in COM Interop is a very very special topic. (the stack trace can clearify that, remove any private informations if you, want i want only see the last netoffice calls) 2) The Visio dev team does something wrong in the IDispatch implementation of GetFormulas( this is a common scenario, i find a lot of bugs all the NetOffice years here in all Office applications except Excel - the "primusin parvum") I'm sorry to say that i dont have visio installed on my current system. (I'm a freelance programmer and not in my country right now) Please give me one day to fix this to reproduce your problem and don let me alone here. This is probably an important issue in NetOffice. Please try this static method instead with "a" as null value (for diagnostics only, i'm sure that fails but i can make sure a possible third kind of error is impossible) public static void GetFormulas(NetOffice.VisioApi.IVPage page, Int16[] sID_SRCStream, out object[] formulaArray) { ParameterModifier[] modifiers = Invoker.CreateParamModifiers(false,true); formulaArray = null; object[] paramsArray = new object[]{sID_SRCStream, formulaArray}; Invoker.Method(page, "GetFormulas", paramsArray, modifiers); formulaArray = (object[])paramsArray[1]; } Thanks and i work for this issue in high priority. *Sebastian
Here's some code which works with Microsoft.Office.Interop.Visio
// using IVisio = Microsoft.Office.Interop.Visio;
var app = new IVisio.Application();
var doc = app.Documents.Add("");
var page = app.ActivePage;
var shape = page.DrawRectangle(0, 0, 2, 3);
shape.Text = "With Microsoft.Office.Interop.Visio";
var SID_SRCStream = new short[4];
SID_SRCStream[0] = (short)shape.ID16;
SID_SRCStream[1] = (short)IVisio.VisSectionIndices.visSectionObject;
SID_SRCStream[2] = (short)IVisio.VisRowIndices.visRowFill;
SID_SRCStream[3] = (short)IVisio.VisCellIndices.visFillForegnd;
System.Array a;
page.GetFormulasU(SID_SRCStream, out a);
But the same code throws an exception with NetOffice.Visio (for .NET 4.0)
// using IVisioNetOffice = NetOffice.VisioApi;
var app = new IVisioNetOffice.Application();
var doc = app.Documents.Add("");
var page = app.ActivePage;
var shape = page.DrawRectangle(0, 0, 2, 3);
shape.Text = "With NetOffice";
var SID_SRCStream = new short[4];
SID_SRCStream[0] = (short)shape.ID16;
SID_SRCStream[1] = (short)IVisioNetOffice.Enums.VisSectionIndices.visSectionObject;
SID_SRCStream[2] = (short)IVisioNetOffice.Enums.VisRowIndices.visRowFill;
SID_SRCStream[3] = (short)IVisioNetOffice.Enums.VisCellIndices.visFillForegnd;
object[] a;
page.GetFormulasU(SID_SRCStream, out a);
The exception occurs in GetFormulas the inner exception says "{"Type mismatch. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))"}".
I suspect the problem is with the second parameter because setformulas seems to work with the same SID_SRCStream.
Any ideas what is wrong in my code?
Comments: I must to ask for it . It is definitely the same kind of exception? BTW: Any kind of stack trace want very helpful here. I see 2 more possible reasons here. 1) NetOffice failed to marshal(back) an array as an output argument here. arrays in COM Interop is a very very special topic. (the stack trace can clearify that, remove any private informations if you, want i want only see the last netoffice calls) 2) The Visio dev team does something wrong in the IDispatch implementation of GetFormulas( this is a common scenario, i find a lot of bugs all the NetOffice years here in all Office applications except Excel - the "primusin parvum") I'm sorry to say that i dont have visio installed on my current system. (I'm a freelance programmer and not in my country right now) Please give me one day to fix this to reproduce your problem and don let me alone here. This is probably an important issue in NetOffice. Please try this static method instead with "a" as null value (for diagnostics only, i'm sure that fails but i can make sure a possible third kind of error is impossible) public static void GetFormulas(NetOffice.VisioApi.IVPage page, Int16[] sID_SRCStream, out object[] formulaArray) { ParameterModifier[] modifiers = Invoker.CreateParamModifiers(false,true); formulaArray = null; object[] paramsArray = new object[]{sID_SRCStream, formulaArray}; Invoker.Method(page, "GetFormulas", paramsArray, modifiers); formulaArray = (object[])paramsArray[1]; } Thanks and i work for this issue in high priority. *Sebastian