uncatchable Error

Jan 14, 2014 at 3:02 PM
Edited Jan 14, 2014 at 3:03 PM
Hi,

With some experience in VBA and OOP, but beginner in C# and COM programming, I decided to take Office programming to the next level with COM component thanks to NetOffice.

I am looking to build a CustomTaskPane in Excel to list all Named Range of a Workbook.
I used the CTP example given with NetOffice (list of customers) as a "template" to build my add-in.

At Excel Startup, I got a "see inner exception(s)" error. After some investigation, I figured out I cannot access Addin.Application.Names (Named range collection) at launch of the add-in, as (I suppose) no workbook is opened, so no Names collection is available.

I am trying to encapsulate my code in a try / catch procedure
try {
  ... 
     foreach (Excel.name XLName in Addin.Application.Names)  
  ...
} catch (Exception ex) {
  ...
} 
but the error is still here.

Am I missing something ? or how/when can I use Addin.Application.Names ?
Is catching exception not sufficient ?

Thanks in advance for your help!
Coordinator
Jan 14, 2014 at 4:43 PM
sounds like the error occures in another place. may your taskpane instance? when its possible, send me a min. sample solution to public.sebastian[at]web.de i want clearify the situation for you.

*sebastian
Jan 14, 2014 at 5:11 PM
Edited Jan 14, 2014 at 5:13 PM
Thanks for your reactive reply.

You were right, the problem came from the CTP instance creation (i did not change the name of the add-in in the properties of the project - still learning).
I manage to move my way forward on my project : get the list populated and some basic interaction.
As I am moving forward, I have some additional questions that would definitly help me to move faster in this new "land" of C# and COM.
  • From what I read on the net, it is not possible to select a range that is not in the activesheet. That you have to first activate the sheet, then select the range.
    In VBA you could have done a Application.Range("Sheet1!A1:B2").Select to get the right range in the right sheet selected.
    => Could you confirm that it is not the case in NetOffice or COM (i.e. Addin.Application.get_Range("Sheet1!A1:B2").Select() or equivalent will not work) ?
  • From what I understand, COM object are "silos" and therefore each object must be invoked (first activate the sheet, then select the range) in order to work.
    => Is that correct ?
  • Last point : how can I debug my addin within Excel ? Could not find any elements on this.
Thanks a lot for your time and help.
Your library is brilliant and I hope I will soon have the level to get it work perfectly with what I need.
Coordinator
Jan 14, 2014 at 6:29 PM
hey man,

as first i want explain how its possible to debug a managed office addin.
1.) go to the project options => top main menu=>project=>$myProjectProperties (sorry my VS is in german, i hope its the same in yours)
  1. go to the debbuging tab in the project options dialog
  2. change the start action from "start project" to "start external program" and choose excel.exe in the openfile dialog.
thats all. now you can set breakpoints and use all other debugging features.

the second one. your example select a range for the current active sheet(its failed without an active sheet. not sure what does VBA in this case). Range or get_Range means the same in NO. (get_Range is just for compatibility with the stupid plain interop assemblies from Microsoft because C# can't use properties with arguments)

the third: "COM Objects" is not realy true. we say "COM proxies", because the original instance lives still in the COM server memory(office application) all what you have is a substitute, just a proxy. But you dont have to activate a COM proxy before use(In your scenario, its just an Excel behaviour.
) but you have to make sure to dispose a COM proxy after using because the instance in the office COM server memory lives so long as more >0 registered proxies exists. Its a common problem in the .net world that the office instance not dies after quit and still live in memory because not all proxies are disposed from client caller. VBA and VB6 does this more intelligent and dipose com proxies automaticly for you if a proxy its no longer used.

NO use a special concept to handle this problem, in other words, NO make sure, its impossible to forget proxy release (dispose9 . I suggest you to have a look for the NO tutorials section. specialy the first 3 tutorials about COM proxy management.

*sebastian







.