[ExcelDna] Debugging and settting breakpoint in visual studio

4,825 views
Skip to first unread message

BoringAccountant

unread,
Apr 30, 2010, 3:35:32 PM4/30/10
to ExcelDna
Hi, Im' wondering if anyone has any tips for me concerning an issue
where I can't debug an ExcelDNA project I'm working on. The
envrionment is VB.NET 2010 Express (or C#, it hasn't made a
difference.) I've tried this in Excel 2007 and Excel 2010. For
reference, I used the excellent post "Excel DNA Tutorial"
http://groups.google.com/group/exceldna/browse_thread/thread/96a7b7bccdfdd84a
as a step-by step document for creating and exposing a function in
Excel using ExcelDNA. I also reviewed the documentation and another
post on here about setting up breakpoints in VS2005.
http://groups.google.com/group/exceldna/browse_thread/thread/df6ae8af64889bd8/7698c33e143890b5?lnk=gst&q=breakpoints#7698c33e143890b5

The VS2005 article is a bit old and I'm not sure how relevant it is to
my situation. Does anyone have any updated information on setting up
debugging in VS (2008 or later?)

--
You received this message because you are subscribed to the Google Groups "ExcelDna" group.
To post to this group, send email to exce...@googlegroups.com.
To unsubscribe from this group, send email to exceldna+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/exceldna?hl=en.

Govert van Drimmelen

unread,
May 2, 2010, 3:03:48 AM5/2/10
to ExcelDna
Hi,

Since ExcelDna currently works with the .Net 2.0 runtime, you need
change some settings to make debugging work under Visual Studio 2010.
The problem is that VS2010 does not know which version of the runtime
it will be debugging since excel.exe is an unmanaged executable. It
therefore prepares to debug .Net 4, and your ExcelDna add-in runnimg
under .Net 2.0 is never attached to by the debugger.

The easiest way to tell the debugger that you will be debugging .Net
2.0 is to add an excel.exe.config file with a supportedRuntime entry
next to your Excel.exe executable. The file should contain:
<?xml version ="1.0"?>
<configuration>
<startup>
<supportedRuntime version="v2.0.50727" />
</startup>
</configuration>
Note that this file is not needed when you redistribute your add-in -
it is just for the debugger while you are developing.

Another way to get the right debugger running, if you are only
debugging managed code, is to right-click on your solution, select
'New Project' and then pick the excel.exe executable as your
'project'. This allows you to set Excel as the start-up project for
your solution, and in the properties page to set which debugger to use
- here you should pick Managed (.Net 2.0, 3.0, 3.5). F5 then starts
Excel with the right managed debugger attached. I'm not sure you are
able to do this in the Express editions.

A third way to get the debugger attached is to put a Debug.Fail
statement in your code, then run Excel from the Start menu, and attach
to your running Visual Studio when the assertion is hit. Here you can
also select exactly which debuggers (native, managed or both) to use.

I have tried all of these options successfully under VS2010
Professional.

If you need to debug both native code and managed code, the first
option seems best. There is also a Microsoft Connect issue filed as
Connect ID 554067 - entitled "Cannot debug .NET 2.0/3.0/3.5 code using
F5 in mixed mode from native c++ projects or c# project with 'start
external program' set to native .exe". -
https://connect.microsoft.com/VisualStudio/feedback/details/554067/cannot-debug-net-2-0-3-0-3-5-code-using-f5-in-mixed-mode-from-native-c-projects-or-c-project-with-start-external-program-set-to-native-exe

Please let us know if this does not work for you in the Express
editions.

Regards,
Govert




On Apr 30, 9:35 pm, BoringAccountant <jbl...@hotmail.com> wrote:
> Hi, Im' wondering if anyone has any tips for me concerning an issue
> where I can't debug an ExcelDNA project I'm working on. The
> envrionment is VB.NET 2010 Express (or C#, it hasn't made a
> difference.) I've tried this in Excel 2007 and Excel 2010. For
> reference, I used the excellent post "Excel DNA Tutorial"http://groups.google.com/group/exceldna/browse_thread/thread/96a7b7bc...
> as a step-by step document for creating and exposing a function in
> Excel using ExcelDNA. I also reviewed the documentation and another
> post on here about setting up breakpoints in VS2005.http://groups.google.com/group/exceldna/browse_thread/thread/df6ae8af...

BoringAccountant

unread,
May 2, 2010, 2:59:57 PM5/2/10
to ExcelDna
Thanks for an excellent post, this was the magic piece that I was
missing. The Excel.exe.config works great.

When it comes to visual studio express, the tricky part is getting the
debugger to start external program/attach to process. In the express
editions, this is not provided in the UI, BUT it is still available if
you know how to write the user config XML for your project. This is
normally the file right next to your visual studio project file, not
your solution. You can replace the contents of one from a professional
or standard edition and it works great. Here is an example.

