|
|
Comments and Discussions
|
|
 |
|

|
I found a bug when running css_config.exe, at first time configuration. I'm under Windows Seven. I unpacked the archive in my download directory, after unblocking its content. I ran css_config.exe, then I exit it clicking Close button, choosing No when the dialog asked me to save or not the configuration. I move the folder in my Program File, then ran again the css_config.exe which throw an ApplicationException : Cannot use alternative compiler...
You can reproduce the same exception by renaming or moving the installation folder then running again css_config.exe.
To solve it, I unpacked again the .zip, then ran again css_config.exe which this time was able to give me a normal message explaining me that a previous installation already exists somewhere else, giving me the ability to replace it.
Nice work, keep up !
Cheers.
|
|
|
|

|
Thank you for letting me know.
I tested it and indeed the recovery algorithm is not as comprehensive as one would want.
While the error message gives some ideas on how to fix the problem "adjusting CSSCRIPT_DIR Env Var" but it is confusing and even misleading nevertheless.
There are two problems:
1 - The error notification is inadequate.
2 - The script engine should be more proactive and try to make a repairing decision on behalf user when it is appropriate (when old installation does not exist any more).
The fixes will be available with the next release (most likely next week).
If you want to be notified on the releases please click the "add to mailing list" on the user feedback page:http://www.csscript.net/Feedback.html[^]
And for the quicker response please report the problems through "report bug" on the same page.
Thank you again for the info.
Cheers,
Oleg
|
|
|
|
|

|
Microsoft script engine handle vbscript and jscript languages in a com technology way.
Can this engine be handle in visual c++ applications...
Can you publish a sample of how to do this???
Mauricio Alfaro
|
|
|
|

|
Hi malfaro,
Yes CS-Script engine can be hosted in the unmanaged applications through callable wrappers. I have no ready to go example but you can google for it "how to call managed code from unmanaged application". CS-Script assembly is signed so you will have no problems hosting it.
I can tell you more. CS-Script is commercially used for one of the CAD add-ins. This add-in is an unmanaged application, which hosts CLR based CS-Script engine. Unfortunately I am not at liberty to name this product.
Cheers,
Oleg
|
|
|
|

|
Hello,
I'm trying to run CSScript under SharePoint, and I'm getting the "Failed to grant permission to execute" error - I'm guessing it's because SharePoint only allows assemblies that are written in web.config etc.
Any ideas how to deal with this?
Thanks!
|
|
|
|

|
Hi Jaromir,
I am no expert in SharePoint configuration. Thus it is hard for me to give you an educated advise.
However your problem can be related to the assembly locking issue when the latest Windows versions (Win7 and Server2008) do not treat downloaded assemblies as "tratsted".
Have a look at section #28 (http://www.csscript.net/FAQ.html#_winServ2008[^]). May be it is the solution.
Cheers,
Oleg
|
|
|
|

|
Thanks for quick answer
However, that wasn't the issue.
AFAIK in order to run in SharePoint, the generated assemblies would have to be strongly named (PublicKeyToken), and probably also located in SharePoint's Program Files/.../14/Bin
Would this be possible?
Thanks
|
|
|
|

|
Hi Jaromir,
Actually CSScriptLibrary.dll is a strongly named assembly (make sure you are using the uptodate release). But it does not make any difference until you register it with GAC. And as far as GAC concerns the actual location of the assembly does not make any difference.
Cheers
|
|
|
|

|
Yep, CSScriptLibrary.dll is, I've got it referenced in my SharePoint project and I'm able to use it. However, the assemblies it generates are not, and I couldn't find a way to change the output directory. So I was asking whether it would be possible to somehow sign the temporary assemblies a store them in a chosen directory. I can imagine then I could persuade SharePoint to load them.
Thanks
|
|
|
|

