Quantcast
Channel: NetOffice - MS Office in .NET
Viewing all articles
Browse latest Browse all 1741

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

$
0
0
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 **

Hi Sebastian,
The Saga continues. I was finally able to get this doing what I needed to. I noticed that on the TaskPanes.Add it was not doing anything to set or create the TaskPaneInfo.Pane, which I need for my app. I changed the code to this, and it worked:
```
public Addin()
{
try
{
TaskPanes.Add(typeof(MainTaskPane), "Main Task Pane");
TaskPanes[0].DockPosition = MsoCTPDockPosition.msoCTPDockPositionRight;
TaskPanes[0].DockPositionRestrict = MsoCTPDockPositionRestrict.msoCTPDockPositionRestrictNoHorizontal;
TaskPanes[0].Width = 250;
TaskPanes[0].Visible = true;
TaskPanes[0].Arguments = new object[] { this };


this.OnStartupComplete += new OnStartupCompleteEventHandler(Addin_OnStartupComplete);
this.OnConnection += new OnConnectionEventHandler(Addin_OnConnection);
this.OnDisconnection += new OnDisconnectionEventHandler(Addin_OnDisconnection);
}
catch (Exception throwedException)
{
string details = string.Format("{1}{1}Details:{1}{1}{0}", throwedException.Message, Environment.NewLine);
MessageBox.Show("An error occured in OnAction: " + details, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

public override void CTPFactoryAvailable(object CTPFactoryInst)
{
try
{
base.CTPFactoryAvailable(CTPFactoryInst);
_taskPane = TaskPanes[0];
_mainTaskPane = _taskPane.Pane.ContentControl as MainTaskPane;
}
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);
}
}
```
Now the problem is that my taskpane is frozen as if it's disabled. I cannot interact with any controls on it at all. I've checked the status and it is enabled. Is there something that I need to do in order to enable that otherwise? I've looked through the samples and nothing stands out.

Thanks again for all your work!

-Erick


Viewing all articles
Browse latest Browse all 1741

Trending Articles



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