开发者

Generic Interface Library: Could not load type from assembly

开发者 https://www.devze.com 2023-02-03 10:43 出处:网络
For experimental purposes, I am attempting to construct a binary search tree library from which a BST may be instantiated to hold either unique-only or redundant nodes (with a redundant node being one

For experimental purposes, I am attempting to construct a binary search tree library from which a BST may be instantiated to hold either unique-only or redundant nodes (with a redundant node being one with a value equivalent to another in the tree). For reusability, I have defined a single generic interface, ITree, and two sub-interfaces: IUnique and IRedundant.

Being the reason for my reply to Explicit C# interface implementation of interfaces that inherit from other interfaces, the library code may be demonstrated as follows [File Name: itest.cs]:

namespace MyNS {

    public interface INode<T,N>
        where N : INode<T,N> {

        N LChild { get; set; }
        N RChild { get; set; }

        T Value { get; set; }
    }

    public interface ITree<T,N,I>
        where N : INode<T,N> 
        where I : ITree<T,N,I> {

        void Add(N node);
    }

    public interface IUnique<T,N>
        : ITree<T,N,IUnique<T,N>>
        where N : INode<T,N> {
    }

    public interface IRedundant<T,N>
        : ITree<T,N,IRedundant<T,N>>
        where N : INode<T,N> {
    }

    public class Node<T>
        : INode<T,Node<T>> {

        public Node<T> LChild { get; set; }
        public Node<T> RChild { get; set; }

        public T Value { get; set; }
    }

    public class Tree<T>
        : IUnique<T,Node<T>>,
          IRedundant<T,Node<T>> {

        void ITree<T,Node<T>,IUnique<T,Node<T>>>.Add(Node<T> node) {
            /// Add node only if there is none with an equivalent value ///
        }

        void ITree<T,Node<T>,IRedundant<T,Node<T>>>.Add(Node<T> node) {
            /// Add node regardless of its redundancy ///
        }
    }
}

And an example main method [File Name: main.cs]:

public class ITest {
    public static void Main() {
        System.Console.WriteLine(typeof(MyNS.Tree<int>));
    }
}

Attempting to compile the library as a separate assembly from the main executable results in the following error:

$ mc开发者_如何学Gos -out:itest.dll -t:library itest.cs
$ mcs -out:itest.exe main.cs -reference:itest
error CS0011: Could not load type 'MyNS.ITree`3[T,N,MyNS.IUnique`2[T,N]]' from assembly 'itest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.
Compilation failed: 1 error(s), 0 warnings

However, compiling the two together works exactly as expected:

$ mcs -out:itest.exe main.cs itest.cs
$ mono itest.exe
MyNS.Tree`1[System.Int32]

To maintain modularity, how may I keep the library separate from my application logic?

EDIT (Jan 11, 2010): Yep, it was a bug with Mono 2.8.x, and has been fixed in version 2.10.


I'm not familiar with the mono compiler, so I can't tell you the right syntax, but I think the simpler answer is that your second library is not properly referencing the itest library. That they compile together properly is evidence that your code is correct.

I think you're 99% of the way there...just double-check your reference syntax.

0

精彩评论

暂无评论...
验证码 换一张
取 消