[Ironpython-users] Having an issue with using pyc compiled scripts in my C# application.

Jeff Hardy jdhardy at gmail.com
Thu Sep 24 17:11:44 CEST 2015


On Tue, Sep 22, 2015 at 1:36 PM, Chris Knaack <chris at linestream.com> wrote:

> I am using python scripts  to extend my C# application.  Different
> configurations can implement concrete instances of interfaces differently.
> I implement the derived class in python and compile them using pyc.
>
> I have unique versions of the files for each configuration but they have
> the same name in each configuration.
>

Are they strong-named? I don't recall pyc having that option, but the .NET
loader ignores everything except the name (the AssemblyName, not the file
name, for added confusion) if the assemblies are not strong-named.


>
> If I start fresh and load this modules using clr.AddReference() and import
> it works fine.
>
> If I change configurations, the previous implementations appear to be
> cached in the system.  I will get the concrete implementation of the
> original configuration not the newer one.
>

This makes sense. pyc-compiled assemblies are not unloadable, and since
they're not strong-named either the .NET loader assumes they're the same
and doesn't load the new one.

To verify if that's the case, setup fuslogvw and see what messages it gives
when the assemblies are loaded.


> I have tried:
>
> Adding reload() after all the import statements.
>

This only affects Python modules. Once they're compiled with pyc, the .NET
loader gets involved and things get trickier.


> Tried making my PythonEngine in a new AppDomain
>
> Get an error that Microsoft.Scripting.SourceUnit is not serializable.
>
>
An AppDomain should solve the problem, although if there's a bug in
AppDomain support in IronPython it obviously doesn't help you (if there's a
minimal way to reproduce it can you open an issue on
https://github.com/IronLanguages/main/issues?).

Strong-naming should also help, since the loader will now consider the
version. You should be able to just call sn.exe on the assembly produced by
pyc to add this.

Finally, if nothing else, you could change the names to to include the
version. Hacky, but effective.

- Jeff
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20150924/d6fe5035/attachment.html>


More information about the Ironpython-users mailing list