Embed python in c# application

Oct 4, 2008 at 10:45 AM
Hi,

I'm trying  to execute the following code in a silverlight application,

            string s = @"from System.Windows import * ";
           
            ScriptEngine engine = IronPython.Hosting.PythonEngine.CurrentEngine;
            engine.Runtime.LoadAssembly( typeof(System.Windows.Duration).Assembly ); 
            ScriptScope scope = engine.CreateScope();
            ScriptSource source = engine.CreateScriptSourceFromString( s , Microsoft.Scripting.SourceCodeKind.Statements);
            source.Execute(scope); 

I'm trying to embed python within a silverlight c# application, but I keep getting the following error:

at Microsoft.Scripting.PlatformAdaptationLayer.FileExists(String path) at Microsoft.Scripting.Hosting.ScriptHost.TryGetSourceFile(ScriptEngine engine, String path, Encoding encoding, SourceCodeKind kind) at Microsoft.Scripting.Hosting.ScriptHostProxy.TryGetSourceFileUnit(LanguageContext language, String path, Encoding encoding, SourceCodeKind kind) at IronPython.Runtime.Importer.LoadModuleFromSource(CodeContext context, String name, String path) at IronPython.Runtime.Importer.LoadPackageFromSource(CodeContext context, String name, String path) at IronPython.Runtime.Importer.ImportFromPath(CodeContext context, String name, String fullName, List path) at IronPython.Runtime.Importer.ImportTopAbsolute(CodeContext context, String name) at IronPython.Runtime.Importer.ImportModule(CodeContext context, Object globals, String modName, Boolean bottom, Int32 level) at IronPython.Runtime.Builtin.__import__(CodeContext context, String name, Object globals, Object locals, Object fromlist, Int32 level) at IronPython.Runtime.Builtin.__import__(CodeContext context, String name, Object globals, Object locals, Object fromlist)

If I do not reference any static assemblies I'm able to run python fine. It looks like on the stack trace that the runtime searches for the assembly, but get some kind of security exception. So how do I embed the static assemblies within my python context .

Best Regards
Niels