Debugging SSIS Script task - Breakpoint is enabled but it does not hit - debugging

I am working on an SSIS package. The package has a script (C# language) task. I need to debug the script task. I set the break point. The script in script editor (Visual Studio) and the task in SSIS package editor, both, show break point in red color - means the break point is enabled. However, when I debug the package the break point does not hit.
The break point has no conditions on it, so I expect it to hit every time the package runs.
I am using Visual Studio 2008 on Windows 2003 R2 64-bit SP2.

After more research and trial-error, found that the SSIS package ignores the breakpoints in a Script Task when debugging on a 64-bit machine. To fix it -
Go to the Solution Explorer
Right click your SSIS project node > Properties
In Configuration Properties > Debugging > Debug Options > Set Run64BitRunTime to False.
After making this change, the breakpoints hit like magic.

I tried all the answers provided here with no success (using VS2015). After some more searching I found this question that is actually an answer which stated that newer C# features / syntax were causing the debugger to not fire correctly.
In their example (and also mine) using string interpolation was causing the breakpoints to not be hit.
Replacing
$"{someVariable} - {someOtherVariable}"
with
string.Format("{0} - {1}", someVariable, someOtherVariable);
did the trick for me.
EDIT
It appears this issue has now been fixed with SQL Server Integration Services Projects, but you need to be running VS2019 to download it.

Update: Guys, I againg lost any ability to set breakpoints (a request to MS)
My previous fixes are below.
Now I'm using logging and tracing instead of debugging.
C# new features (after C# 4.0) are blamed for killing debugging of the SSIS Script Task.
To return the breakpoint capability I do the following.
Remove C# new features
Run my Script Task once, successfully. I.e. without a crash.
Reopen the Vsta Project from my Script Task and put breakpoints there.
At the end, you have to see a red circle on your Script Task.
(Tested in VS 2017.)
Note. I have to mention that debugging works even if your use "Execute Task" only, not "Execute Package"!
Remove C# new features
To remove the C# new features, I can advise you two ways.
First, restrict Vsta Project properties to C# 4.0 (migrated packages may not support this).
Dobule click your "Script Task" to open "Script Task Editor".
Click "Edit Script..." button to open Visual Studio.
In "Solution Explorer" select the project and click the F4 key on your keyboard.
In opened "Properties" window in "C# Language Level" choise "C# 4.0"
Build your project and fix compilation errors.
Secondly, Vsta Projects in old/migrated packages may not show the above "C# Language Level" property.
So you can put your code in a fake project in Visual Studio 2010 and compile it there.
Run it once successfully
After you fix your C#, you have to run your Script Task once successfully.
You may want to put the return statement at the beginning of the Main() method to prevent any real execution.
Sorry, this doesn't always work and I don't realise why but you definitely need to fix your C# in the first place.
At least you will get a working Script Task and can debug it in an old fashioned way (logs by Dts.Events..., exceptions, etc.)
TL;DR
It looks like I even got severe cases when C# new features forced Script Tasks to fail silently with a success completion status.
As an example, add the following to your Script task.
string Bug { get; } // Only getter properties.
//...
var str = $"Now is {DateTime.Now}"; // String Interpolation in C#
//...
var dummy = val?.ToUpper(); // ?. and ?[] null-conditional Operators
And workarounds for this non-complete list:
string Bug { get; set; }
//...
var str = string.Format("Now is {0}", DateTime.Now);
// etc.
What I also do, I build my C# code in Visual Studio 2010. It simply doesn't compile the new .NET features and do not allows .NET Framework versions above 4.0. So far, so good.
Of course, other answers from this SO-question didn't help me.

In my case, none of these solutions worked. I finally got to know that the Resharper was culprit. After uninstalling it, it started working like charm.

In my case, I had to get rid of all features from C# 6: string interpolation, null conditional operators (?., ?(), ?[]) and expression-bodied members (=>) (there might be more in your case). You can check them all here. Of course, the same applies to C# 7 features.
The 32/64 bit changes from other answers didn't help, so I rolled back those and the debugging kept working just fine.

Use System.Diagnostics.Debugger class to add breakpoint programmatically:
System.Diagnostics.Debugger.Launch();
System.Diagnostics.Debugger.Break();
You can check if the debugger is attached or not:
if (System.Diagnostics.Debugger.IsAttached)
System.Diagnostics.Debugger.Break();
Follow these step:
Keep your project or solution opened.
Run your app to hit breakpoint.
Select your project in Just-In-Time Debugger.

I inherited an SSIS package where unfortunately the above answers didn't help.
In the end I found the script task's build properties for debug mode had had the optimize code ticked. Make sure this isn't ticked because for me visual studio would fire up for script debugging and close shortly after without breaking at all.
Pretty obscure but worth a mention.

We hit the same problem recently. For us the solution was to ensure that the script task project was marked to run as with the platform target set to x86.
Edit the script task
Click on the project and select properties
Select to set the platform target to x86

In addition to Jeff's suggestion, also change the Platform Target to "x86" (In the script's properties' Build tab. This FINALLY got me debugging again on a 64-bit system.

Microsoft released an update v3.2 of SQL Server Integration Services Projects where it resolves the issue with Roslyn and other C# language features introduced after .Net 4.5. C# features.
Bad news - this fix is for Visual Studio 2019 only, you have to upgrade your VS to use it.

I spent whole day on this and NONE of the solutions mentioned here worked for me.
In my case, the existing project was targeted to SQL Server 2016 which defaults ScriptLanguage Microsoft Visual c# 2015. This doesn't allow debugging in VS 2019. I have to target project to SQL Server 2019 to make debugging work. Of course, I am not going to checkin version change. It's only to debug script. Once script is working, I am going to revert target version to SQL server 2016.
Hope this saves time for someone.

I had the same problem as you #PAS. Using VS 2019 and Target server version 2016.
Just found out that if upgrading SSIS in Visual Studio (going into Extensions->Manage Extensions) to latest version (which now is 3.15) debugging is now working.

My breakpoints refused to hit no matter what I did. I ended up debugging and fixing the issues just using exception throws. Once I had fixed the issues I was having, the breakpoints started hitting!
So my breakpoints would only hit once the code did not experience any runtime issues... which is bizarre.

In my experience, it doesn't matter:
if Run64BitRuntime is true or false
if you build the 32 or 64 bits version of your package
But there is something very important, not mentioned in any other answer: you must run the whole package. If you run a Task or a Container the breakpoint will be ignored.
I'm using Visual Studio 2013, on a 64 bits machine.

I only had one Script component were no breakpoints were hit (I was doing some CRM stuff without needing source/target).
I trid to add a Source componenet with a simple fetchXML (even if I didn't needed it).
Then it worked! :-)

I found out that by copying a Script Component task, the VSTA project as a whole is copied as well. This is what you would expect, but what I did not expect is with that, the assembly name for example is also copied.
Running then Execute Task works fine, but running the whole package actually only runs the first script that was copied and resulted in exceptions being thrown before ever hitting the row processing function.
That was also the reason for me that breakpoints were not being hit.

Related

Automatically attaching to support behavior not completely successful

I have a Visual Studio 2010 solution containing several C# projects, with Resharper 5.1 installed and enabled. All these projects target the .NET Framework 4.
This solution has been working fine for months, but this morning I got the following message when the solution was loaded:
I've looked around for an explanation on the meaning of this message, but with little luck.
Additionally, I haven't been able to repro this error, and it doesn't seem to have broken anything on my project.
Still, I don't like these kind of unexplained errors, so I was wondering if anyone reading this knows the root cause?
Hmm, that's special. It must be a debugger notification, the part of VS that 'attaches' and makes "Managed" a category. The other category is "Unmanaged", a different kind of debugger interface. It clearly lost its marbles there.
Counter-measures, in order, are:
Restart VS.
Reboot
Install Service Pack 1, it has many debugger fixes.
Consider moving 3 up the list if you haven't installed it yet, there are a ton of bug fixes and tweaks and works well.
In Visual Studio 2012 and Windows 8.1, I had this problem,I changed X86 from Solution Properties/Build/Platform target then my problem resolved.
This has been nagging me for a while. Finally I found a solution.
When I press the help button they suggest I sort out the attached debug option. Without any result I finally managed to check the Enable SQL Server Debugging option under Project Properties - Debug.
I have the exact same setting as you: VS2010 with several C# projects pointing to Net 4 and Resharper 5.1. I'm on Windows XP SP3
I was getting the exact same error, along with an empty VS icon in the taskbar.
The empty icon got away when I shifted VS to my main monitor (I have 2) and restarted. It seems that VS doesn't like to be in the second monitor.
As for your error, I cleaned up the Resharper cache (I'm storing it in the TEMP folder, not the solution folder) restarted, and didn't get the error again
In Debug Menu - GoTo Solution Properties and select debug tab and tick the ENABLE SQL SERVER DEBUGGING checkbox

Not hitting breakpoints attached to NUnit

I'm using the latest NUnit, 2.5.9, on Windows 7 64-bit, Visual Studio 2010 Premium, and the projects are .Net 3.5.
The problem is that I attach to NUnit (there is NOT an nunit-agent appearing), and symbols are loading, but my break points aren't being hit. There is no error indicator next to the breakpoint indicating something is wrong.
The first run seems to take some time to start the test, but subsequent runs after that seem to complete almost instantly. I assume because StructureMap (required for the objects i'm testing) has already done its thing and doesn't need to repeat that setup.
Any ideas on how to fix this?
I sort of figured out the answer. I reset all of my settings to the standard Visual C# Development Settings and debugging suddenly works again.
I'm not sure which setting got everything back on the right track; I didn't see a "disable debugging while debugging setting."

A project with output type of class library cannot be started directly - with a startup exe

Firstly I'm completely aware of this message and why it happens normally. It's not that I'm just trying to run a dll (like this question).
I have a project that compiles to a dll but has a startup program specified in the project properties. Most of the time I'm able to right-click on the project and select Debug > Start new instance, and it will run the program and let me debug my dll. However, occasionally I get this message (A project with output type of class library cannot be started directly) as if I haven't got a startup program. The first few times I thought it was just me accidentally clicking on the wrong project but I'm certain this isn't the case given that it's happened so many times and I've been careful to watch it.
When this message appears I'm able to try it again and it always works on the second or third attempt.
A colleague using the same Solution never has this problem :-/
Anyone else had this problem or know how to solve it?
I'm using Visual Studio 2005 Pro Version 8.0.50727.762 (SP.050727-7600)
Edit: Also happens with Visual Studio 2010
Another colleague suggested it's because after clicking Debug > Start new instance, while I'm waiting for it to start up, I click on a different project. I don't do it for any reason, just randomly selecting things as I wait for the project to start up. Maybe Visual Studio looks at the selected project sometime after I clicked the menu, gets confused, and shows the error message?
Anyone able to confirm this matches their experience?
Typically problems in VS are caused by:
Add-ins: Run VS without and see if the problems is solved
Corrupted files in your solution: Delete / rename all files created by Visual Studio which are not part of your project, i.e. all .suo, .ncb files and a like.
I had this problem with projects that were created as "Windows Control Library" that somehow forget their status. Unloading and reloading the project usually did the trick.
If it was created as a "Class Library" then to make it a "Windows Control Library" I manually add the following to the .csproj file. It was the only difference I could see between a class library and windows control library project.
BTW - starting a Windows Control Library starts the User Control Test Container - allows you to test any user control in the library. Very cool.
<Service Include="{94E38DFF-614B-4cbd-B67C-F211BB35CE8B}" />
add that inside of an <itemgroup> element.
If you plan to use/create/add extra dll's or just have more than one project in your solution, you may get this kind of problem, especially if you forgot a simple rule:
1. In your "Solution Explorer" window. Right click and chose "Set StartUp Projects..."
2. Under "Start Up Project" select and change "Single startup project" to your working entity.
no just make a start up project
Going to resurrect this thread, I have just been experiencing similar issues, when right clicking a project and start new instance..
So instead of right clicking the project and selecting start new instance, I right clicked and clicked set as startup project.
Low and behold a class library project was set to bold, certainly not the one I was right clicking.
I tried selecting a different executable project and setting that as the startup project. Same class library was highlighted as the start up project.
Realised that the current open file was from that project, possibly all the open files were from that project...
closed all open files and tried again.... Problem solved, behaviour as expected for both set as start up project and start new instance options...
Definitely a bug, hope this helps others..
Microsoft Visual Studio 2010 Version 10.0.40219.1 SP1Rel
Microsoft .NET Framework Version 4.0.30319 SP1Rel
This sounds like a transient Visual Studio problem. Reinstallation or upgrade may solve your problem.
I've seen this as well, and it seems like a bug in VS. It happens after you right-click/build a class library (that requires rebuilding), and then right-click/debug > start new instance.
edit- It's still very intermittent, I can't seem reproduce it reliably
I've found that I've had the Startup Project on the Solution set to Current selection, then at some point, I've unloaded a project, and the solution has reverted to Single startup project on a project that happens to be a class library.

Visual Studio integrated custom MSBuild task behaviour

I was looking around the net for a NUnit custom MSBuild task that would run on every build and also nicely play with Visual Studio UI (2008 is my version). I found MSBuild.Community.Tasks project that was great, but failed in Visual Studio integration part.
What I actually wanted to have is get failed tests displayed as warnings/errors in VS's error list window (and also FAILED project build when tests are not successful). So I wrote my own custom MSBuild task that does the job exactly how I wanted it to be.
BUT.
The only problem that I have is that normal VS UI error list behaviour is that when you click on an error it jumps to appropriate source file and highlights the problematic code. I was able to relate file and line number with failed test however I wasn't able in any way to persuade Visual Studio to HIGHLIGHT problematic code for me (when I double click the error). All I get is cursor in the right spot.
I tried all kinds of combinations of line, endLine, column, endColumn method parameters (Log.LogError()), but to no avail. And based on error output by compiler errors it looks like it also provides just line and column (no end values).
Anybody ran against this oddity and solved it?
Update 13 May 2009
You can get this project for free (without method selection) at
http://code.google.com/p/nunitmsbuildvsintegrated/
For this feature, you must create Visual Studio Integrated Package that display custom panel in Visual Studio. This custom panel will be called when your project is built.
Visual Studio Extensibility Developer Center
I have no solution to your exact problem, but have some thoughts.
Are you sure you want to run a full suite of unit tests at the end of each and every build? I personally find it to be a productivity killer. Rather, while working with code I tend to run a small subset tests which cover only the code in question, and this is where tools like ReSharper or TestDriven.NET come into play.
(source: jetbrains.com)

Is there a free Visual Studio addin for Nunit?

I'm cheap and don't want to pay for ReSharper or TestDriven.NET, is there a free visual Studio addin for NUnit?
You can create a blank project (Choose console application for example) and in the property of the project you can select DEBUG tag and select "Start External Program". Put the path of Nunit. Then, in the start option, the command line arguments select the DLL that contains all your tests (mine is always in the nunit\bin...). Then select "enable unmanaged code debugging" and you will be able to start the project inside VS and even use the debugger step-by-step.
This is a free solution.
Now you can use Gallio: it's open source. www.gallio.org
By the way TestDriven can be downloaded for free if it's for personal use or Open Source project.
I had to find a way to use .Net Reflector inside VS few days ago and when I downloaded TestDriven it cames with. Never got any popup asking me to paid.
NUnit actually ships with a basic integrated runner. It's not very good, and not very publicized, but unless Charlie has taken it out, it should be in the source.
I know this is an old question but another way to do this is to add an external tool from the tools menu to run nunit - set the arguments to be $(TargetName)$(TargetExt) and initial directory to $(ProjectDir)\bin\Debug
check out this link
This is an old question and things have changed since the answer was accepted.
You may try NCrunch to run tests automatically or manually.
If you're running Visual Studio 2012, there is a plugin written by Charlie Poole, one of the NUnit contributers, that makes use of the new Visual Studio Unit testing plugins.
Download VsTestAdapater - it's also in the extension manager.
Unfortunately it doesn't have much grouping options yet, either by run/not run - so you can't group by class, solution and so on. It also doesn't show you any stacktrace if a test fails, just a simple green tick or red box and a message.
I haven't used it, but NUnitit is a free Visual Studio Add-in for NUnit.
http://nunitit.codeplex.com
From my experience, the best add-in for visual studio is resharper. TestDriven.Net is also good for unit tests. Hope that helps
Also found this one : http://visualstudiogallery.msdn.microsoft.com/c8164c71-0836-4471-80ce-633383031099
It is able to launch your tests in debugger, however you need to recompile the code manually each time you change something - no auto run-build integration

Resources