Skip to content

System.Runtime.Serialization.SerializationException when call IsolatedRazorEngineService.Create() #601

@cysnet

Description

@cysnet

This error occurs if I use CallContext.LogicalSetData before method IsolatedRazorEngineService.Create() and set an entity that is not marked [Serializable].

here is a demo to produce this error.

using RazorEngine.Templating;
using System.Runtime.Remoting.Messaging;

namespace WorkerRole
{
    public class User
    {
        public string Name { get; set; }
    }
    internal class Program
    {
        static void Main(string[] args)
        {
            var user = new User();
            CallContext.LogicalSetData("123", user);
            using (var service = IsolatedRazorEngineService.Create())
            {
            }
        }
    }
}

error is

System.Runtime.Serialization.SerializationException: 'Type 'WorkerRole.User' in assembly 'WorkerRole, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions