1

I installed a feature to my production environment but now it is throwing the following error:

The Execute method of job definition SharePointSocialNetworking.Facebook (ID 528d61e4-95b6-4766-bb98-4363da570506) threw an exception. More information is included below. Object reference not set to an instance of an object.

Exception stack trace: at SharePointSocialNetworking.Facebook.Execute(Guid targetInstanceId) at Microsoft.SharePoint.Administration.SPTimerJobInvoke.Invoke(TimerJobExecuteData& data, Int32& result)

My problem is that my stack trace stops just as it's getting useful... I need to know WHERE in the Execute method it is erroring out (maybe even a line number). They are just giving me enough info to have a general idea of what the problem is but not where it is happening...

Is there anywhere to get a FULL stack trace or to track down exactly where my "Object reference not set to an instance of an object." error is occurring?

In my "Diagnostic Logging" section in the central admin I have "Least critical even to report to the event log" set to "Error" and "Least critical event to report to the trace log" set to "Verbose".

This is for a timer-job.

Abe Miessler
  • 82,532
  • 99
  • 305
  • 486

2 Answers2

1

Because your pdbs dont get packaged and deployed, you cant get line numbers from your exceptions

How can I include line numbers in a stack trace without a pdb?

But i get around it by building a 'message' as a process happens, you know where the error occurs because of the value in the 'message'.

All my sharepoint jobs are structured similar to this:

public class CustomJob : SPJobDefinition {
    public override void Execute() {
        try {
            WriteTrace("CustomJob.Execute:");
            Process();
            WriteTrace("CustomJob.Execute[end]");
        } catch (Exception ex) {
            WriteTrace(string.Format("CustomJob.Execute\nException: {0}", ex));
        }
    }
    public void Process() {
        string message = "CustomJob.Process\n";
        try {
            //do something
            message += "value1: " + value1 + "\n";
            //do something
            message += "value2: " + value2 + "\n";
            //do something
            message += "value3: " + value3 + "\n";
        } catch (Exception ex) {
            WriteTrace(string.Format("CustomJob.Process\nException: {0}", ex));
        }
        WriteTrace(message);
    }
    private void WriteTrace(string message) {
        //configure how you need, either write to ULS or write to event log
        SPDiagnosticsService.Local.WriteTrace(0, 
            new SPDiagnosticsCategory("My Category", 
            TraceSeverity.Unexpected, 
            EventSeverity.Error), 
            TraceSeverity.Unexpected, message, ex.StackTrace);
    }
}

This allows me to trace most errors fairly accurately in development and production

EDIT

There are ways to write to the trace logs in 2007 (more complicated sure)

http://weblogs.asp.net/erobillard/archive/2008/07/31/sharepoint-trace-logs-and-the-unified-logging-service-uls.aspx

http://msdn.microsoft.com/en-us/library/aa979522%28v=office.12%29.aspx

http://weblogs.asp.net/gunnarpeipman/archive/2009/02/25/sharepoint-writing-messages-to-uls-unified-logging-system.aspx

But i just wrote straight to the event log:

        EventLog el1 = new EventLog();
        el1.Source = "My Custom Source";
        el1.WriteEntry(message, EventLogEntryType.Information);
Community
  • 1
  • 1
djeeg
  • 6,685
  • 3
  • 25
  • 28
0

If its your custom timer job, Why don't you debug it interactively by attaching to owstimer.exe. See debugging timer jobs:

http://msdn.microsoft.com/en-us/library/ff798310.aspx

Regarding your trace question, you can log StackTrace property of Exception object string to the Trace log as indicated by other posts.

Madhur Ahuja
  • 22,211
  • 14
  • 71
  • 124