问题
我在两个各自的 dll 中有以下代码。dll1 依赖于 dll2。
当DoWork()
被调用时,它将执行得myInterface.MyListMethod(ImmutableList<byte>.Empty);
很好。当它去执行时,会myInterface.MyArrayMethod(ImmutableArray<byte>.Empty);
抛出以下异常:
Exception:System.MissingMethodException: Method not found: Namespace.MyArrayMethod(System.Collections.Immutable.ImmutableArray'1<Byte>)
dll1.dll
public class TestClass
{
public void DoWork()
{
IMyInterface myInterface = new MyInterface();
myInterface.MyListMethod(ImmutableList<byte>.Empty);
myInterface.MyArrayMethod(ImmutableArray<byte>.Empty);
}
}
dll2.dll
public class MyInterface : IMyInterface
{
public void MyArrayMethod(ImmutableArray<byte> byteArray)
{
// Do stuff
}
public void MyListMethod(ImmutableList<byte> byteList)
{
// Do stuff
}
}
public interface IMyInterface
{
void MyArrayMethod(ImmutableArray<byte> byteArray);
void MyListMethod(ImmutableList<byte> byteList);
}
测试
从我的角度来看,这似乎ImmutableArray<>
是错误的,因为我已经尝试了多种类型,包括如您在上面看到的,以及 Immutable 命名空间中的其他类型。它只发生ImmutableArray<>
在我尝试过的情况下。
我还确保这两个 dll 都是当前的 dll,并且 gac 周围没有一些旧的缓存版本。更新接口以具有另一个方法,然后在 MyArrayMethod 按预期工作之前调用该方法。
Visual Studios 特别不会在包含ImmutableArray<>
参数的接口上调用对方法的引用,但它会针对带有ImmutableList<>
. ImmutableArray<>
如果您从方法中删除参数,它也会获取引用。
然而,该解决方案构建良好,只有当它在运行时尝试 JIT 时才会引发此错误。