Note that there are some explanatory texts on larger screens.

plurals
  1. POUnable to load a generic type into another AppDomain in ASP.NET Application
    primarykey
    data
    text
    <p>I have a very odd problem where I am unable to load a generic type into another AppDomain when running inside of ASP.NET, but it works in my Test project and a Console app.</p> <p>The relevant code does essentially this:</p> <pre><code>Assembly ass = Assembly.GetExecutingAssembly(); string AssemblyPath = ass.Location; var templateType = typeof(RazorEngine&lt;RazorTemplateBase&gt;); object instance = LocalAppDomain.CreateInstanceFrom(AssemblyPath, templateType.FullName) .Unwrap(); </code></pre> <p>The code bombs on the last line. The AppDomain exists and its base execution and bin paths are matched to the original AppDomain.</p> <p>When running through this code in a test project, it works fine. The instance is created (as a TransparentProxy remoting reference) and all is well.</p> <p>When running in ASP.NET I get a type error on the generic type parameter:</p> <blockquote> <p>GenericArguments[0], 'Westwind.RazorHosting.RazorTemplateBase', on 'Westwind.RazorHosting.RazorEngine`1[TBaseTemplateType]' violates the constraint of type 'TBaseTemplateType'.</p> </blockquote> <p>where TBaseTemplateType is the same type passed in (ie. RazorTemplateBase) with RazorEngine defined like this:</p> <pre><code>public class RazorEngine&lt;TBaseTemplateType&gt; : MarshalByRefObject where TBaseTemplateType : RazorTemplateBase </code></pre> <p>Clearly I'm passing the right type since it is the actual restraining type, but somehow the AppDomain is not recognizing the Generic type as the same.</p> <p>As I mentioned it works inside of a Windows application and a test project, but inside of ASP.NET the generic type won't instantiate across AppDomain boundaries. Using the same code to create a non-generic type (even the same non-generic version of this type RazorHosting that inherits from RazorHosting) and it works fine.</p> <p>Stumped. What could ASP.NET be doing to make this behave so differently than when running in a test project?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload