Disclaimer: I'm fairly new to C# and .NET in general.

Using IronPython 0.9.2. on .NET 2.0.50.215.44 w/ SharpDevelop 2.0.0 build 408

I've been trying to use a modified version of the supplied Embed4.cs example to run from within AutoCAD (just to see if I can get it to work). It compiles fine but when I load and run it I get the exception listed below. I tried "caspol -m -af c:\path\to\IronPython.dll" but it errors out saying IronPython.dll is not strong named. Do I need to recompile IronPython.dll or am I heading in the wrong direction all together? Any help/tips would be greatly appreciated.

Regards,
Tim Riley

[Exception]
************** Exception Text **************
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.TypeInitializationException: The type initializer for ' IronPython.AST.SnippetMaker' threw an exception. ---> System.Security.Policy.PolicyException: Execution permission cannot be acquired.
   at System.AppDomain.nCreateDynamicAssembly(AssemblyName name, Evidence identity, StackCrawlMark& stackMark, PermissionSet requiredPermissions, PermissionSet optionalPermissions, PermissionSet refusedPermissions, AssemblyBuilderAccess access)
   at System.AppDomain.InternalDefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access, String dir, Evidence evidence, PermissionSet requiredPermissions, PermissionSet optionalPermissions, PermissionSet refusedPermissions, StackCrawlMark& stackMark)
   at System.AppDomain.DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access, String dir, Evidence evidence)
   at IronPython.AST.AssemblyGen..ctor(String sourceFileName, String moduleName, String outDir, String outFile)
   at IronPython.AST.AssemblyGen..ctor(String source, String module, String output)
   at IronPython.AST.SnippetMaker..cctor()
   --- End of inner exception stack trace ---
   at IronPython.Hosting.PythonEngine..ctor ()
   at IPTest.EmbededExample.pythontest() in c:\Documents and Settings\TJRiley\My Documents\SharpDevelop Projects\AcadHelloWorld\MyClass.cs:line 18
   at IronPython.Hosting.PythonEngine..ctor()
   at IPTest.EmbededExample.pythontest () in c:\Documents and Settings\TJRiley\My Documents\SharpDevelop Projects\AcadHelloWorld\MyClass.cs:line 18
   at IronPython.Hosting.PythonEngine..ctor()
   at IPTest.EmbededExample.pythontest() in c:\Documents and Settings\TJRiley\My Documents\SharpDevelop Projects\AcadHelloWorld\MyClass.cs:line 18
   at IronPython.Hosting.PythonEngine..ctor()
   at IPTest.EmbededExample.pythontest() in c:\Documents and Settings\TJRiley\My Documents\SharpDevelop Projects\AcadHelloWorld\MyClass.cs:line 18
   at IronPython.Hosting.PythonEngine..ctor ()
   at IPTest.EmbededExample.pythontest() in c:\Documents and Settings\TJRiley\My Documents\SharpDevelop Projects\AcadHelloWorld\MyClass.cs:line 18
   at IronPython.Hosting.PythonEngine..ctor()
   at IPTest.EmbededExample.pythontest () in c:\Documents and Settings\TJRiley\My Documents\SharpDevelop Projects\AcadHelloWorld\MyClass.cs:line 18
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
   at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, SignatureStruct sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
   at System.Reflection.RuntimeMethodInfo.Invoke (Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at AcMgPerDocumentCommandClass.Invoke(AcMgPerDocumentCommandClass* , gcroot<System::Reflection::MethodInfo __gc \*>* mi)
   at AcMgCommandClass.CommandThunk.Invoke(CommandThunk* )
[/Exception]

[Code]
using System;
using System.Collections;
using System.Windows.Forms;

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;

using IronPython.Hosting;

namespace IPTest
{
   public class EmbededExample
   {   
      [CommandMethod("pytest")]
       public void pythontest()
       {
           PythonEngine engine = new PythonEngine();
           Form form = new Form();
           engine.SetVariable("form", form);
           string command =

        //
        //  Import Windows.Forms
        //
        "import sys                                                     " +
        "sys.LoadAssemblyByName('System.Windows.Forms')                 " +
        "sys.LoadAssemblyByName('System.Drawing')                       " +
        "from System.Windows.Forms import Application, Button           " +
        "from System.Drawing import Point                               " +

        //
        //  Create button and add it into the form created by the C# code
        //
        "b = Button(Text='Exit')                                        " +
        "form.Controls.Add(b)                                           " +
        "b.Location = Point(100, 100)                                   " +

        //
        //  Setup an event handler for button's Click event
        //
        "def on_exit(*args):                                            " +
        "    Application.Exit ()                                         " +
        "b.Click += on_exit                                             " +

        //
        //  Display the form
        //
        " form.Text = 'Embedding'                                        " +
        "form.Show()                                                    " +
           "Application.Run()                                              ";
           engine.Execute(command);
       }
   }
}
[/Code]

_______________________________________________
users-ironpython.com mailing list
users-ironpython.com@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Reply via email to