Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8892893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:07:12+00:00 2026-06-14T23:07:12+00:00

I am working on a little app to run some timer jobs in SharePoint.

  • 0

I am working on a little app to run some timer jobs in SharePoint.
Instead of just using a foreach to loop through all the jobs and pick the ones I want, I am attempting to select them by Guid via Linq statements. However, I am not having much luck.
Here is what I have so far:

   foreach (SPService service in centralAdmin.Farm.Services)
{
   var traceJob =
       from jobDefinition in service.JobDefinitions
       where jobDefinition.Id == traceGuid
       select jobDefinition;

   SPJobDefinition jobInfo = traceJob as SPJobDefinition
   Console.WriteLine(jobInfo.DisplayName);
 }

EDIT The error I am receiving is a “NullReferenceException” at Console.WriteLine(jobInfo.DisplayName)

I am sure I have just missed something since this is my first time using LINQ statements, but I have not been able to figure out what I did wrong. I cast traceJob as SPJobDefinition because otherwise I cannot access any of the SPJobDefinition properties off of traceJob. Any tips or pointers would be very much appreciated!

EDIT
the enumeration yields no results when searching for the Guid.
However, if I do the following code:

    foreach (SPJobDefinition jobDefinition in service.JobDefinitions)
    {
     if (jobDefinition.Id == traceGuid)
     {
       jobDefinition.RunNow();
       Console.WriteLine(jobDefinition.DisplayName);
     }
    }

It will pull back exactly what I expect to see- the Job Definition’s display name. This would seem indicate that the issue is not with a faulty Guid or non-existent job.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T23:07:14+00:00Added an answer on June 14, 2026 at 11:07 pm

    The exception you’re getting is because your as operation will always fail, and when an as fails it doesn’t throw an exception, it just returns null. The exception comes from using that null value.

    traceJob shouldn’t need to be cast at all. Using var doesn’t mean it’s actually of a variable type, or even unknown at all. It simply means that the compiler will look at the expression to the right of the = and use that (statically, at compile time) to determine the type of that variable. In this case, hovering over var will show you that it is actually an IEnumerable<SPJobDefinition>. What you have is a sequence of job definitions, not just a single one. You can easily get the first item in the sequence through First, FirstOrDefault, Single, or SingleOrDefault. After doing that you’ll have just one item, and you won’t need to cast it at all.

    var traceJob =
        (from jobDefinition in service.JobDefinitions
        where jobDefinition.Id == traceGuid
        select jobDefinition)
        .SingleOrDefault();
    
    if(traceJob != null)
        Console.WriteLine(traceJob.DisplayName);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just began working on a little twitter-app using tweepy. is there any kind
I'm working on a little WPF app that will run fullscreen and I'd like
I'm working on a little Android app to stream some camera footage (as a
I am working on a little WinForm app and have been trying to find
I've got a nice little web app working that brings down playlists and videos
I have been working on a Windows Mobile app for a little while now
I'm working on a little program to make my life easier when using Microsoft
I'm working on animating little subviews throughout my UI using a flip transition. To
I am working on my first iOS app, and have run in the first
I'm working on a little app to scrape css from a url. Demo it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.