SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have create a timer job and deployed in SharePoint 2013. Debugging worked fine couple of times.

After retract and redeploy couple of times. Now while attaching to OWSTIMER getting below error.

enter image description here

After attachment it gives this error at break point and break point never reaches.

enter image description here

share|improve this question

You must perform a reset on sptimerv4 between retractions in order to unload the GAC'ed custom developed binaries.

share|improve this answer
    
I am doing manual restart OWSTIMER on every deployment. – James123 Jan 8 at 19:39

Since the question does not provide much debugging information, I will try to provide some common solutions based on my personal experience and the few hints I can get from your context.

Option 1
Seem something you may get when the executing code is not up to date with your Visual Studio environment. I suggest that you try and restart the OWSTIMER process manually, since it is very common for it to be "stuck" using an old cached version of the actual dll.

If you can, I suggest you install the CKS-Dev extension, it provides some contextual menus inside Visual Studio to manage common SharePoint related task, and this includes restarting most of the SharePoint related services (restart IIS, recycle app pools, restart the OWSTIMER one and so on).


Option 2
I notice that the code is under an #if DEBUG directive. While I think this may be pretty obvious, try to double check and confirm that you haven't by change switched to release mode without noticing (or some co-worker did that, I seem to recall that the compilation mode is a setting that gets saved to source control).


Option 3
Sometime Visual Studio can trigger a bug - the dll in the GAC gets "locked" by the visual studio instance process. If that is the case, just restarting Visual Studio does the trick. Back in the VS2010 days it wasn't uncommon either for the debugging service to crash either (usually that would trigger an error window, but non always) - this was also most of the time fixed by a Visual Studio restart.


Some other ideas:
I had multiple times see the error message "the following break point cannot be set" get triggered even when the break points were actually working. If that is the case, you should be safe ignoring it. Also, deleting all the break points from the Visual Studio debug menu can fix this bug.

Also worth a try, if everything else fails, is trying to trigger the execution to stop with the System.Diagnostic.Debugger.Break() method (Debugger.Launch() may work too). And if possible try to add some sort of feedback that may ensure you that the updated code is actually running - a simple log to uls line with a number message you increment at each attempt may be enough.

share|improve this answer
    
I am doing manual restart OWSTIMER on every deployment. – James123 Jan 8 at 19:39
    
I have added some more options, see if anything helps @James123. Also, I may be able to provide more ideas if you can give us some more details. These above are only some of the most common scenarios I can think of. – SPArchaeologist Jan 8 at 19:59
    
more likes to Option 3 or Caching dll issue. I don't how to deal with caching dll by timer. Even I delete dll from GAC and added again still not work. I rebooted machine and restarted couple of times VS. Funny thing is it works some times. – James123 Jan 8 at 20:10

I have gotten to the point now that I actually don't allow VS to push my solutions out any more. Instead I do a publish to my file system and then create a script that retracts the old solution, resets IIS and SPTimerv4 and then pushes the new solution out all via PowerShell.

Run Uninstall-SPSolution

then Remove-SPSolution

perform the IIS and SPTimer reset

Then run Add-SPSolution

and finally Install-SPSolution

From there I manually connect to the w3wp instance and to OWSTIMER instance from visual studio.

I will be the first one to admit this is a lot of steps, but I have had less issues debugging code doing this and ended up saving time then using VS to do it for me.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.