[Python.NET] Restrictions on assembly names

Johannes Strecha j.strecha at gmail.com
Fri Apr 5 08:21:24 EDT 2019

Dear list,

I'm having trouble to import assemblies with certain names. I found it
impossible to import assemblies named "Library", and I cannot import
arbitrarily named assemblies that live in a subfolder having the same name
as the assembly.

Here are some details of a working configuration (MWE):
> namespace mylib {
>     public static class mylibClass {
>     public static double DoubleThis (double x) => x*2;
>     }
> }

> <?xml version="1.0" encoding="utf-8"?>
> <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
>   <PropertyGroup>
>     <Platform>AnyCPU</Platform>
>     <OutputType>Library</OutputType>
>     <OutputPath>bin\</OutputPath>
>     <DefineConstants>TRACE;DEBUG</DefineConstants>
>   </PropertyGroup>
>   <ItemGroup>
>     <Compile Include="*.cs" />
>   </ItemGroup>
>   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
> </Project>

build with "msbuild mylib.csproj", copy the .dll from the bin directory to
the python script (avoid modifying the path).

Python (3.6.6 from Anaconda):
> clr.AddReference('mylib')
> import mylib
> print(mylib)
> print(mylib.mylibClass.DoubleThis(3))

This will print "<module 'mylib'>" and "6.0".

When I name everything "Library" instead of mylib, or put mylib.dll in a
directory called 'mylib', the import works, but the module doesn't contain
any symbols/attributes. (In the latter case, I use
clr.AddReference('mylib/mylib'), of course.) Then, print(mylib) or
print(Library) prints "<module 'Library' (namespace)>", the main difference
being the added "(namespace)". The imported module is empty, calls to
something in the assembly raise an AttributeError (e.g. "...has no
attribute LibraryClass").

Is this a known limitation? Should I post a bug report? Are there any other
restrictions I should know about?

Thank you for considering. Regards,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pythondotnet/attachments/20190405/fc13ce43/attachment.html>

More information about the PythonDotNet mailing list