Note that there are some explanatory texts on larger screens.

plurals
  1. POList, load and instantiate unknown classes in App_Code at run-time
    primarykey
    data
    text
    <p>I want to load and instantiate classes located in my App_Code folder at run-time.</p> <p>The classes implements <code>IModule</code>:</p> <pre><code>public interface IModule { String Test(); } </code></pre> <p>A test class:</p> <pre><code>// ~/App_Code/Test.cs namespace ModuleManagementSystem { class Test : IModule { public String Test() { return "Testing! One, two, thee!"; } } } </code></pre> <p>The class-files are uploaded by the system users and acts as modules.</p> <p>The class-name of the modules will always be the same as the module filename. <br /> <br /> <br /> I am looking for functioning example-code.</p> <p>I will place a bounty as soon as I am able to. <br /> <br /> <br /></p> <h2><strong>Update:</strong></h2> <p><br /></p> <pre><code>namespace ModuleManagementSystem { public sealed class Compile { public void ToDLL(String sourcefile, String outputfile) { var compilerResults = CodeDomProvider.CreateProvider("CSharp").CompileAssemblyFromFile( new CompilerParameters { OutputAssembly = outputfile, GenerateInMemory = false, TreatWarningsAsErrors = false, GenerateExecutable = false, }, sourcefile ); } } } </code></pre> <p>The above works fine for:</p> <pre><code>// ~/App_Code/Test.cs public class Test { // ... } </code></pre> <p>But if I implement my <code>IModule</code> interface:</p> <pre><code>namespace ModuleManagementSystem { public interface IModule { String HelloWorld(); } } </code></pre> <p>I get the following error:</p> <blockquote> <p>{c:\inetpub\wwwroot\ModuleManagementSystemWeb\App_Code\Test.cs(4,21) : error CS0246: The type or namespace name 'ModuleManagementSystem' could not be found (are you missing a using directive or an assembly reference?)} System.CodeDom.Compiler.CompilerError</p> </blockquote> <p>Both the <code>IModule</code> interface and <code>Compile</code> class is located in the same class library, which is referenced from a web application:</p> <p><a href="http://roosteronacid.com/ModuleManagementSystem.jpg" rel="nofollow noreferrer">http://roosteronacid.com/ModuleManagementSystem.jpg</a></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.
 

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