Visual Studio Development Bookmark and Share   
 index > Visual Studio Tools for Office > VSTO not starting in ThisWorkbook.cs
 

VSTO not starting in ThisWorkbook.cs

I'm using Visual Studio 2008. I have a Excel 2003 Workbook application attached to TFS 2005.

I have two branches which run fine. After merging the changes from the two branches, ThisWorkbook_startup is not the first method to execute.

ThisWorkbook.Designer.xml has hostitem:master="true" hostitem:startupIndex="0"
ThisWorkbook.Designer.cs has [Microsoft.VisualStudio.Tools.Applications.Runtime.StartupObjectAttribute(0)]

The sheet that is opening has
LocationDeductiblesSheet.Designer.xml : hostitem:primaryCookie="Sheet5" hostitem:startupIndex="8"
LocationDeductiblesSheet.Designer.cs has [Microsoft.VisualStudio.Tools.Applications.Runtime.StartupObjectAttribute(8)]

The error I am getting is:
Object reference not set to an instance of an object.


************** Exception Text **************
System.NullReferenceException: Object reference not set to an instance of an object.
at RiskDecisioner.LocationDeductiblesSheet.TerritoryMapItem..ctor(LocationDeductiblesSheet sheet, String peril, String territoryName, Int32 excelRow, Int32 selectionColumn, Int32 deductibleColumn) in C:\Projects\UWRiskDecisioner_Release\UWRiskDecisioner_Earthquake\Source\UwDecisioner\RiskDecisioner\LocationDeductiblesSheet.cs:line 45
at RiskDecisioner.LocationDeductiblesSheet.addTerritory(String peril, String territoryName, Int32 excelRow, Int32 selectionColumn, Int32 deductibleColumn) in C:\Projects\UWRiskDecisioner_Release\UWRiskDecisioner_Earthquake\Source\UwDecisioner\RiskDecisioner\LocationDeductiblesSheet.cs:line 110
at RiskDecisioner.LocationDeductiblesSheet.LocationDeductiblesSheet_Startup(Object sender, EventArgs e) in C:\Projects\UWRiskDecisioner_Release\UWRiskDecisioner_Earthquake\Source\UwDecisioner\RiskDecisioner\LocationDeductiblesSheet.cs:line 189
at Microsoft.Office.Tools.Excel.Worksheet.OnStartup()
at RiskDecisioner.LocationDeductiblesSheet.FinishInitialization() in C:\Projects\UWRiskDecisioner_Release\UWRiskDecisioner_Earthquake\Source\UwDecisioner\RiskDecisioner\LocationDeductiblesSheet.Designer.cs:line 269
at Microsoft.VisualStudio.Tools.Applications.Runtime.AppDomainManagerInternal.ExecutePhase(String methodName)
at Microsoft.VisualStudio.Tools.Applications.Runtime.AppDomainManagerInternal.ExecuteCustomizationStartupCode()
at Microsoft.VisualStudio.Tools.Applications.Runtime.AppDomainManagerInternal.ExecuteEntryPointsHelper()
at Microsoft.VisualStudio.Tools.Applications.Runtime.AppDomainManagerInternal.Microsoft.VisualStudio.Tools.Applications.Runtime.IExecuteCustomization2.ExecuteEntryPoints()


************** Loaded Assemblies **************


Any idea how to get the entry point to be ThisWorkbook_startup rather than LocationDeductiblesSheet_StartUp?

RockhillInsurance  Monday, September 28, 2009 10:29 PM
Hi,

Actually, I'm not really any good at TFS.

However, regarding this error, you could try to set breakpoint in your code, and catch possible cause. I guess the variablemay beset tonull, and then the code use thisvariable again. You will see this by debuging your solution in Visual Studio.

Best regards,
Bessie
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
Bessie Zhao  Thursday, October 01, 2009 11:53 AM

We are changing the issue type to "General Discussion" because you have not followed up with the necessary information. If you have more time to look at the issue and provide more information, please feel free to change the issue type back to "Question" by opening the Options list at the top of the post window, and changing the type. If the issue is resolved, we will appreciate it if you can share the solution so that the answer can be found and used by other community members having similar questions.
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
Bessie Zhao  Tuesday, October 06, 2009 6:48 AM
Thank you for the suggestion Bessie.

