Thank you John,

I will try 2.0 alpha, that is perfectly ok.

I would like to avoid the C# helper DLL as I try to show that there are
advantages
useing IronPython instead of C# (in some situations).
For example because of the Python library or the convenient syntax.

So build a C# DLL to enable the use of Python wouldn't demonstrate the point
;-)

If I am on it here are some of my ideas, any suggestions are welcome:

The example I thought about were:

1. Searching for files (and listing them on stdout) by iterating though
directories and comparing the names to a regular expression (pure Python)
2. Extending 1. to modify the files (eg. batch renaming) (pure Python)

3. Extending 1. to search for assemblies and print their versions (and the
referenced assemblies and their version, similar to Linux ldd) (IronPython)
4. Accessing the registry and listing all installed programs (IronPython)

More ideas or extensions are welcome.

Regards,
Claudius

On 6/28/07, John Messerly <[EMAIL PROTECTED]> wrote:

I think what we're seeing here is an IronPython bug. When you try to call
a method on "a", we reflect over the assembly looking for custom attributes,
which fails because it was loaded with ReflectionOnlyLoadFrom. If it's any
consolation, it is fixed in the 2.0 alpha tree:

IronPython console: IronPython 2.0 (2.0.10625.05) on .NET 2.0.50727.1318
Copyright (c) Microsoft Corporation. All rights reserved.
>>> import sys
>>> from System.Reflection import *
>>> a = Assembly.ReflectionOnlyLoadFrom('Test.exe')
>>> an = a.GetName()
>>> print an.Name + " " + str(an.Version)
Test 1.0.0.0

In 1.1, it looks like you can get the assembly version string by doing
"str(a)". That doesn't get you the list of referenced assemblies though. The
easiest workaround is probably to create a C# helper DLL to do the
reflection piece, and then call that from IronPython.

- John


-----Original Message-----
From: [EMAIL PROTECTED] [mailto:
[EMAIL PROTECTED] On Behalf Of C L
Sent: Thursday, June 28, 2007 1:41 PM
To: [email protected]
Subject: [IronPython] SystemError when inspecting an Assembly File through
Assembly.ReflectionOnlyLoadFrom()

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.
_______________________________________________
users mailing list
[email protected]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

_______________________________________________
users mailing list
[email protected]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Reply via email to