[Ironpython-users] Problem with embedding IronPython into Silverlight Application

Keith Rome rome at Wintellect.com
Fri Apr 20 00:34:02 CEST 2012


We were able to confirm that this problem affects our product as well. It shows up in both Silverlight 4 and 5 builds. I didn't see an issue ticket created on CodePlex yet, so I created one.

Is the best "fix" going to be to catch MethodAccessException and return an empty string from GetPrefix()? I am not familiar with the importance of that call.


Keith Rome
Senior Consultant and Architect
MCPD-EAD, MCSD, MCDBA, MCTS-WPF, MCTS-TFS, MCTS-WSS
Wintellect | 770.617.4016 | krome at wintellect.com<mailto:rome at wintellect.com>
www.wintellect.com<http://www.wintellect.com/>

From: Mattias Ahlenius [mailto:mattias at goodsolutions.se]
Sent: Thursday, April 19, 2012 2:16 PM
To: Slide
Cc: Keith Rome; ironpython-users at python.org
Subject: Re: [Ironpython-users] Problem with embedding IronPython into Silverlight Application

I've put together a small testproject, when I build it with target SL4 I get the same error as with the IronPython bins, but it works fine when I compile it to target SL5, I've attached a testproject as a .zip (just rename it from sip)

/Mattias
2012/4/19 Mattias Ahlenius <mattias at goodsolutions.se<mailto:mattias at goodsolutions.se>>
I think the binaries under: lib\Sl5 is compiled with SL4 as target and not with SL5, not sure but that may be the issue.

/Mattias



2012/4/19 Slide <slide.o.mix at gmail.com<mailto:slide.o.mix at gmail.com>>
No, that is correct, SL5 does include the FEATURE_ASSEMBLY_LOCATION property in the build, so you should be getting that code when you disassemble. Can you check if there is anything in the InnerException when you catch it?

On Thu, Apr 19, 2012 at 7:28 AM, Mattias Ahlenius <mattias at goodsolutions.se<mailto:mattias at goodsolutions.se>> wrote:
Do I do something fundamentally wrong here... The below is what I get do a disasm on the SL5 assembly in the latest distribution (2.7.2.1)

Greatful for any help I could get in the right direction.

Best regards,

Mattias

2012/4/18 Mattias Ahlenius <mattias at goodsolutions.se<mailto:mattias at goodsolutions.se>>

I get the following when I make a disam in Reflector, the exception (System.MethodAccessException) that I'm getting is not subclassing neither SecurityException or ArgumentException which is catched and handled.



private static string<http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:5.0.5.0:7cec85d7bea7798e/System.String> GetPrefix<http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://IronPython:2.7.1300.40:7f709c5b713576e1/IronPython.Modules.SysModule/GetPrefix():String>()

{

    try

    {

        return Path<http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:5.0.5.0:7cec85d7bea7798e/System.IO.Path>.GetDirectoryName<http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:5.0.5.0:7cec85d7bea7798e/System.IO.Path/GetDirectoryName(String):String>(Assembly<http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:5.0.5.0:7cec85d7bea7798e/System.Reflection.Assembly>.GetExecutingAssembly<http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:5.0.5.0:7cec85d7bea7798e/System.Reflection.Assembly/GetExecutingAssembly():System.Reflection.Assembly>().Location<http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089/System.Reflection.Assembly/property:Location:String>);

    }

    catch (SecurityException<http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:5.0.5.0:7cec85d7bea7798e/System.Security.SecurityException>)

    {

        return string<http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:5.0.5.0:7cec85d7bea7798e/System.String>.Empty<http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:5.0.5.0:7cec85d7bea7798e/System.String/Empty>;

    }

    catch (ArgumentException<http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:5.0.5.0:7cec85d7bea7798e/System.ArgumentException>)

    {

        return string<http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:5.0.5.0:7cec85d7bea7798e/System.String>.Empty<http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:5.0.5.0:7cec85d7bea7798e/System.String/Empty>;

    }

}





/Mattias




2012/4/18 Slide <slide.o.mix at gmail.com<mailto:slide.o.mix at gmail.com>>
This really sounds like the assemblies you are referencing are not really the SL assemblies, can you open the assembly in ILSpy and decompile GetPrefix and see what you have?

slide

On Wed, Apr 18, 2012 at 1:44 PM, Mattias Ahlenius <mattias at goodsolutions.se<mailto:mattias at goodsolutions.se>> wrote:
Same exception even if I use the 2.7.2.1 bins: (I support you mean 2.7.. and not 2.5..)

Message: Failed to load language 'IronPython 2.7.2.1': The type initializer for 'IronPython.Modules.SysModule' threw an exception.

InnerException:

"Attempt by security transparent method 'IronPython.Modules.SysModule.GetPrefix()' to access security critical method 'System.Reflection.Assembly.get_Location()' failed."

/Mattias

2012/4/18 Slide <slide.o.mix at gmail.com<mailto:slide.o.mix at gmail.com>>
Please make sure you have 2.5.2.1 and not just 2.5.2.

