0

In the exe have a child and base classes defined as follows. The partial classRootX is defined in multiple files of the exe.

namespace X
{
    public partial classRootX
    {

    }

    public class child : classRootX
    {
         A a = new A(( classRootX ) this );
    }
}

In a dll

using X;
namespace Y
{
   public class A
   {
       public A(ClassRootX root)
       {
       }
   }
}

get a compiler error

"Argument 1: cannot convert from 'classRootX [....\file.cs(79)]' to 'classRootX [....\xxx.dll]'

Any suggestions for a fix?

  • Missed a using Y; before namespace X – user3735088 Sep 20 '17 at 21:32
  • You can't have `classRootX` _defined_ in both if you want to include on in the other. Then the compiler _will_ get confused. Better approach is to have two separate names. – Sach Sep 20 '17 at 21:34
  • 2
    [You cannot have partial classes spread across multiple assemblies](https://stackoverflow.com/q/647385/216074). – poke Sep 20 '17 at 21:38
  • By "DLL" do you mean an already built dll file? Or a class library project in the solution? Also note that `classRootX != ClassRootX`. And the dll references your main exe project? That doesn't seem fine to me. – Andrew Sep 20 '17 at 21:38
  • Update the post to clarify that classRootX is not defined in dll. Yes dll means a already built dll file / assembly – user3735088 Sep 21 '17 at 08:56

1 Answers1

0

You can't make the static dll depend on the code you are writing.

The dll knows ClassRootX as it was when it was compiled. It doesn't know your current ClassRootX. What if the dll does root.SomeProperty and your code doesn't have it? The dll would have a "compilation error", which makes no sense.

You shouldn't have two projects reference each other, that produces a circular reference. If you need some flexibility in what class A received, you can use an interface, defined in the dll, and then make classRootX implement it.

Andrew
  • 7,602
  • 2
  • 34
  • 42