c# - CSharpCodeProvider does not see the Stack<T> class under System.Collections.Generic -


i'm building pseudocode translator , compiler. translates pseudocode code performing several string operations, uses csharpcodeprovider class compile it, , tries run it.

after few tests, in case translated/output code following:

using system; using system.collections.generic;  public class translatedprogram {     public static void readline(ref int destiny)     {         destiny = int.parse(console.readline());     }     public static void insertinstack(ref stack<int> originalstack, int value)     {         console.writeline("inserting value " + value + " stack.");         originalstack.push(value);         foreach (int current in originalstack)         {             console.writeline("|" + current);         }         console.writeline("_______");     }     public static void main()     {         int value = new int();         stack<int> data = new stack<int>();         readline(ref value);         insertinstack(ref data, value);     } } 

when application sends code csharpcodeprovider, doesn't compile. in compilerresults, following error: "the type or namespace name 'stack' not found (are missing using directive or assembly reference?)" (cs0246)

but when put code, is, inside new project vs ide, works perfectly.

any guess?

thanks.

edit:

i'm calling csharpcodeprovider compiler vb doing following:

private sub compilebutton_click(sender object, e eventargs) handles compilebutton.click         if applicationsavefiledialog.showdialog = windows.forms.dialogresult.ok             dim compiler new microsoft.csharp.csharpcodeprovider             dim results system.codedom.compiler.compilerresults             results = compiler.compileassemblyfromsource(new codedom.compiler.compilerparameters {.generateexecutable = true, .outputassembly = applicationsavefiledialog.filename}, codetextbox.text)             if results.errors.count = 0                 shell(applicationsavefiledialog.filename)             else                 each exception system.codedom.compiler.compilererror in results.errors                     exceptionstextbox.appendtext(exception.errortext)                 next             end if         end if     end sub 

how include reference system.dll?

make sure that, when compile, have reference dll holds stack<>, system.dll.

you can add reference using property referencedassemblies of compilerparameters class:

compilerparameters cp = new compilerparameters(); cp.referencedassemblies.add("system.dll"); csharpcodeprovider provider = new csharpcodeprovider(); compilerresults cr = provider.compileassemblyfromfile(cp, "myfile.cs"); 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -