Object '/xxxx/xxxx.rem' has been disconnected or does not exist at the server.

Mar 8, 2012 at 2:44 PM
Edited Mar 8, 2012 at 2:46 PM

Using the IsolatedTemplateServices I am randomly finding this exception being thrown.

 

System.Runtime.Remoting.RemotingException

Object '/5d79aa48_fe69_459e_9dbe_3f5ddac771f9/l_lfl70rxb_fcqf7noaihy9b_23.rem' has been disconnected or does not exist at the server.

Server stack trace: 
at System.Runtime.Remoting.Channels.ChannelServices.CheckDisconnectedOrCreateWellKnownObject(IMessage msg)
at System.Runtime.Remoting.Channels.ChannelServices.SyncDispatchMessage(IMessage msg)

Exception rethrown at [0]: 
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at RazorEngine.Templating.ITemplateService.Compile(String razorTemplate, Type modelType, String name)
at RazorEngine.Templating.IsolatedTemplateService.Compile(String razorTemplate, Type modelType, String name)
at MyOffers.Handlers.LandingPageHandler.LoadTemplate(String templateName)
at MyOffers.Handlers.LandingPageHandler.<>c__DisplayClass8.b__6(String s)
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at MyOffers.Handlers.LandingPageHandler.ProcessRequest(HttpContext context)

Summarised code is: 

public static IsolatedTemplateService templateService = new IsolatedTemplateService();

string templateText = File.ReadAllText(templateName);

templateService.Compile(templateText, typeof (PageModel), templateName);

 

 

This happens after leaving the IsolatedTemplateService alone for a period of time. I figured that the appdomain it was using to load the templates had somehow died, however after that creating a new instance of the template service, the exception remains.

In the end I have to reload the app to get it to work again.

 

How can I avoid this? Or atleast, how can i recover the situation if it happens?