[IronPython] SystemError when inspecting an Assembly File through Assembly.ReflectionOnlyLoadFrom()

C L realn2s at googlemail.com
Thu Jun 28 22:41:08 CEST 2007


Hello,

I am just playing around with IronPython (1.0 and 1.1 on .NET 2.0.50727.42)
and I tried to access the version and the assembly name of an assembly (DLL
or EXE)
through reflections. (I would like to get the referenced assemblies as well,
but that is a second step)

While the following works in C# code work (with eg it's own EXE as argument)
------
using System;
using System.Reflection;

class Program
{
    static void Main(string[] args)
    {
        Assembly a = Assembly.ReflectionOnlyLoadFrom(args[0]);
        AssemblyName an = a.GetName();
        Console.Write("{0} {1}", an.Name, an.Version);
    }
}
------


With the (IMHO) equivalent IronPython code
------
import sys
from System.Reflection import *
a = Assembly.ReflectionOnlyLoadFrom(sys.argv[1])
an = a.GetName()
print an.Name + " " + an.Version
------

I get following error (VersionInfo.exe is the compiled version of the above
C# code)
> ipy.exe AssemblyVersion.py bin\Debug\VersionInfo.exe
Traceback (most recent call last):
  File AssemblyVersion.py, line 4, in Initialize
SystemError: It is illegal to reflect on the custom attributes of a Type
loaded via ReflectionOnlyGetType (see Assembly.ReflectionOnly) -- use
CustomAttributeData instead.

I tried to use CustomAttributeData  as suggested by the error but didn't
succeed
(I simply don't understand how to use it).
It seemed terrible complicated to access the version.

It would be possible to parse str(a) but I can't believe this is
the way to go.

Are there any other ways to access this information or
what am I missing? Or any hints?

Regards,
Claudius


Btw: I tried to send this may before, but didn't get any reply nor
could I find it in the archive. So please excuse if you get it a second
time.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20070628/39788a49/attachment.html>


More information about the Ironpython-users mailing list