|
OK. I see your point.
Signing of the temp assemblies is indeed possible. There are a few options for available:
1. The simplest way is to specify the key file for signing the script as a "compiler option" when loading the script. Note that it is an optional parameter for the MS C# compiler (csc.exe), which the script engine just passes through. Have a look at the code sample E:\cs-script\Samples\Hosting\ConditionalCompilation.cs. This should work though I have never tried it.
2. CS-Script allows post-processing of the freshly compiled script before its execution. CS-Script comes with the example for the aspect injection (AOP) with PostSharp. This is where you will find the details: http://www.csscript.net/help/scriptPostProcessing.html[^].
You can run some sort of relinking utility/routine which would sign the assembly during linking. Th approach is very similar to the way PostSharp does the injection.
---------------------------------------
The approach #1 is the simplest and cleanest. #2 is rather exotic but it may be the way if #1 is not working for what ever reason.
I still beleive that the location of the assembly is irrelevant but you can specify where CS-Script should create the temporary assembly when you call CSScript.Load() or CSScript.Compile().
|
|
|
|
|

|
thanks for your great work
|
|
|
|

|
Not a problem. I am glad you found CS-Script useful.
Oleg
|
|
|
|

|
I am playing with the WCF samples and I get this error
Error: Specified file could not be executed.
Script C:\Projects\Tools\cs-script\Lib\wsdl.cs cannot be executed.
Since I am new to this code I am not sure what t olook for. Can you give me some help.
|
|
|
|

|
Hi mtone,
wsdl.cs is the script responsible for running Microsoft wsdl.exe utility. It needs to be executed in order to produce a proxy cs file for consuming by WCF client application.
In your case wsdl.exe for some reason cannot generate the proxy file. I would suggest that you remove the proxy generating instructions in the WCF client script (e.g. //css_prescript wsdl(http://localhost/hello?wsdl, HelloService, /new)) and try to generate the proxy file manually.
In order to do so run wsdl from command prompt with the same parameters as in the client script. This will show where the problem is.
If you cannot solve the problem send the request to the csscript.support@gmail.com address and I will have a closer look at your problem.
Cheers,
Oleg
|
|
|
|

|
Thanks
I got it to work, I had a typo in the URL path.
One other thing while I am here.
The Sample is listed under WCF but the sample only specifies an HTTP call. How about other binding types? do you have any samples for using cs-script for them?
|
|
|
|

|
The sample in the WCF folder was intended to give developers an idea on how to use WCF in C# scripts with auto-generating proxy class with wsdl.exe. Demonstration of all binding flavors of WCF is well beyond the scope of CS-Script documentation.
If your client script/application does not use proxy the code is absolutely the same as for the standalone non-scripted application.
Saying that, I have prepared for you the sample of using named pipes with WCF: http://dl.dropbox.com/u/956512/mtone/SimplePipe%2BHTTP.zip[^]
Cheers,
Oleg
|
|
|
|

|
First of all, let me state that that to me the ease at which cs-script allows implementing type-shared hosted pattern is breakthrough. Not only it is a missing piece but the silver bullet. It allows dealing with the fundamental problem of wild variation when you can't throw enough data models and expert systems at the problem domain to have good coverage. If you have a good object model and API for you problem domain don't look further than cs-script when the real world is laughing in your face and you understand that your models only cover the tip of the iceberg. Yo have the ultimate weapon right here. That said, I am starting to see a compilation issue when multiple appdomains of the same application are entering same compilation calls, like this for example: error CS0016: Could not write to output file 'c:\WINDOWS\Temp\CSSCRIPT\Cache\949632885\2CE2.dll' -- 'The process cannot access the file because it is being used by another process. ' The application is done in ClickOnce with only the CSScriptLibrary.dll being distributed. The global settings are initialized in a static class as follows: CSScript.CacheEnabled = false; CSScript.GlobalSettings.InMemoryAsssembly = true; CSScript.GlobalSettings.TargetFramework = "v3.5"; CSScript.ShareHostRefAssemblies = true; Can this error be somehow guarded against? Want to say thanks again for saving me and my small team. We have a great system with all the pieces but variation was killing us. Please accept my small token of appreciation.
-- Modified Friday, March 12, 2010 10:29 AM
|
|
|
|

|
Hello icyvisor,
I am glad you found CS-Script useful. And you are absolutely right: variations it is where CS-Script works the best. You can "promote" your scripts (addressing the variations) to the "static" code, if you wish, by including them in your compiled codebase. Or you can move any "too static" code from your application to scripts. And all this can be done with very little effort.
Now about your problem.
Usually such symptoms indicate problems with concurrent compilation/execution of the same script file by multiple code routines. Have a look at "<cs-script>\Samples\Hosting\Modifying script without restart" sample in the distributable package. If it is not relevant to your problem contact me by this email: csscript.support@gmail.com. Provide a bit more details and I think I will be able to help.
Regards,
Oleg
|
|
|
|

|
Thanks, turns out we were using it slightly differently, example: new AsmHelper(CSScript.Compile(<String>, null, true)); we have: new AsmHelper(CSScript.LoadCode(<String>)); would you think this could account for the file collision effect? Thanks
|
|
|
|

|
Yes it could, but I cannot say for sure it did.
Nevertheless I would appreciate if you can send me HelloWorld style replica of your application. I would like to see if I can implement some safeguard against this problem.
Thanks,
Oleg
|
|
|
|

|
Hi, I'm trying to implement runtime recompiling of code. I have a game engine which I want external .cs scripts to be able to be altered without stopping the main program.
The way I want to try to do it is by using another AppDomain for each script. So when a .cs file is modified I unload it's AppDomain, compile the new .cs file and create the assembly again (and possibly restore as many variables as possible)
Is this what csscript is doing? Can I unload and update the scripts in place? Thanks!
|
|
|
|
|

|
Hi Oleg
Thanks for creating C# Script.
I'm basically trying get it to do the job of LabView. I've used LabView a lot
I'm trying to attach the script engine in to a logging application that I've had running for a couple of years.
I'v emanaged to get it to interact with public variables in my class but I'm unable to have it pass data to a rich text box and a MessageBox.
For both MessageBox.Show and LogToScreen calls I get :
error CS0103 : The name MessageBox does not exist in the current context.
error CS0103 : The name LogToScreen does not exist in the current context.
Here is an example I've created to illustrate my problem.
Form 1 has a single button and a single richtextbox.
I'd be very grateful if you could tell me where I'm going wrong.
Thanks in advance
Gerry Murray
Glasgow
Scotland
code :
using System;
using System.Windows.Forms;
using System.Windows;
using CSScriptLibrary;
namespace ScriptEngineTest
{
public partial class Form1 : Form
{
static public uint a = 5;
static public uint b = 7;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
LogToScreen("richtextbox1 visible from here!\n");
var code = @"using System;
using System.Windows;
using ScriptEngineTest;
public class Script : MarshalByRefObject
{
public void RunActions(string passtring)
{
MessageBox.Show((Form1.a * Form1.b).ToString());
LogToScreen(Form1.a.ToString() + Form1.b.ToString());
}
}";
try
{
var script = CSScript.LoadCode(code)
.CreateInstance("Script")
.AlignToInterface<IScript>();
script.RunActions("Hello RichTextBox1");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.Trim());
}
}
public interface IScript
{
void RunActions(string passtring);
}
public void LogToScreen(string msg)
{
richTextBox1.AppendText(msg);
}
}
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
|
|
|
|

