Type is not marked as serializable in custom sequential workflow

Hi,

I have a SP 2010 project, which has a class file, which I have used for custom logging.

In my another solution, I have 2 projects. First project has a visual webpart, and in that i have referenced the logger project dll and used in my try catch block.

Second project is a sequential workflow. In that also, I refrenece the logger project dll and used in my try catch block.

The logging is working in my visual webpart, however is throwing error in the workflow project. I am getting the below error:

"Type 'Test.CustomLogs.ErrorLogger' in Assembly 'Test.CustomLogs, Version=1.0.0.0, Culture=neutral, PublicKeyToken=guid' is not marked as serializable."

How to fix this?

Thanks

July 8th, 2013 4:33am

You need apply the [SerializableAttribute] to your logging class and ensure any of it's properties are serializable.

Have a look at this MSDN attribute: http://msdn.microsoft.com/en-us/library/system.serializableattribute(v=vs.90).aspx

And this blog post: http://sharepoint.microsoft.com/blog/Pages/BlogPost.aspx?pID=861

Free Windows Admin Tool Kit Click here and download it now
July 8th, 2013 5:26am

HI,

Thanks for the reply.

I tried like this:

 [Serializable]
    public class ErrorLogger
    {
              public void UpdateErrortoLog(string  string methodName, string errorMessage, string timeStamp)
        {   
                          SPSecurity.RunWithElevatedPrivileges(delegate()
                 {
using (SPSite oSite = new SPSite(SPContext.Current.Site.Url))
 {
using (SPWeb oWeb = oSite.RootWeb)
{
 oWeb.AllowUnsafeUpdates = true;

Now, when the line hits SPContext.Current.Site.Url, I am getting "Object reference not set error". Before using the serializable attribute, i was not getting the error.

Thanks

July 8th, 2013 5:57am

The class needs to be serializable in case the workflow is interrupted, causing the current state to be serialized so it can be saved to the database.

In the case of a workflow, you can't (I'm pretty sure) use SPContext, because the workflow is running under the system account (in the owstimer process).

For the logging class, you're probably better off passing in an SPWeb object as a parameter.

Free Windows Admin Tool Kit Click here and download it now
July 8th, 2013 6:32am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics