Package uses root namespace that is one of my main class names

288 Views Asked by At

I'm using IronPython for my project. The setup is following:

Project.Main
  - MyProject.Python
     - IronPython package

Project.Main has a class called Community that is one of the main classes. It is used everywhere.

Now has IronPython a namespace called Community.CsharpSqlite with a class called Sqlite3.

  • I do not need to reference this class within MyProject.Main
  • I am not using any classes directly from the IronPython package within MyProject.Main
  • I only refer to wrapper classes in MyProject.Python.

All my code doesn't compile anymore though because I'm getting:

Error CS0118 'Community' is a namespace but is used like a type

This is a very large project and I do not want to start prefixing all my references to the Community class with a namespace prefix.

Example project:

https://www.dropbox.com/s/hayi3a4ctrh8rlx/NamespaceProblem.zip?dl=0

1

There are 1 best solutions below

1
On BEST ANSWER

Update:

To fix this we need to edit the ConsoleApp1.csproj file and add at the bottom:

  <Target Name="ChangeAliasesOfStrongNameAssemblies" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
    <ItemGroup>
      <ReferencePath Condition="'%(FileName)' == 'IronPython.SQLite'">
        <Aliases>IronPythonCommunity</Aliases>
      </ReferencePath>
    </ItemGroup>
  </Target>
<!-- </Project> -->

Then we can load the new modified external alias in our code with the following:

extern alias IronPythonCommunity;
using Community = MyProject.Python.Community;
using System;

Old:

As far as I know you cannot change the Namespace of an imported DLL or NuGet. Usually you want to either use the using like

using Community = MyProj.MyProject.Python;

or use the fully qualified namespace like (you can use CTRL+H for replace all occurrences of Community with MyProject.Python.Community):

static void Test(MyProject.Python.Community x)
{
}