|
Hi Gerry,
There are a few tiny mistakes in your code that prevent it from working.
- In your script code you are using MessageBox but there is no using statement for System.Windows.Forms
- You are trying to call LogToScreen without specifying object instance (LogToScreen is an instance method). Also you are not passing that instance from the host.
- IScript interface should not be a nested class.
The working code looks like this:
public interface IScript { void RunActions(string passtring, Form1 f); }
namespace ScriptEngineTest { public partial class Form1 : Form { public uint a = 5; public uint b = 7;
public void LogToScreen(string msg) { instance.richTextBox1.AppendText(msg); }
private void button1_Click_1(object sender, EventArgs e) { LogToScreen("richtextbox1 visible from here!\n");
var code = @"using System; using System.Windows.Forms; using ScriptEngineTest;
public class Script { public void RunActions(string passtring, Form1 f) { MessageBox.Show((f.a * f.b).ToString()); f.LogToScreen(f.a.ToString() + f.b.ToString()); } }"; try { var script = CSScriptLibrary.CSScript.LoadCode(code) .CreateInstance("Script") .AlignToInterface<IScript>(true);
script.RunActions("Hello RichTextBox1", this); } catch (Exception ex) { MessageBox.Show(ex.Message.Trim()); } }
Please note that I removed MarshalByRefObject as it is not needed within current context and also added true to the AlignToInterface to allow the script and the host application to share the same assembly set.
Let me know if you still experience problems and I will send you the whole Form1.cs file.
Cheers,
Oleg
|
|
|
|

|
Hi Oleg
Thank you for the quick reply.
You're right about the MessageBox. I missed that one.
Unfortunately, there are still a couple of issues. Mainly brought about by my lack of C# knowledge and how to use CS-Script in my context.
I'm not a newbie by any means but passing around object references is a struggle for me, similar to the problems I had getting my head around pointers in 'C' 15 years ago.
The problems I'm still having are :
1.
My richtextbox is designed and placed on the form designer rather than instantiated explicitly in Form1 at runtime so I'm not sure how I would get a reference to it to pass to my script.
2.
The 'instance' object reference you use in the line : 'instance.richTextBox1.AppendText(msg);', I'm not sure how that instance is declared and where since it's not referred to anywhere else in your reply.
This means that I can't call 'LogToScreen' from the script.
3.
Placing the ISCript interface outside of 'namespace ScriptEngineTest' means that it doesn't have visibility of 'Form1' and so the program doesn't compile.
Changing it to 'void RunActions(string passtring, Form f);' allows it to compile but then the script call to 'MessageBox.Show((f.a * f.b).ToString());' results in :
error CS1061 : System.Windows.Forms.Form' doesn't contain a definition for 'a'. I understand why this is, it's because I'm referring to a generic form rather than my specific 'Form1'
When I change my script call to refer to 'Form1' specifically, I get error CS0176: Member 'ScriptEngineTest.Form1.a' cannot be accessed with an instance reference; qualify it with a type name instead.
Giving it a type name takes me back to CS1061.
Yes, I'd readily admit that I may be missing something obvious.
Bottom line is: yes please, can you send me Form1.cs?
Thanks in advance.
Gerry Murray
|
|
|
|

|
Hi Gerry,
>1. My richtextbox is designed and placed on the form designer rather than instantiated explicitly in Form1 at runtime so I'm not sure how I would get a reference to it to pass to my script.
Put //css_include Form1.designer.cs; at the top of your Form1.cs.
>2. The 'instance' object reference you use in the line : 'instance.richTextBox1.AppendText(msg);', I'm not sure how that instance is declared and where since it's not referred to anywhere else in your reply.
It was a typo please remove 'instance' and the dot after it.
>3.Placing the ISCript interface outside of 'namespace ScriptEngineTest' means that it doesn't have visibility of 'Form1' and so the program doesn't compile.
It does not have to be outside of namespase (though it can). It just has to be plain not nested type.
However the best way of handling this is to work with the original code. Please respond to this post with direct email with attached not working script(s) and I will fix it up for you and send back.
Cheers,
Oleg
|
|
|
|

|
I'm using the CSScriptLibrary.dll assembly, version 2.5.2 from cs-script\Lib\Bin\NET 3.5\
I invoke CS-Script as you suggested with
using CSScriptLibrary;
...
CSScript.ShareHostRefAssemblies = false;
var masterScript = new StringBuilder();
var scripts = Directory.GetFiles(scriptDir,
"*.cs",
SearchOption.AllDirectories);
foreach (var file in scripts)
masterScript.AppendFormat("//css_import {0};\n", file);
string asmFileTypedTableBase = Assembly.GetAssembly(typeof(System.Data.TypedTableBase<DataRow>)).Location;
string[] assemblies = { ".\\CSScriptLibrary.dll", ".\\MyClient.exe", asmFileTypedTableBase };
MzExportInterface exportObj = CSScript.LoadCode(masterScript.ToString(), assemblies)
.CreateObject("MyClient.ExportTemplates." + exportTemplateName + "." + exportTemplateName)
.AlignToInterface<MzExportInterface>();
exportObj.StartExport(scriptDir, exportDir);
However, I fail to debug my scripts. When I set breakpoints in the code, it never stops there. I've read http://csscript.net/help/Debugging.html, but it seems focused on debugging scripts that are launched standalone with cscs.exe (eg. use these command line switches)
And I don't quite get the debug samples...
Do you have any specific hints how to make the debugging work? I don't have any other process to attach to since CS-Script is loaded in process, and it's not CS-Script I want to debug but the script it executes.
|
|
|
|

|
LoadCode has another overloaded signature which accepts bool flag indicating if debug simbols for the script should be generated.
The code appropriate for debugging should look like following:
MzExportInterface exportObj = CSScript.LoadCode(masterScript.ToString(), null, true, assemblies)<br/> .CreateObject("MyClient.ExportTemplates." + exportTemplateName + "." + exportTemplateName)<br/> .AlignToInterface<MzExportInterface>();
Cheers,
Oleg
|
|
|
|

|
Thanks!
And for others reading this: Remember to put the breakpoint in the correct script file if you, just like me, have the script being copied to the bin folder. Having a System.Diagnostics.Debug.Assert(false); in the code works fairly well as well.
|
|
|
|
|

|
Hello again!
My work is going forward with a good pace, and CS-Script is working excellently!
However, I was wondering if you could please sign the assemblies (CSScriptLibrary.dll) that come as part of the binary package, so that I can sign my application.
I could download the source and compile/sign it myself, but I feel that that is undesirable since I'd rather not handle the CS-Script source code myself just to sign it.
I'm not in any hurry, but perhaps something to consider for the next release.
|
|
|
|

|
kittelmann wrote: I was wondering if you could please sign the assemblies (CSScriptLibrary.dll)
Certainly.
|
|
|
|

|
Hi, How do i use the dynamic typing feature in cs-script?
Documentation describes about using the Object as the default type and box/unbox it. Can you give me an example for it?
Thanks.
|
|
|
|

|
Hi there,
Yes, this is what documentation says:
Script language is type safe:
strong typing is a luxury not available in most of the scripting languages. Dynamic typing is also available: use Object as a default type and do boxing/unboxing all the time.
This sort of dynamic typing is (and always was) available in C# and as such this feature has no relation to the scripting nature of CS-Script.
This is a pseudo code example:
static public void Main()
{
object result = Add(1,2);
Console.WriteLine(result);
}
static object Add(object a, object b)
{
return (int)a + (int)b;
}
But honestly, why would any one do anything like that? Strong typing offers not only safer but also more readable/maintainable code.
Of course with C# 4.0 actualy dynamic typing can be really useful:
dynamic calc = GetCalculator();
int sum = calc.Add(10, 20);
instead of reflection based equivalent in C# 3.0:
object calc = GetCalculator();
object res = calc.GetType().InvokeMember("Add",
BindingFlags.InvokeMethod, null,
new object[] { 10, 20 });
int sum = Convert.ToInt32(res);
Cheers,
Oleg
|
|
|
|

|
Thanks for the info. The documentation suggested that it really added functionality to support dynamic typing. But it is default c# behavior, but that is not what i needed.
|
|
|
|

|
>The documentation suggested that it really added functionality to support dynamic typing.
Initially I disagreed. Documentation never suggested that neither strong nor dynamic typing is a feature of the CS-Script engine. That is why I quoted the documentation in my previous post. In fact that quote was taken from the CS-Script Help section describing the advantages of any scripting system based on C#, not only CS-Script.
However...
On the CS-Script home page the very same documentation statement was splet into two separate sentences, what indeed made an impression that CS-Script has its own feature associated with dynamic typing.
I apologise for any confusing. To avoid any further misinterpretation this statement about dynamic typing has been already completely removed from the CS-Script home page.
This statement will be reinstated only when MS releases its dynamic typing support for C# 4.0. And an appropriate explanation will be supplied.
------------------------------------------------
However there is a real CS-Script specific feature associated with dynamic typing - DuckTyping.
It is not what you asked about (boxing/unboxing) but it is about generating strong types dynamically from the script.
It offers dynamic typing but without complitelly surrendering the type safty (as in case of C# 4.0). You can find details here: http://csscript.net/help/Script_hosting_guideline_.html#_interfaceAlignment[^]
Regards,
Oleg
|
|
|
|

|
No problem. I really like CS-script as it is now. Great tooling. Wondering when Microsoft is going to release C# 4.0.
Thanks for the link about ducktyping. Maybe it can help me to get to my goals. Thanks again en good luck with further development.
Arjen
|
|
|
|

|
Member 881719 wrote: Wondering when Microsoft is going to release C# 4.0.
I think it is October/November this year.
|
|
|
|

|
My scenario is as follows:
I have an application, and users will be able to write small plugins to it, or modify existing plugins.
The plugins will be written/coded i CS-Script.
The size of the plugins will vary a lot. Some will be very small, while others will be large.
The users and plugin writers might not have access to a compiler, that's why I'm using CS-Script.
So, some scripts will be rather large, have multiple classes, and be split in several files. I have decided that the scripts will be placed in one directory per plugin.
So, I discover that I have a plugin directory, and what I want to do then is to load all *.cs files in there and execute one method in one of the files (I know which class/file that starting method is in).
I can include other files by using the //css_import statement, but preferably I'd like the users to not have to worry about which files to include. (I'd rater like them to not have to worry about any css directive at all).
Is it possible to do multiple CSScript.Load(file1) for one AsmHelper and thus load all files present without using //css_import ?
I have tried to merge all files into one string, but that fails since using statements should come before the rest of the code.
Do you have any idea if this is possible?
|
|
|
|

|
Yes it is possible. And you will be surprised how this actually is:
(the whole example can be downloaded from here http://dl.getdropbox.com/u/956512/kittelmann/LoadDir/LoadDir.7z[^])
public interface IScript { void Print(string msg); }
...
var masterScript = new StringBuilder();
var scripts = Directory.GetFiles(Environment.CurrentDirectory, "*.cs", SearchOption.AllDirectories);
foreach (var file in scripts) masterScript.AppendFormat("//css_inc {0};\n", file);
IScript script = CSScript.LoadCode(masterScript.ToString()) .CreateObject("Plugins.Script") .AlignToInterface<IScript>();
script.Print("Hello World!");
|
|
|
|

|
Namespaces in the script doesn't work when invoking an instance method.
Namespaces does seem to work when invoking a static method.
This applies to versin 2.5.0, and I have only tesed it within another C# application.
Working code:
string scriptCode = "using System;\n " +
"public class Calc " +
"{ " +
" public int Subtract(int a, int b) " +
" { " +
" return a - b; " +
" } " +
"}";
CSScript.ShareHostRefAssemblies = false;
AsmHelper helper = new AsmHelper(CSScript.LoadCode(scriptCode, null, false, ".\\CSScriptLibrary.dll", ".\\MyClient.exe"));
object calc = helper.CreateObject("Calc");
int c = (int)helper.InvokeInst(calc, "Subtract", 5, 3);
Non-working code:
string scriptCode = "using System;\n " +
"namespace testspace{ " +
"public class Calc " +
"{ " +
" public int Subtract(int a, int b) " +
" { " +
" return a - b; " +
" } " +
"}}";
CSScript.ShareHostRefAssemblies = false;
AsmHelper helper = new AsmHelper(CSScript.LoadCode(scriptCode, null, false, ".\\CSScriptLibrary.dll", ".\\MyClient.exe"));
object calc = helper.CreateObject("testspace.Calc");
int c = (int)helper.InvokeInst(calc, "Subtract", 5, 3);
The exception is:
ApplicationException: Method Calc.Subtract(System.Int32, System.Int32) cannot be found.
at:
at CSScriptLibrary.AsmBrowser.FindMethod(String methodName, Object[] list)
at CSScriptLibrary.AsmBrowser.Invoke(Object obj, String methodName, Object[] list)
at CSScriptLibrary.AsmHelper.InvokeInst(Object obj, String methodName, Object[] list)
...
|
|
|
|

|
Yes this particular scenario exposes the defect in AsmHelper.InvokeInst.
I have fixed the problem and the fix will be published tomorrow. In a mean time I will send you the binaries by email.
However I want to draw you attention that using Reflection based calls (AsmHelper.InvokeInst in your example) is not necessarily the best approach (though there is nothing wrong with this).
Arguable the better choice is CS-Script DuckTyping. Advantages: more readable, strongly typed code, your example will work with just out of box CS-Script v2.5.
using CSScriptLibrary;
...
public interface ICalc { int Subtract(int a, int b); }
...
static void Test() { string scriptCode = @"using System; namespace testspace { public class Calc { public int Subtract(int a, int b) { return a - b; } } }";
CSScript.ShareHostRefAssemblies = false; var script = CSScript.LoadCode(scriptCode, Assembly.GetExecutingAssembly().Location, //your client.exe typeof(CSScript).Assembly.Location); //CSScriptLibrary.dll
ICalc calc = script.CreateObject("testspace.Calc") .AlignToInterface<ICalc>(); //DuckTyping
int c = calc.Subtract(5, 3); Console.WriteLine(c); }
|
Cheers
|
|
|
|

|
That seems like an excellent solution, because what I really want is not for the script to say that it implements my script-interface, but to actually enforce it from the host side.
|
|
|
|

|
Hello!
CSScript seems like a very nice script engine, and I though I'd give it a try for my application.
However, I just can't make it work.
I'm not if it's related to that I'm using Visual Studio 2010 Beta 1 with .NET Framework 4 Beta.
The code I'm using is:
TestScript.cs:
using System;
using System.Windows.Forms;
class TestScript
{
public void ShowString(string message)
{
MessageBox.Show(message);
}
}
MzOptions.cs (a part of my application, compiled and working save for this issue):
private void button3_Click(object sender, EventArgs e)
{
AsmHelper helper = new AsmHelper(CSScript.Load("ExportTemplates\\TestScript.cs"));
helper.Invoke("TestScript.ShowString", "Hello World");
}
And the Load call throws the following exception:
(0,0): error CS1703: An assembly with the same identity 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' has already been imported. Try removing one of the duplicate references.
in:
at csscript.CSExecutor.Compile(String scriptFileName)
at csscript.CSExecutor.Compile(String scriptFile, String assemblyFile, Boolean debugBuild)
at CSScriptLibrary.CSScript.Load(String scriptFile, String assemblyFile, Boolean debugBuild, String[] refAssemblies)
at CSScriptLibrary.CSScript.Load(String scriptFile)
at MazermindClient.MzOptions.button3_Click(Object sender, EventArgs e) in D:\Data\Projects\Mazermind2\Source\MazermindClient\Forms\MzOptions.cs:line 78
at System.Windows.Forms.Control.OnClick(EventArgs e)
...
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
Do you have any suggestion to what I can change to fix it?
Thanks in advance!
|
|
|
|

|
Hello kittelmann,
The problem you are experiencing is caused by your runtime environment. It looks like in your experiment your current AppDomain has at least two mscorlib, Version=4.0.0.0 loaded. And because CS-Script engine by default treats all loaded assemblies as potential referenced assemblies for the script it supplies the to MS C# compiler, which does not like such a duplication.
The solution would be to switch off the assembly sharing between Host and Script. Though then you will need to handle all referenced assemblies for the script by yourself.
With the next CS-Script release (in a day or two) the problem will be handled even in the assembly sharing mode as long as duplicated assemblies have the same file name (not path).
I have composed the example for you, which demonstrates the problem and way of solving it.
http://dl.getdropbox.com/u/956512/kittelmann/kittelmann.7z[^]
Note the example is using CS-Script v2.5 binaries.
Cheers,
Oleg
|
|
|
|

|
Thanks for your help. I'm looking forward to the new version of CS-Script!
|
|
|
|

|
I've downloaded 2.5.0, and there still seems to be the same problem with duplicate mscorlib loaded.
I have tried the CSScript.ShareHostRefAssemblies = false; approach, and it does seem to work.
I don't really have any idea as to why I would have duplicate mscorlib loaded, the only reason I can think of is that I have some references to other assemblies that have loaded mscorlib themselves...
|
|
|
|
 |
|
|
General News Suggestion Question Bug Answer Joke Rant Admin
|
An article on a "scripting engine" for the C# language
| Type | Article |
| Licence | CPOL |
| First Posted | 26 Oct 2004 |
| Views | 541,095 |
| Downloads | 7,092 |
| Bookmarked | 468 times |
|
|