[IronPython] Compiling with Pyc for Silverlight
Michael Foord
fuzzyman at voidspace.org.uk
Tue Apr 21 00:06:58 CEST 2009
Michael Foord wrote:
> Jb Evain wrote:
>> Hey Michael,
>>
>> On 4/20/09, Michael Foord <fuzzyman at voidspace.org.uk> wrote:
>>
>>> I guess a full IL writer would be needed - which means back to
>>> Cecil and
>>> the like and seeing if parts of them could be run on Silverlight.
>>> *sigh*
>>>
>>
>> You just want to change the references to an assembly from the desktop
>> version to the SL version? With Cecil it's like:
>>
>> var assembly = AssemblyFactory.GetAssembly (file);
>> foreach (var reference in assembly.MainModule.AssemblyReferences) {
>> if (!IsTargetAssembly (reference))
>> continue;
>>
>> reference.Version = new Version (2, 0, 5, 0);
>> }
>> AssemblyFactory.SaveAssembly (assembly, file);
>>
>> Now it doesn't guarantee that the resulting assembly is coherent,
>> visibility wise, as you may have used methods that are not visible or
>> not existent in SL.
>>
>>
> Thanks for that - if it would work it would be really useful, however...
>
> I think I've done the equivalent of this using ildasm / ilasm. I've
> disassembled the assembly to IL, then replaced the references with the
> references to Silverlight assemblies and re-assembled.
>
> The resulting assembly throws exactly the same error - which makes me
> think that the assemblies compiled by Pyc are using things that aren't
> available in Silverlight. *However* -
> Microsoft.Runtime.CompilerServices.StrongBox does exist in
> Silverlight. I think I'll try the whole process again just to see. My
> guess is that rewriting would require an intimate knowledge of the
> differences between the CoreCLR and standard .NET.
>
No - I've rerun the whole process from compiling with Pyc through to
replacing the references in the il and reassembling. Same error. Shame.
SystemError: Could not load type
'Microsoft.Runtime.CompilerServices.StrongBox`1' from assembly
'Microsoft.Scripting.Core, Version=2.0.5.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35'.app.py
Michael Foord
> I can't import it in a Silverlight application though (the following
> code does work on the desktop version of IronPython):
>
> import clr
> clr.AddReference('Microsoft.Scripting')
> clr.AddReference('Microsoft.Scripting.Core')
> from Microsoft.Runtime.CompilerServices import StrongBox
>
> ImportError: No module named Runtime
>
> Michael
>
--
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/blog
More information about the Ironpython-users
mailing list