c# - 使用动态方法参数实现接口时的 xUnit System.TypeLoadException
问题描述
我有一个引用的 nuget 包,其中包含一个接口:
public interface IMyInterface {
bool Initialize(Dictionary<string, dynamic> initArguments);
}
在我的解决方案中,我有这个实现:
public class MyImplementation : IMyInterface
{
public bool Initialize(Dictionary<string, dynamic> initArguments)
{
return true;
}
}
如果我在控制台项目中使用它,它可以正常工作:
var myImplementation = new MyImplementation();
但是我如果尝试在单元测试项目中使用它会抛出这个:
System.TypeLoadException:来自程序集 'xxx,Version=1.0.0.0,Culture=neutral,PublicKeyToken=null' 的类型 'xxx.MyImplementation' 中的方法 'Initialize' 没有实现。
这是我的单元测试:
[Fact]
public void Test1()
{
var myImplementation = new MyImplementation();
Assert.NotNull(myImplementation);
}
我认为这可能是因为Dictionary<string, dynamic>
参数,与此相关dynamic
但不确定。我有很多谷歌它没有运气。
更新
如果我检查从 nuget 包引用的接口,它是这样的:
public interface IMyInterface {
bool Initialize([Dynamic(new[] { false, false, true })] Dictionary<string, dynamic> initArguments);
}
我不知道为什么nuget包的编译版本是这样的,Dynamic
param中有data属性。
解决方案
推荐阅读
- javascript - Mongodb(猫鼬)我无法从数组中删除子元素
- javascript - 如何检查一个数组是否包含可以在另一个数组中找到的元素并存储它们的值
- react-native - Error TypeError: undefined is not an object (evalating '_this.state') React-Native
- awk - awk 在列中使用少于 3 个唯一字符的过滤器
- cognos - Cognos Report Studio 每月日期
- git - Gerrit:单击“查看”链接时未看到修改后的文件
- javascript - 在 Shopify 中提交链接而不刷新页面
- sql-server - mssql 上 dlib 的重音字符问题
- javascript - 本来应该带走2的为什么还要拼接很多元素
- python - 在 Pandas 中获取数据框的子集