Antaris / RazorEngine

Open source templating engine based on Microsoft's Razor parsing engine
http://antaris.github.io/RazorEngine
Other
2.14k stars 577 forks source link

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

Open cysnet opened 6 months ago

cysnet commented 6 months ago

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.'
cysnet commented 6 months ago

this issue similar with https://github.com/Antaris/RazorEngine/issues/324