Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8843079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:07:38+00:00 2026-06-14T11:07:38+00:00

Say I have a string of code as below that I compile in my

  • 0

Say I have a string of code as below that I compile in my main project. But I want to implement an interface in the CustomClass. The interface is located in another project in my solution (part of the references in my main project) When I do this

public class CustomClass : InterfaceType

I get an error like this. How can I reference the other project so that I canmake use of the interface and other classes that are part of it, within my dynamic code?

c:\Users\xxx\AppData\Local\Temp\m8ed4ow-.0.cs(1,32: error CS0246: The type or namespace name ‘InterfaceType’ could not be found (are you missing a using directive or an assembly reference?)

string code2 =
"    public class CustomClass : InterfaceType " +
"    {" +
"    }";
        // Compiler and CompilerParameters
        CSharpCodeProvider codeProvider = new CSharpCodeProvider();

        CompilerParameters compParameters = new CompilerParameters();
        compParameters.GenerateInMemory = false; //default
        //compParameters.TempFiles = new TempFileCollection(Environment.GetEnvironmentVariable("TEMP"), true);
        compParameters.IncludeDebugInformation = true;
        //compParameters.TempFiles.KeepFiles = true;
        compParameters.ReferencedAssemblies.Add("System.dll");

        CodeDomProvider compiler = CSharpCodeProvider.CreateProvider("CSharp");

        // Compile the code
        CompilerResults res = codeProvider.CompileAssemblyFromSource(compParameters, code2);

        // Check the compiler results for errors
        StringWriter sw = new StringWriter();
        foreach (CompilerError ce in res.Errors)
        {
            if (ce.IsWarning) continue;
            sw.WriteLine("{0}({1},{2}: error {3}: {4}", ce.FileName, ce.Line,     ce.Column, ce.ErrorNumber, ce.ErrorText);
        }

        string error = sw.ToString();
        sw.Close();

        // Create a new instance of the class 'CustomClass'
        object myClass = res.CompiledAssembly.CreateInstance("CustomClass");
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T11:07:39+00:00Added an answer on June 14, 2026 at 11:07 am

    The bottom line is that you need to add the other project to your CompilerParameters.ReferencedAssemblies collection. This can be tricky, because CodeDOM needs to be able to get to the assembly and thus the assembly either needs to be in the GAC or you need to add a full path to the assembly to the ReferencedAssemblies location.

    One easy way to do this, if you are referencing the project that contains “InterfaceType” in the project that is executing the CodeDOM compiler, is to do something like this: compilerParameters.ReferencedAssemblies.Add(typeof(InterfaceType).Assembly.Location);. If not, you’ll have to figure out some other method for making sure CodeDOM can find the assembly you want to reference.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let us say we have some code that looks like below: @interface SomeClass :
Say, I have a code snippet like this: public static void main(String[] args) {
Let's say I have a bean like below. class Customer{ private String code; private
Let's say I have a string like this. Dim str As String = code
Say I have the following code: class Parent { static string MyField = ParentField;
Lets say I have this code: public void MyMethod(string Data, List<string> InputData) { //I
Say i have a string that i need to evaluate in javascript such as
Lets say we have the following code: #include <iostream> #include <string> struct A {
Let's say I have a variable that will always be a string. Now take
Let's say I have a CString variable carrying the string Bob Evans. I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.