Question

I've been asked to look into a live client site which currently isn't working. I've been told that an IIS recycle will fix this issue for about 3 months when it will re-appear again. The issue seems to be in a 3rd party CMS but I can't currently provide any debugging information for them to try and reproduce.

That got me wondering if it would be possible to do the following - Put together a simple ASP page with a text editor which can accept arbitrary input. Take the input and compile/execute it in the current App Domain using the Rosyln service and print any output to another text area on a page.

Can anyone give me an indication on if this is achievable? The bits I'm not sure if I can achieve are:

  • Running the Roslyn code in the context of the current page/app domain.
  • Tracing output to the page without turning on global tracing.
Was it helpful?

Solution

When you load a dynamic assembly, by default it loads it into the same AppDomain that you're running in, with Roslyn or not.

However there are some considerations:

  1. You do not need the Roslyn service (which is used by Script Engine), you only need the Roslyn client DLLs if you're just going to build and run the code.
  2. You don't really need Roslyn to compile dynamic code and run it. .NET already has the ability to load, compile and run an arbitrary lump of code. This article is a little old but still valid. Use reflection in your page to load and run the dynamic DLL.
  3. If it is the Roslyn script engine you need, that needs the Roslyn service (to act as a host). The service needs visual studio 2012. As Daniel Mann points out in the comment, that's not licensed for production.
  4. Memory leaks via IIS are often caused by a given thread/request, not by actions on the App Domain (or shared resources). Your dynamic code (be it Roslyn Script Engine or plain old dynamic assembly) will be running outside where the leaks are happening, so I doubt you will see any problems.
  5. This scares me. Running dynamic code straight onto live sounds amazingly dangerous. Protect yourself!

Can you reproduce it locally or on a test machine similar to live? If it only happens over an extended period of time, then you can simulate use using automation like Selenium.

Once you have it reproduced, use something like ANTS Memory Profiler to see where the problems are.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top