Compiler executable file csc.exe cannot be found.

373 views
Skip to first unread message

mark

unread,
Apr 25, 2012, 1:58:48 PM4/25/12
to CS-Script
I have a .NET service application which is a WCF Web Service. When my
program calls CSScript.Compile I get an exception that says, "Compiler
executable file csc.exe cannot be found." However, this works fine
when I run under the WCF Service Host (WcfSvcHost). Any ideas or
suggestions?
Thanks,
Mark

Oleg Shilo

unread,
Apr 25, 2012, 9:06:02 PM4/25/12
to cs-s...@googlegroups.com

Hello Mark,

Thank you for your interest in CS-Script.

You probably realize that the problem is caused by the CLR (not CS-Script)  not being able to load MS C# compiler csc.exe

In your case I think the CLR somehow is failing to locate the correct version csc.exe. One of the possible reasons is that when you host your services on IIS they may be configured to use an older version of runtime and as the result csc.exe cannot be found.

If you exhaust all options you can load csc.exe by yourself instead of relying on the CS-Script engine, which always tries to load the csc.exe of the CLR the engine was compiled against.   
  
I have attached the sample demonstrating the loading the actual CLR compiler by the host application. You may try the approach but in your case you will need not VB.NET (VBCodeProvider) but C# compiler.
 
Regards,
Oleg Shilo
--------------------------------------------------------------------------------------------
Internet: http://www.csscript.net
E-Mail: csscript...@gmail.com
You can register for e-mail notification on CS-Script updates: Add to mailing list

Oleg Shilo
--------------------------------------------------------------------------------------------
Internet: http://www.csscript.net
E-Mail: csscript...@gmail.com
NonC#CompilerInHostApp.cs

mark....@gmail.com

unread,
Apr 26, 2012, 7:34:30 AM4/26/12
to cs-s...@googlegroups.com
Hi Oleg,

Thank you for the response. I do like CS-Script very much.

I am not hosting under IIS. It fails when I am hosting the web service in a Windows service application where I have a class derived from ServiceBase. It is confusing to me that it works with the MS WCF testing tool.

I think I will first try to compile your code for debugging and see if I can step into it to see what is happening. If I cannot figure it out then I will try your proposed solution. I am not sure how to translate this line:

return new Microsoft.VisualBasic.VBCodeProvider().CreateCompiler();

to get the c# compiler.

I will post any progress that I make.

Mark

mark....@gmail.com

unread,
Apr 26, 2012, 8:19:31 AM4/26/12
to cs-s...@googlegroups.com
Hi Oleg,

I have some more information from debugging.

In the LoadCompiler method I see the class options. The value of options.altCompiler is "C:\Users\Mark.CANARY\Desktop\cs-script\Lib\CSSCodeProvider.dll". Of course, this assembly cannot be loaded into my application because my application is .NET 3.5 and this assembly is 4.0. This is the location that I first ran cs-script. It is not the location that I am referencing the csscript library in my project. Strangely, when I run under the hosting environment that works, opctions.altCompiler is the same value but somehow the assembly loads. Another interesting point is that options.TargetFramework is "v4.0" in both cases.

One final point is that I am trying to compile my script into an assembly to be loaded into a new AppDomain.

Can you tell me the best way to fix this?

Thanks,
Mark

mark....@gmail.com

unread,
Apr 26, 2012, 2:13:12 PM4/26/12
to cs-s...@googlegroups.com
I ran uninstall.cmd from the cs-script folder to display the cs-script explorer functionality and that seems to have resolved the problem. It seems that there is some conflict.

Regards,
Mark

On Wednesday, April 25, 2012 1:58:48 PM UTC-4, mark wrote:

Oleg Shilo

unread,
Apr 26, 2012, 8:51:46 PM4/26/12
to cs-s...@googlegroups.com
I am glad you solved it. 

Regarding loading the compiler, consult MSDN for this. From my memory it is:
new Microsoft.CSharp.CSharpCodeProvider().CreateCompiler(); 
Reply all
Reply to author
Forward
0 new messages