I have set breakpoints in the code.  The value is indeed null.  However, that is not the problem I'm concerned with.

The problem is the very first line of code executed is in LocationDeductiblesSheet_startup.  If the very first line of code had been in ThisWorkbook_startup, the value would not be null.

My concern is why is the the application not starting in ThisWorkbook_startup as all documentation I've been able to find on the topic of "VSTO Programming" indicates VSTO excel always does.

Any idea what might have caused the application to go against the normal VSTO expectation?
RockhillInsurance  Wednesday, October 14, 2009 2:45 PM

<<I have two branches which run fine.  After merging the changes from the two branches, ThisWorkbook_startup is not the first method to execute.>>
How do you merging two branches? Could you be more specific about this if it is related to this issue?

For entry point of Excel Workbook project, it is as the same as Word document project. When we create a Excel Workbook project in VSTO SE, the project automatically creates four classes named ThisWorkbook, Sheet1, Sheet2, and Sheet3. ThisWorkbook class derives from Microsft.Office.Tools.Excel.Workbook, and it is the first entry point into the Excel object model. And Sheet1 class derive from Microsoft.Office.Tools.Excel.Worksheet, it is the second entry point. Set breakpoint into ThisWorkbook, Sheet1, Sheet2 and Sheet3, and you will see the order of starting up.

Useful link: C# Application object.

Best regards,
Bessie


Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
Bessie Zhao  Thursday, October 15, 2009 3:47 AM

Bessie –

 

In regards to your question about how the merge was done…  I am using Microsoft Team Foundation Server to manage changes made by multiple developers. The structure is as follows:

UWRiskDecisioner\Main\Source\UwDecisioner branched to

UWRiskDecisioner_Production\Source\UwDecisioner branched to

            UWRiskDecisioner_Test\Source\UwDecisioner branched to

                        UWRiskDecisioner_Development\Source\UwDecisioner branched to

                                    UWRiskDecisioner_Release\Source\UwDecisioner branched to

                                                UWRiskDecisioner_Earthquake\Source\UwDecisioner

Changes were made in the UWRiskDecisoner\Main\Source\UwDecisioner branch as well as in the UWRiskDecisioner_Earthquake\Source\UwDecisioner applications.  Both of these applications where working.  Changes from UWRiskDecisioner\Main\Source\UwDecisioner were merged down through the hierarchy of branches into the UWRiskDecisioner_Earthquake\Source\UwDecisioner application.  The merge process is a function of TFS from which I selected “All changes to a specific version” version type “Latest version”.

 

In regards to your explination of how Excel Workbook project works … I agree.  Unfortunately that is not how it is working.  The Excel Workbook project that I am working with has 11 sheets numbered 2 theough 12 (nothing is marked as Sheet1).  Sheet12 has been renamed to WindstormResultsSheet.  Sheet2 has been renamed to DataSheet.  Sheet3 has been renamed to LocationDetailsSheet.  Sheet4 has been renamed to PolicyDetailsSheet.  Sheet5 has been renamed to LocationDeductiblesSheet.  Sheet6 has been renamed to AttritionalPmlDataSheet.  Sheet7 has been renamed to UwRulesSheet. Sheet8 has been renamed to AOPLocationDetailsSheet.  Sheet9 has been renamed to PolicySummarySheet.  Sheet10 has been renamed to AttritionalPmlDataSheetEQ.  Sheet11 has been renamed to EarthquakeResultsSheet.

 

Putting a breakpoint on the first line of the _Startup method of each sheet shows LocationDeductiblesSheet_StartUp as the first line of executed code.

 

Thank you for your help

RockhillInsurance  Friday, October 16, 2009 3:05 PM

You can use google to search for other answers

Custom Search

More Threads

• how can i convert a selection.Text from word to RTF Format
• Is Excel a partial trust caller?
• Outlook add-in prerequisites
• Word VSTO and label
• Deployment a Word Solution with actions pane
• Modify query in Mail Merge in a Word document
• Dreaded "document opened in multiple windows" error
• Outlook 2003 Word as Editor and .NET forms
• Excel to xml conversion -Decimal point problem
• Code Security