Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have written a custom timer job, created a feature, and written a feature receiver to install and uninstall the Timer Job in the web app on Activate/Deactivate. The custom job roughly follows the examples af Andrew Connell here: http://www.andrewconnell.com/blog/articles/CreatingCustomSharePointTimerJobs.aspx.

The Feature is Site-scoped, and not visible. I am doing all of the feature install/uninstall and activate/deactivate via STSADM.exe.

Deployment is fine, and the feature installs, activates, deactivates, and uninstalls smoothly. The Feature event receiver is working correctly: the custom job definition appears and dissappears from the Central Administration -> Operations -> Timer Job Definitions interface when the feature activates and deactivates.

However, when the job itself is executed by the timer process, I get errors in the ULS logs and the System Event log. From the ULS Logs:

10/12/2010 13:10:00.14  OWSTIMER.EXE (0x1CE8)                       0x2DDC  Windows SharePoint Services     Timer                           7psa    Critical    The Execute method of job definition Example.TimerJobs.RequiredTaskMonitorJob (ID 94f5f3ce-ed38-4e27-b15d-1b00a6a143c1) threw an exception. More information is included below.  Value does not fall within the expected range.  
10/12/2010 13:10:00.14  OWSTIMER.EXE (0x1CE8)                       0x2DDC  Windows SharePoint Services     Timer                           72ae    Unexpected  Exception stack trace:    at Microsoft.SharePoint.SPListCollection.GetListByName(String strListName, Boolean bThrowException)     at Microsoft.SharePoint.SPListCollection.get_Item(String strListName)     at Example.TimerJobs.RequiredTaskMonitorJob.Execute(Guid contentDbId)     at Microsoft.SharePoint.Administration.SPTimerJobInvoke.Invoke(TimerJobExecuteData& data, Int32& result)  

Note that this error occurs no matter what the content of the Execute() method is. Originally I was reading in the details of a SPList used for configuration, and creating Task List items when certain conditions were found to be true.

But in the currently-installed version of the Timer Job, the Execute() method is entirely empty. I don't even call the base class's implementation of it. I have no idea where it is trying to call the SPListCollection.get_Item() method; it's certainly not in my code.

Is anyone able to assist with this error?

Thanks for your help,

Darryl.

share|improve this question
    
I should note that this is on a WSS 3.0 installation. –  user1170 Oct 12 '10 at 18:46
add comment

4 Answers

In WSS i made a habit of testing my timer jobs in a test harnes, most often a console application, before deploying the timer job to SharePoint.

This is because it is tedious waiting for jobs to start (this is better in SP2010 where you have RunNow).

To test this code either call your method from a console application, or debug the timer job by setting a breakpoint in your Execute code and attaching OWSTIMER.EXE in Visual Studio.

Read more on debugging timer jobs in an earlier discussion here

share|improve this answer
    
I like to create Cmdlets to invoke my timer jobs –  Steve P Oct 13 '10 at 17:51
    
Thanks Anders. Works great in a console app. So great that I am considering just running it with Windows Task Scheduler. Who needs the heartache of the Timer Job framework? Well, I'm sure lots of people do, but my code payload is local to a single SPWeb on a standalone server, not in a farm or anything, so I don't care about Scope of LockType which TimerJobs help with.... –  user1170 Oct 13 '10 at 21:55
add comment

The Timer Job is trying to find a list - does this work in a brand new web application with an out of the box site collection with no other custom code?

share|improve this answer
    
Thanks James. Yes, deploying to a fresh location caused the error to go away. The code is working in a console app (thanks Anders), and in new deployments of it. But not in the original location. I have deactivated, uninstalled the feature, done an IIS reset and restarted the OWSTIMER service. I think that old code is cached somewhere and causing problems. –  user1170 Oct 13 '10 at 21:52
add comment

You state that your latest version of your code has an empty execute method yet the log file indicates

Example.TimerJobs.RequiredTaskMonitorJob.Execute

Is calling get_Item this suggests that the latest version of your code is not running.

Have you tried restarting the timer service to flush out your old code?

share|improve this answer
    
Hi Steve, I did deactivate the feature, uninstall the feature, uninstall my dlls from the GAC, did an IISRESET, and restarted the timer service. Then I reinstalled my new dlls (with the empty Execute() method), installed the feature, and reactivated the feature. After that I still got the ArgumentException out of SPListCollection.get_item(). Short of rebooting the physical machine, I don't know what else I can do? –  user1170 Oct 18 '10 at 15:26
add comment

Have you changed the AssemblyVersion numbers of your assembly?

This might explain why some old code is hanging around.

You should be able to check the GAC to see how many versions of your Assembly are hanging around.

You can see exactly where your TimeJob was loaded from by attaching the debugger to the OWSTIMER.EXE and switching to the Debug/Modules windows it will list exactly what assemblies are loaded and what path they were loaded from.

share|improve this answer
add comment

Your Answer

 
discard

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