Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>After fiddling around with AppDomains, I've found out that Ninject has nothing to do with this.</p> <p><strong>(an extensive explanation follows, solution/workaround is at the end of the answer)</strong></p> <p>Ninject creates seperate <code>AppDomain</code> in <code>AssemblyNameRetriever</code> to retrieve assembly names. In my case, those assemblies are Ninject extensions:</p> <pre><code>private static AppDomain CreateTemporaryAppDomain() { return AppDomain.CreateDomain( "NinjectModuleLoader", AppDomain.CurrentDomain.Evidence, AppDomain.CurrentDomain.SetupInformation); } </code></pre> <p>The problem lies with the object <code>AppDomainSetup</code> stored in <code>AppDomain.CurrentDomain.SetupInformation</code> property. It has <code>ActivationArguments</code> property set to instance of <code>ActivationArguments</code> class, which contains information that causes entry assembly to execute (which is fine, since XBAP application has to start somehow).</p> <p>However, since Ninject uses same setup information, this causes infinite recursion and thus our favorite <strong>StackOverflow</strong> exception.</p> <p>The workaround is to set property <code>ActivationArguments</code> to <code>null</code>. However, <code>AppDomain</code> class creates a copy of <code>AppDomainSetup</code> object in <code>SetupInformation</code> property getter. Thus it is necessary to get a copy of <code>AppDomainSetup</code> object, set <code>ActivationArguments</code> to <code>null</code> and via <strong>reflection</strong> set value <code>_FusionStore</code> field of <code>AppDomain</code> class to this object.</p> <p><strong>TL;DR</strong>: Before creating Ninject kernel, we have to invoke this code:</p> <pre><code>var setupInformation = AppDomain.CurrentDomain.SetupInformation; setupInformation.ActivationArguments = null; var field = typeof(AppDomain).GetField("_FusionStore", BindingFlags.Instance | BindingFlags.NonPublic); field.SetValue(AppDomain.CurrentDomain, setupInformation); </code></pre> <p>No idea if this will cause any issues later. Thus far, I believe this code requires full trust, because it accesses private field (and sets its value).</p>
    singulars
    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.
    1. This table or related slice is empty.
    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