I was not able to do something a little more elaborate with my timer job so I decided to check if something basic works. So I tried the code below - but it keeps giving me this error - why?


Error text is: ArgumentOutOfRangeException was unhandled by user code - Specified argument was out of the range of valid values.

enter image description here

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;

namespace AlertAudit
public class AlertMailer : SPJobDefinition    {
    public AlertMailer()
        : base() {

    public AlertMailer(string alertName, SPWebApplication webApplication)
        : base(alertName, webApplication, null, SPJobLockType.ContentDatabase)
        this.Title = "Alert Mailerv1";

    public override void Execute(Guid contentDbId)
        // get a reference to the current site collection's content database
        SPWebApplication webApplication = this.Parent as SPWebApplication;
        SPContentDatabase contentDb = webApplication.ContentDatabases[contentDbId];
        using (SPWeb web = new SPSite("http://myRootSite/").OpenWeb())
            foreach (SPList list in web.Lists)



  • is it possible to post the error message directly as text? for some reason the image is not displaying (unsure - it could be blocked at my end). Ta. Commented May 9, 2012 at 20:52
  • 3
    Console.WriteLine ?? You are writing timer job not a console application!? Commented May 9, 2012 at 21:23
  • you have mentioned that "it keeps giving me this error".. I can't see it (the error image), so if you could type the error message above within your question itself. Commented May 9, 2012 at 21:39
  • thanks for (Update) posting "ArgumentOutOfRangeException" error message. Commented May 10, 2012 at 17:22

1 Answer 1


First - how can you write to console, if you are running timer job and not a console application?

Second - does your list.Title contain anything that looks like {0}? ArgumentOutOfRangeException at Console.WriteLine would mean, that you didn't give enough parameters to format string. This method works exactly like string.Format():

Console.WriteLine("foo {0}, bar {1)", foo, bar);

If you don't give enough parameters, you get this kind of exception.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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