Menu

#9 clr.AddReference() loads an assembly multiple times

open
nobody
None
5
2012-12-23
2007-09-05
No

>>> import clr
>>> clr.AddReference("System")
<System.Reflection.Assembly object at 0x899c94c>
>>> clr.AddReference("System")
<System.Reflection.Assembly object at 0x8990eac>
>>> clr.AddReference("System")
<System.Reflection.Assembly object at 0x899c98c>
>>> list(clr.ListAssemblies(False))
[u'Mono.Posix', u'System', u'System.Configuration', u'System.Xml', u'Mono.Security', u'e__NativeCall_Assembly', u'Python.Runtime', u'mscorlib', u'System', u'System', u'System']

Discussion

  • Barton Cline

    Barton Cline - 2010-09-12

    1) I don't see existence of, the [...,, u'System', u'System', u'System'] artifact in the current (CLR 2.0) implementation. There are no checks in the AssemblyLoadHandler() method, but it is not called multiple times for a repeated load of a particular assemble by the framework (on Windows, anyway).

    2) Two possible solutions for the unique object reference returned by AddReference() (it does seem reasonable to always get the same instance):
    a) Implement Assembly as a managed type
    b) (I've done this in my version) Wrap the assembly in a ModuleObject and store it CLRModle.dict on the first call. On subsequent calls, retrieve it from the dict.

    Any comment?
    - Barton

     
  • Barton Cline

    Barton Cline - 2010-10-10

    In either case, Converter.ToPython(value, type) must allow some type of ManagedType to be returned OR some Attribute may be applied in order to return the raw results.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.