From my test project user file MyFirstUDF.vbproj.user
(<ProjectName>.<ProjectTypeExtension>.user):

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|
AnyCPU' ">
<StartAction>Program</StartAction>
<StartProgram>C:\Program Files\Microsoft Office
\Office12\EXCEL.EXE</StartProgram>
<EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' ==
'Release|AnyCPU' ">
<StartAction>Program</StartAction>
<StartProgram>C:\Program Files\Microsoft Office
\OFFICE11\EXCEL.EXE</StartProgram>
<EnableSQLServerDebugging>false</EnableSQLServerDebugging>
</PropertyGroup>
<PropertyGroup>
<ProjectView>ShowAllFiles</ProjectView>
</PropertyGroup>
</Project>

Pretty sweet, I can't take credit for it, one of our senior developers
figured it out.

Zhenyu Lu

unread,
Aug 23, 2012, 10:53:07 PM8/23/12
to exce...@googlegroups.com
Hi, first of all, I would like to thank you for the great post. What I would like to ask is will the configuration of the proj.user file work for the project with the output type as library? I've tried the configuration, it always remind me that can not start a project with the library as output. Do you have any suggestions or examples on how to apply this proj.user setting file? Thanks again.

Patrick O'Beirne

unread,
Aug 24, 2012, 3:58:48 AM8/24/12
to exce...@googlegroups.com

In VS Express you include this in the .vbproj file so F5 will launch the debugger:

 

<?xml version="1.0" encoding="utf-8"?>

<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">

<StartAction>Program</StartAction>

<StartProgram>C:\Program Files\Microsoft Office\Office14\EXCEL.EXE</StartProgram>

<StartArguments>MY_ADDIN_GOES_HERE.XLL</StartArguments>

</PropertyGroup>

 

<PropertyGroup>

<ProjectView>ShowAllFiles</ProjectView>

</PropertyGroup>

</Project>


On 24/08/2012 03:53, Zhenyu Lu wrote:

Zhenyu Lu

unread,
Aug 24, 2012, 9:43:56 AM8/24/12
to exce...@googlegroups.com
Hi Patrick,
 
It works like magic. Thanks a lot.
I have another question to ask: there is an error raised after I set up using your following proj user file. The first time I launched the project, Excel started with a messagebox showing that I need to disable the start up .xll. After the .xll file was disabled, I could not load the ribbons from the .xll file through Excel AddIn options anymore. Do you have a clue for this?
Thanks a lot again,
 
Zhenyu

2012/8/24 Patrick O'Beirne <obeir...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "Excel-DNA" group.
To post to this group, send email to exce...@googlegroups.com.
To unsubscribe from this group, send email to exceldna+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/exceldna?hl=en.



--
Zhenyu Lu
SUNY-ESF

Naju Mancheril

unread,
Aug 24, 2012, 9:43:13 AM8/24/12
to exce...@googlegroups.com
Hi,

You may also find this post useful.

https://groups.google.com/forum/?fromgroups=#!searchin/exceldna/naju$20cycle/exceldna/stk7Ll6Ya70/YI125Fwne5QJ

It covers debugging addin code and also debugging ExcelDna.

Zhenyu Lu

unread,
Aug 24, 2012, 9:57:26 AM8/24/12
to exce...@googlegroups.com
Awesome. Thank you so much,

2012/8/24 Naju Mancheril <naju.ma...@gmail.com>


--
You received this message because you are subscribed to the Google Groups "Excel-DNA" group.

To post to this group, send email to exce...@googlegroups.com.
To unsubscribe from this group, send email to exceldna+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/exceldna?hl=en.



--
Zhenyu Lu
SUNY-ESF

Patrick O'Beirne

