المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : How to dynamically use C# 3.5 compiler



C# Programming
09-24-2009, 11:01 AM
For several months I've used dynamic compiler in my app that mounted a dll on start-up. But today I came across a painful problem. The code that can be compiled trouble-free in vc#08 has syntax errors according to the 'dynamic' compiler (let me call it dynamic for distinction).

The piece of code in mind looks like this:


void foo()
{
//...
ActorDescription actorDesc = new ActorDescription()
{
BodyDescription = new BodyDescription(70)
};
//...
}


The dynamic compiler shows an error : "error CS1002: ; expected". After simple test I managed to find out that the dynamic compiler probably aims at an older framework and I'm trying to use newer syntax features.

In shortcut, what I was using is this:


System.CodeDom.Compiler.CodeDomProvider cdp =
System.CodeDom.Compiler.CodeDomProvider.CreateProvider("CSharp");
System.CodeDom.Compiler.CompilerResults cr = cdp.CompileAssemblyFromFile(parameters, fullPaths);


The functions above are contained by System.dll v2.0 library, so it's not surprising it won't work. Anyway, System.dll v3.5 doesn't exist. Where is the new set of methods to compile according to the newest c# specification? What's the workaround for this? I've been googling for a few hours with no answer.

Thanks in advance! http://www.barakasoft.com/script/Forums/Images/smiley_smile.gif