mpapier

I pulled the following from a book on workflows:

private void onCreateTask(object sender, EventArgs e)

{

taskID = Guid.NewGuid();

taskProperties.Title = workflowProperties.Item["Name"].ToString();

taskProperties.AssignedTo = sCSEmail;

}

I continually get the error below. Since we have commented out the other lines for some trial and error, we are fairly certain it caused by taskID = Guid.NewGuid();

09/26/2007 16:34:52.70 w3wp.exe (0x0D48) 0x0570 Windows SharePoint Services Workflow Infrastructure 98d4 Unexpected System.NullReferenceException: Object reference not set to an instance of an object. at UPGFeeDeviation.UPGFeeDeviation.onCreateTask(Object sender, EventArgs e) at System.Workflow.ComponentModel.Activity.RaiseEvent(DependencyProperty dependencyEvent, Object sender, EventArgs e) at System.Workflow.Activities.CallExternalMethodActivity.Execute(ActivityExecutionContext executionContext) at System.Workflow.ComponentModel.ActivityExecutor`1.Execute(T activity, ActivityExecutionContext executionContext) at System.Workflow.ComponentModel.ActivityExecutor`1.Execute(Activity activity, ActivityExecutionContext executionContext) at System.Workflow.ComponentModel.ActivityExecutorOperation.Run(IWorkflowCoreRuntime workflowCoreRuntime) at System.Workflow.Runtime.Scheduler.Run...



Re: SharePoint - Workflow taskID = Guid.NewGuid(); Null Reference Exception?

Paul Galvin

I think it's unlikely that Guid.NewGuid() is causing a null. I think it's more likely that workflowProperties, or worfklowProperties.Item["Name"] is null. Or, the null reference is not in that bit of code.

Guid.NewGuid() is probably called hundreds of time a minute in a living breathing MOSS/WSS environment.






Re: SharePoint - Workflow taskID = Guid.NewGuid(); Null Reference Exception?

Craig Regester

Hi Paul,

Is there any greater way to troubleshoot these things beside looking in the cryptic log files that don't seem to pinpoint where the error is Obviously we (I work with Marc btw) get it to compile in Visual Studio and it installs into SharePoint and the workflow does actually activate because one of our sendemail functions work, but then it dies and the error Marc showed above is all we have to go off of.

I have a hard time believing it is the workflowProperties or workflowProperties.Item["Name"] simply because we are following along with an example in a book. Granted, the book could be wrong but I would hope not. You mention the null reference may not be in that bit of code, but the exception we get refers to onCreateTask - so where else would it be Hence the need for better troubleshooting tools.

Thanks Paul!!

Craig





Re: SharePoint - Workflow taskID = Guid.NewGuid(); Null Reference Exception?

Paul Galvin

I understand your pain Smile It's hard to debug this stuff.

You may be able to attach to the worker process and debug it (after setting break points, etc). This is your best option. I know that some people report having trouble doing that. If you haven't done this before, it may feel a little awkward, but it's worth figuring out.

The class methods work too ... write log entries to an ascii file, create events in event viewer ...

It really can't be the call to NewGuid(). That's a core function in the System namespace. I wouldn't waste time on that one.






Re: SharePoint - Workflow taskID = Guid.NewGuid(); Null Reference Exception?

Nick Cox

Is the Task ID property in the designer bound to the taskID field in your workflow class





Re: SharePoint - Workflow taskID = Guid.NewGuid(); Null Reference Exception?

Craig Regester

When you say Task ID property in designer, are you referring to TaskId, where you have to set the Name (class name) and Path (Variable name) If so, yes, we have this set to our class name and the taskID variable for the onTaskChanged objet, updateTask object, createTask object and completeTask object.




Re: SharePoint - Workflow taskID = Guid.NewGuid(); Null Reference Exception?

Craig Regester

I added some code in to write a single line at the beginning and end (and sometimes in the middle) of each code segment to a file called C:\sp.txt.

For example, in the onWorkflowActivated, it writes out "Beginning of onWorkActivated" and, at the end of that sub, writes "End of onWorkActivated".

Using this method, I was able to determine that in the onCreateTask, it successfully got past taskID = Guid.NewGuid(); but errored out on

Code Block
taskProperties.Title = workflowProperties.Item["Name"].ToString();

Note that it will error out whether or not I pull from workflowProperties or if I simply force a string "Test" to the taskProperties.Title property.... so obviously something is wrong with taskProperties, but looking at the design view and code, I sure can't figure out what at this poitn. Time for more pondering...

If anyone has a thought, that would be great. I'm sure it's something simply obvious...





Re: SharePoint - Workflow taskID = Guid.NewGuid(); Null Reference Exception?

Paul Galvin

I know that in other contexts, if I try to refer to SP data that is blank (i.e. appears blank in a list view), it's actually stored as a null in the data. I would make sure that "Name" has a real value.

I'd also make sure that "Name" is the actual name of the property. It's case sensitive and maybe you reallyo want to refer to Title

There is also the chance that workflowProperties itself is null, or workflowProperties["Name"] is null.

Since you're writing to the log file, you can iterate through the Item collection and display the name of all the items that are in that workflowProperties collection.

If you can get the remote debugging to work, then you may be able see that kind of stuff right from the debugger.






Re: SharePoint - Workflow taskID = Guid.NewGuid(); Null Reference Exception?

Craig Regester

The solution to this problem, in case any others are interested, is that taskProperties, afterProperties and beforeProperties were not created/initialized properly by Visual Studio's GUI for creating this objects (which is how they were created when we followed along in the book we have).

To create them manually, we used:

Code Block

public SPWorkflowTaskProperties taskProperties = new SPWorkflowTaskProperties();

public SPWorkflowTaskProperties afterProperties = new SPWorkflowTaskProperties();

public SPWorkflowTaskProperties beforeProperties = new SPWorkflowTaskProperties();

And then assigned them to the task Objects in the Design view. You could even see their icon was different when assigning them than the objects that existed before.

This resolved the issue.