unread,
Aug 24, 2012, 1:38:42 PM8/24/12
to exce...@googlegroups.com
Don't disable it :-)
Go into Options, Excel-addins, click Manage disabled items, re-enable ribbonhelper (I think it's called)

Zhenyu Lu

unread,
Aug 25, 2012, 11:14:41 AM8/25/12
to exce...@googlegroups.com
Hi Group,
 
I just had a very weird issue. I was debugging my ExcelDNA add-in, I closed the debugging. Then after I re-open the excel, I could not see any of the add-in ribbons any more including the ribbons which worked well before. Am I corrupting some default settings or have any of you met the same issue before? I'm using Excel 2007 and Visual Studio 2008. Much appreciated.

Patrick O'Beirne

unread,
Aug 26, 2012, 4:22:02 AM8/26/12
to exce...@googlegroups.com
So, when you Go into Options, Excel-addins, click Manage disabled items,
what item is disabled?
If it's the "ribbonhelper" item, re-enable it and don't disable the next time Excel  gets alarmed.


On 25/08/2012 16:14, Zhenyu Lu wrote:

Zhenyu Lu

unread,
Aug 26, 2012, 10:32:01 AM8/26/12
to exce...@googlegroups.com
Hi Patrick,
 
I got it figured out as you suggested. I missed the several other items in the combo box for the Add-ins manage panel.
Thank you so much for your help and time,
 
Zhenyu 

2012/8/26 Patrick O'Beirne <obeir...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "Excel-DNA" group.
To post to this group, send email to exce...@googlegroups.com.
To unsubscribe from this group, send email to exceldna+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/exceldna?hl=en.



--
Zhenyu Lu
SUNY-ESF

Duyet Le

unread,
Jul 16, 2021, 11:57:52 PM7/16/21
to Excel-DNA
Hi everyone,
I have got the same problem that I could not debug in VSTO 2019. I have followed the informations of this group.
Anyone has solution for this.

Thanks,

Duyet Le

ExcelDNA1.jpgExcelDNA2.jpgExcelDNA3.jpg

Govert van Drimmelen

unread,
Jul 17, 2021, 7:33:17 AM7/17/21
to Excel-DNA
--------------------------------------------------
Excel-DNA is now registered on GitHub Sponsors.
You can add Excel-DNA support with easy billing through a corporate GitHub account.
--------------------------------------------------

I suggest you try the following to get the debugging working:

1. Rename or delete the Excel.exe.config file.
2. Make sure your project is rebuilt in Visual Studio and runs correctly - in particular make sure you are editing the project that is loaded (make a small test function or some other change, so that you can see it is not an old add-in being loaded.
3. Put a breakpoint on your function. 
4. Close and restart Excel directly (not from Visual Studio with the debugger).
5. In Visual Studio, go to Debug -> Attach to Process...
6. Select the EXCEL.EXE process in the list 
7. In the middle of the dialog where it says "Attach To: " go to Select and pick "Debug these code types", and then select only "Managed (.NET4.x)" from the list.
7. Press "OK", then "Attach".
8. Now go to Excel and File -> Open and navigate to your Debug directory, then pick your .xll to open (not the -packed one, just the -AddIn.xll or -AddIn64.xll file.
9. Now run your function and check that the breakpoint is hit.
10. Once you've done this and it works, you can stop debugging and then run the debug project normally - it should work from there on.

I don't know where Visual Studio keeps these Debug settings, but they seem to be sticky.

-Govert

Kamiel Vandewoude

unread,
Dec 24, 2021, 2:45:00 AM12/24/21
to Excel-DNA
Hello Govert,

I have the same problem. When I want to debug, it doesn't hit any breakpoints. I then followed your steps, but when i add a dummy function and run my solution, it opens excel as it should, but the new function is not there, so it's still running an old version somehow. Do you have an idea what could be going wrong here?
Thanks in advance!

Op zaterdag 17 juli 2021 om 13:33:17 UTC+2 schreef gov...@icon.co.za:

Govert van Drimmelen

unread,
Dec 24, 2021, 2:58:02 AM12/24/21
to exce...@googlegroups.com
Check that your function is a " public static " function in a public class.

-Govert

To unsubscribe from this group and stop receiving emails from it, send an email to exceldna+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/exceldna/7d9cefde-6b46-4861-b3c7-007002fb52f7n%40googlegroups.com.

Kamiel Vandewoude

unread,
Dec 24, 2021, 3:23:28 AM12/24/21
to Excel-DNA
Thanks for the quick reply!
The class is public and my function is public static. I couldn't run my myAddIn64.xll because McAffee automatically removes it, so i'm using the myAddIn64-Packed.xll instead, maybe it has something to do with that?
Thanks in advance!

Op vrijdag 24 december 2021 om 08:58:02 UTC+1 schreef gov...@icon.co.za:

Govert van Drimmelen

unread,
Dec 24, 2021, 5:00:02 AM12/24/21
to exce...@googlegroups.com

Yes – I think your add-in won’t work if the anti-virus is blocking it.

Have you been able to report the false positive to McAfee?

Have they replied with any response?

 

-Govert

Kamiel Vandewoude

unread,
Dec 24, 2021, 5:38:33 AM12/24/21
to Excel-DNA
I have reported it, but no response yet!

Op vrijdag 24 december 2021 om 11:00:02 UTC+1 schreef Govert van Drimmelen:

Kamiel Vandewoude

unread,
Dec 27, 2021, 3:19:30 AM12/27/21
to Excel-DNA
When i rebuild or run my solution it opens excel, but the xll files doesn't seem to update, it keeps opening an previous version somehow. I changed it so that it opens the packed xll, as i don't have an 64.xll file anymore due to AV, but when i run my addin AV doesn't interupt anymore, so i don't really understand why it doesn't update when i change my code en rebuild or run it. 
Thanks in advance!

Op vrijdag 24 december 2021 om 11:38:33 UTC+1 schreef Kamiel Vandewoude:
Reply all
Reply to author
Forward
0 new messages