Quantcast
Viewing all articles
Browse latest Browse all 1741

Commented Unassigned: COM Exceptions in NetOffice (Excel) [21030]

I'm trying to port an Excel VSTO Addin over to NetOffice. So far I've got the Addin launching, but any time I try to make a call on a NetOffice object I get the following:
```
----- Source: NetOffice -----
Inner Exception 1: System.MissingMethodException: Method 'System.__ComObject.Add' not found.
at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
at NetOffice.Invoker.MethodReturn(COMObject comObject, String name, Object[] paramsArray)
System.Runtime.InteropServices.COMException: See inner exception(s) for details.
at NetOffice.Invoker.MethodReturn(COMObject comObject, String name, Object[] paramsArray)
at NetOffice.ExcelApi.Workbooks.Add()
at Hcg.Stinger.Connect.InitializeAutomationAddIn() in D:\Code\Prevision\Source\Hcg\Stinger\Connect.cs:line 541
at Hcg.Stinger.Connect.OnStartupComplete(Array& custom, MainTaskPane taskPane) in D:\Code\Prevision\Source\Hcg\Stinger\Connect.cs:line 258
----------
```

The code is pretty straightforward:
```
Excel.Workbook book = _excelApp.Workbooks.Add();
```

I also got the similar error when I called saying the Cursor did not exist, even though it show up in the intellisense:
```
Excel.Enums.XlMousePointer cursorOriginal = Excel.Enums.XlMousePointer.xlDefault;
_excelApp.Cursor = Excel.Enums.XlMousePointer.xlWait;
```

Ideas?

Thanks,

Erick
Comments: ** Comment from web user: ericklind **

Actually I did get it working. I'm on Excel 2010 32 bit, VS 2010, .NET 4.0, NetOffice version 1.6, and Win 7 64 bit.
But now I'm getting other COM issues when I try to access other things like the taskPane:
```
Inner Exception 1: System.Runtime.InteropServices.InvalidComObjectException: Attempt has been made to use a COM object that does not have a backing class factory.
at NetOffice.Invoker.PropertySet(COMObject comObject, String name, Object[] value)
System.Runtime.InteropServices.COMException: See inner exception(s) for details.
at NetOffice.Invoker.PropertySet(COMObject comObject, String name, Object[] value)
at NetOffice.OfficeApi._CustomTaskPane.set_Visible(Boolean value)
at PrevisionAddIn.Addin.ShowExcelTaskPane(UserControl taskPane, String title) in D:\Code\Prevision\Source\Hcg\Stinger\PrevisionAddIn\Addin.cs:line 139
at Hcg.Stinger.TaskPaneFrameController.ShowController(ITaskPaneController controller) in D:\Code\Prevision\Source\Hcg\Stinger\TaskPaneFrameController.cs:line 332
at Hcg.Stinger.TaskPaneFrameController.Show(EnumGlobalTaskPanes taskPane) in D:\Code\Prevision\Source\Hcg\Stinger\TaskPaneFrameController.cs:line 146
at Hcg.Stinger.TaskPaneFrameController.AuthorizeTaskPanes() in D:\Code\Prevision\Source\Hcg\Stinger\TaskPaneFrameController.cs:line 174
at Hcg.Stinger.TaskPaneFrameController..ctor(MainTaskPane frame) in D:\Code\Prevision\Source\Hcg\Stinger\TaskPaneFrameController.cs:line 83
at Hcg.Stinger.Connect.OnStartupComplete(Array& custom, MainTaskPane taskPane) in D:\Code\Prevision\Source\Hcg\Stinger\Connect.cs:line 264
----------

```

So the the code is pretty straight forward:
```
private Office._CustomTaskPane _taskPane = null;

public void CTPFactoryAvailable(object CTPFactoryInst)
{
try
{
Office.ICTPFactory ctpFactory = new NetOffice.OfficeApi.ICTPFactory(_app, CTPFactoryInst);
_taskPane = ctpFactory.CreateCTP("Hcg.Stinger.MainTaskPane", "PrevisionEPM", Type.Missing);
_taskPane.DockPosition = MsoCTPDockPosition.msoCTPDockPositionRight;
_taskPane.DockPositionRestrict = MsoCTPDockPositionRestrict.msoCTPDockPositionRestrictNoChange;
_taskPane.Width = 300;
_taskPane.Visible = true;
_mainTaskPane = _taskPane.ContentControl as MainTaskPane;
ctpFactory.Dispose();
}
catch (Exception exception)
{
string message = string.Format("An error occured.{0}{0}{1}", Environment.NewLine, exception.Message);
MessageBox.Show(message, _progId, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
public void ShowExcelTaskPane(System.Windows.Forms.UserControl taskPane, string title)
{
_taskPane.Visible = false;
_taskPane.DockPosition = MsoCTPDockPosition.msoCTPDockPositionRight;
_taskPane.DockPositionRestrict = MsoCTPDockPositionRestrict.msoCTPDockPositionRestrictNoChange;
_taskPane.Visible = true;
}
```
It also sets my takspane so that none of the controls work on it at all. Anything I need to do?


Viewing all articles
Browse latest Browse all 1741

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>