On Wed, Apr 18, 2012 at 12:16 PM, Mattias Ahlenius
<mattias at goodsolutions.se<mailto:mattias at goodsolutions.se>> wrote:
> Thanks for your quick reply Keith,
>
> Tried you code and I still get the same Exception:
>
> "Attempt by security transparent method
> 'IronPython.Modules.SysModule.GetPrefix()' to access security critical
> method 'System.Reflection.Assembly.get_Location()' failed."
>
> /Mattias
>
>
>
> 2012/4/18 Keith Rome <rome at wintellect.com<mailto:rome at wintellect.com>>
>>
>> Does this not work for you?
>>
>>
>>
>> using IronPython.Hosting;
>>
>> // ...
>>
>> _python = Python.CreateEngine();
>>
>>
>>
>> I believe that should handle the simple/typical scenarios, unless you need
>> to alter the environment (such as plugging in a custom Host/PAL).
>>
>>
>>
>> If you need to customize the environment, then this should work:
>>
>>
>>
>> var options = new Dictionary<string, object>();
>>
>> ScriptRuntimeSetup setup = Python.CreateRuntimeSetup(options);
>>
>> _runtime = new ScriptRuntime(setup);
>>
>> _python = Python.GetEngine(_runtime);
>>
>>
>>
>>
>>
>> This code should work exactly the same on desktop CLR and Silverlight.
>>
>>
>>
>>
>>
>>
>>
>> Keith Rome
>>
>> Senior Consultant and Architect
>>
>> MCPD-EAD, MCSD, MCDBA, MCTS-WPF, MCTS-TFS, MCTS-WSS
>>
>> Wintellect | 770.617.4016<tel:770.617.4016> | krome at wintellect.com<mailto:krome at wintellect.com>
>>
>> www.wintellect.com<http://www.wintellect.com>
>>
>>
>>
>> From: ironpython-users-bounces+rome=wintellect.com at python.org<mailto:wintellect.com at python.org>
>> [mailto:ironpython-users-bounces+rome<mailto:ironpython-users-bounces%2Brome>=wintellect.com at python.org<mailto:wintellect.com at python.org>] On Behalf
>> Of Mattias Ahlenius
>> Sent: Wednesday, April 18, 2012 2:41 PM
>> To: ironpython-users at python.org<mailto:ironpython-users at python.org>
>> Subject: [Ironpython-users] Problem with embedding IronPython into
>> Silverlight Application
>>
>>
>>
>> Hi,
>>
>>
>>
>> I'm new to scripting and would like to add support for IronPython to our
>> Silverlight application, I have tried to find an answer on the net but could
>> not find anyone else facing the same problem. The app is an out of browser
>> application.
>>
>>
>>
>> I've added the latest release (2.7.2) from nuget, checked that the
>> binaries being used is from the SL5 libs-catalog: IronPython.2.7.2\lib\Sl5
>>
>>
>>
>> The code I use to create the scripting engine is the following:
>>
>>
>>
>> ..
>>
>>
>>             _runtime = new ScriptRuntime(DynamicEngine.CreateRuntimeSetup(true));
>>
>>             _python = _runtime.GetEngine("py");
>>
>> ..
>>
>>
>>
>> When GetEngine is executed I'll the following secutiry exception:
>>
>> "{System.MethodAccessException: Attempt by security transparent method
>> 'IronPython.Modules.SysModule.GetPrefix()' to access security critical
>> method 'System.Reflection.Assembly.get_Location()' failed.
>>
>>    at IronPython.Modules.SysModule.GetPrefix()
>>
>>    at IronPython.Modules.SysModule..cctor()}"
>>
>> When checking the code at GitHub for the method: GetPrefix()
>>
>>
>>
>> There are code checking a compiler-constant that seems to be if you
>> running in "silverlight" (don't have diskaccess to the libs), but the code
>> seems to be executed anyway, which makes me wonder if I still doesn't use
>> the correct libs for Silverlight.
>>
>>
>>
>>
>>
>> Would really appreciate if someone could point me in the right direction.
>>
>>
>>
>>
>>
>> Have a nice day!
>>
>> --
>>
>> Best regards,
>>
>>
>>
>> Mattias Ahlenius
>>
>> 031 - 788 19 25<tel:031%20-%20788%2019%2025>
>>
>>
>>
>> Good Solutions AB
>>
>> http://www.goodsolutions.se
>>
>>
>
>
>
>
> --
>
> Med vänlig hälsning,
>
> Mattias Ahlenius
> 031 - 788 19 25<tel:031%20-%20788%2019%2025>
>
> Good Solutions AB
> http://www.goodsolutions.se
>
>
> _______________________________________________
> Ironpython-users mailing list
> Ironpython-users at python.org<mailto:Ironpython-users at python.org>
> http://mail.python.org/mailman/listinfo/ironpython-users
>



--
Website: http://earl-of-code.com



--
Med vänlig hälsning,

Mattias Ahlenius
031 - 788 19 25<tel:031%20-%20788%2019%2025>

Good Solutions AB
http://www.goodsolutions.se




--
Website: http://earl-of-code.com



--
Med vänlig hälsning,

Mattias Ahlenius
031 - 788 19 25<tel:031%20-%20788%2019%2025>

Good Solutions AB
http://www.goodsolutions.se




--
Med vänlig hälsning,

Mattias Ahlenius
031 - 788 19 25<tel:031%20-%20788%2019%2025>

Good Solutions AB
http://www.goodsolutions.se




--
Website: http://earl-of-code.com



--
Med vänlig hälsning,

Mattias Ahlenius
031 - 788 19 25<tel:031%20-%20788%2019%2025>

Good Solutions AB
http://www.goodsolutions.se




--
Med vänlig hälsning,

Mattias Ahlenius
031 - 788 19 25

Good Solutions AB
http://www.goodsolutions.se

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20120419/07d380f7/attachment.html>


More information about the Ironpython-users mailing list