Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remoting error due to GC issues when using App Domain #28

Open
gdodd1977 opened this issue Sep 11, 2018 · 5 comments
Open

Remoting error due to GC issues when using App Domain #28

gdodd1977 opened this issue Sep 11, 2018 · 5 comments

Comments

@gdodd1977
Copy link

I'm getting the following error:

System.Runtime.Remoting.RemotingException: Object ‘/76e7cd41_2cd2_4e89_9c03_fae752ec4d59

/zb_uualy_cm6kwizjlentfdl_3.rem’ has been disconnected or does not exist at the server.

It appears to be due to GC issues when using an App Domain. I see where you have a virtual method on the RazorBaseHostContainer called InitializeLifetimeService(). But the Xml Doc seems to indicate that how you have it should keep it alive indefinitely. We are not finding that to be the case.

Any thoughts on this?

@RickStrahl
Copy link
Owner

If you use AppDomains any objects you use have to be either [Serializable] or inherit from MarshalByRefObject otherwise you'll get remoting errors as the objects won;t be able to pass over the AppDomain boundaries.

@gdodd1977
Copy link
Author

Everything we are using is Serializable. In the past, when we weren't, we got exceptions thrown.

@RickStrahl
Copy link
Owner

RickStrahl commented Sep 13, 2018

There's an option ThrowExceptions to turn on the exception behavior. By default this value is false and exception are handled and return an error message instead.

Serializable exceptions can occur even if your top level object is serializable, but one of your subobjects isn't. For example, if you have a DateTimeOffset it may break because that class isn't serializable. Or if you have any other non-serializable child objects.

You can dig into the exception and the stacktrace to hopefully find out exactly which object is failing to serialize either in the parameter list or the return value.

@qlayer
Copy link

qlayer commented Sep 21, 2018

@RickStrahl
This was the stack we've got when we got the exception:

   at Westwind.RazorHosting.RazorEngineConfiguration.get_CompileToMemory()
   at Westwind.RazorHosting.RazorEngine`1.CompileTemplate(TextReader templateReader, String generatedNamespace, String generatedClassName) in Westwind.RazorHosting\Core\RazorEngine.cs:line 550
   at Westwind.RazorHosting.RazorEngine`1.CompileTemplate(String templateText, String generatedNamespace, String generatedClassName) in Westwind.RazorHosting\Core\RazorEngine.cs:line 602  

I think the problem comes from RazorEngineConfiguration : MarshalByRefObject it does not override InitializeLifetimeService method.

@RickStrahl
Copy link
Owner

RickStrahl commented Dec 27, 2018

Hmmm... maybe RazorEngineConfiguration should just be [Serializable] instead of MarshalByRefObject. There seems to be no good reason for that to be MarshalByRefObject, since it's just a state object. Making the change I don't see any adverse behavior, but it's been so long I don't recall whether there was an explicit reason to use MarshalByRefObject.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants