RE: C#: Excel unable to debug - code runs fine when sheet is simpl

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Found the solution at the post below. Problem is when both 1.1 and 2.0
frameworks are installed, have to explicitly tell debugger to use 1.1.

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=304240&SiteID=1


"ExitMachine" wrote:

Sorry, forgot to mention - VS 2003, Excel 2003, XP SP2.

"ExitMachine" wrote:

Have a very simple C# Excel worksheet project I've created to try and
diagnose. Class has one event handler setup for a CommandButton. Command
button simply puts some text into cell A1

Builds fine, when I open sheet from the file system, click the button, text
is output - great.

Have a breakpoint in the button click event handler. Debug -> Start, Excel
opens very briefly (about 1 sec), closes, debugging ends. Cannot get the
breakpoint to hit.

After this, when I try to open the sheet from the file system, get message
"The document 'TestDebug.xls' caused a serious error the last time it was
opened." and the doc gets set to disabled. Can get it re-enabled

Perhaps I am missing something, or maybe Excel VSTO projects don't support
debug stops at breakpoints. I've copied the code from my file below - have
removed comments and left out the "Generated initialization code" section.

Thanks very much.

---------------------------------------------------

using System;
using System.Windows.Forms;
using Office = Microsoft.Office.Core;
using Excel = Microsoft.Office.Interop.Excel;
using MSForms = Microsoft.Vbe.Interop.Forms;

// Office integration attribute. Identifies the startup class for the
workbook. Do not modify.
[assembly:System.ComponentModel.DescriptionAttribute("OfficeStartupClass,
Version=1.0, Class=ExcelTest.OfficeCodeBehind")]

namespace ExcelTest
{
public class OfficeCodeBehind
{
internal Excel.Application ThisApplication
{
get { return thisApplication;}
}

internal Excel.Workbook ThisWorkbook
{
get { return thisWorkbook;}
}

private Excel.Application thisApplication = null;
private Excel.Workbook thisWorkbook = null;

private Excel.WorkbookEvents_OpenEventHandler openEvent;
private Excel.WorkbookEvents_BeforeCloseEventHandler beforeCloseEvent;

protected void ThisWorkbook_Open()
{
MSForms.CommandButton testButton = (MSForms.CommandButton)
this.FindControl( "testButton" );
testButton.Click += new MSForms.CommandButtonEvents_ClickEventHandler(
testButton_Click );
}

protected void ThisWorkbook_BeforeClose(ref bool Cancel)
{
Cancel = false;
}

private void testButton_Click()
{
Excel.Worksheet sheet = (Excel.Worksheet)
ThisApplication.Sheets.get_Item( 1 );
Excel.Range rng = sheet.get_Range ( "A1", "A1" );

rng.Value2 = "Test Debug";
}
}
}

.



Relevant Pages

  • Dropdown in webpart lost its state after postback
    ... I am trying to develop Sharepoint 2k3 webPart for ... private TextBox txt1 = null; ... TableCell c00 = new TableCell; ... protected void dajPodatke1 ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)
  • Re: Beginner - basic inheritance problem -- public/protected
    ... Consider Protected almost as if it was Private. ... Could someone please explain to me why the "protected void ... they are in the same class, that the ddlCategory object would be ... public void Page_Load ...
    (microsoft.public.dotnet.languages.csharp)
  • RE: Block the debugger from seeing values of variables
    ... modify and change arbitrary memory, change registers, play with data structures, etc. ... be to attach an unmanaged debugger to your process and look at the memory space, where they could very easily read your private variables. ... A 3rd party will be ...
    (microsoft.public.dotnet.security)
  • RE: date time difference
    ... protected void Page_Load(object sender, EventArgs e) ... private System.Data.DataTable GetData ... in second column I have to show ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: date time difference
    ... protected void Page_Load(object sender, EventArgs e) ... private System.Data.DataTable GetData ... from tbtickets tck inner join tbticketsmessages tckmsg ...
    (microsoft.public.dotnet.framework.aspnet)