[英]Getting exception Method not found: 'System.Runtime.CompilerServices.CallSiteBinder
I'm currently working on migrating a .net 4 dll to .net core. 我目前正在将.net 4 dll迁移到.net核心。 I'm porting my unit tests but cannot make them work.
我正在移植我的单元测试,但无法使其正常工作。
This is my project.json for the dll 这是我对dll的project.json
{ "version": "1.0.0-*", "dependencies": { "NETStandard.Library": "1.6.1", }, "frameworks": { "netstandard1.6": { "imports": "dnxcore50" } } }
This is the class I'm currently testing 这是我目前正在测试的课程
public class Matcher
{
public List<ElementMatcher> matchers{ get; set; }
public bool Match(string item, Dictionary<string, object> elements)
{
foreach(var matcher in matchers)
{
var result = matcher.Match(item, elements);
if (!result)
{
return false;
}
}
return true;
}
}
public class ElementMatcher
{
public string attribute { get; set; }
public IMatcher matcher { get; set; }
public virtual bool Match(string key, Dictionary<string, object> attributes)
{
if (attribute == null)
{
return matcher.Match(key);
}
if (attributes == null)
{
return false;
}
object value;
attributes.TryGetValue(attribute, out value);
if (value == null)
{
return false;
}
return matcher.Match((dynamic)value);
}
}
This is the line, in Matcher class, throwing exception: 这是Matcher类中的行,引发异常:
matcher.Match(item, elements);
And this are the current dependencies in my unit tests project: 这是我的单元测试项目中的当前依赖项:
<packages> <package id="Castle.Core" version="4.0.0" targetFramework="net462" /> <package id="Microsoft.CSharp" version="4.3.0" targetFramework="net462" /> <package id="Microsoft.Win32.Primitives" version="4.0.1" targetFramework="net462" /> <package id="Moq" version="4.7.1" targetFramework="net462" /> <package id="System.Diagnostics.DiagnosticSource" version="4.0.0" targetFramework="net462" /> <package id="System.IO" version="4.1.0" targetFramework="net462" /> <package id="System.IO.FileSystem" version="4.0.1" targetFramework="net462" /> <package id="System.IO.FileSystem.Primitives" version="4.0.1" targetFramework="net462" /> <package id="System.IO.FileSystem.Watcher" version="4.0.0" targetFramework="net462" /> <package id="System.Linq" version="4.1.0" targetFramework="net462" /> <package id="System.Linq.Expressions" version="4.1.0" targetFramework="net462" /> <package id="System.Net.Http" version="4.1.0" targetFramework="net462" /> <package id="System.Net.NameResolution" version="4.0.0" targetFramework="net462" /> <package id="System.Reflection" version="4.1.0" targetFramework="net462" /> <package id="System.Runtime" version="4.1.0" targetFramework="net462" /> <package id="System.Runtime.Extensions" version="4.1.0" targetFramework="net462" /> <package id="System.Security.Cryptography.Algorithms" version="4.2.0" targetFramework="net462" /> <package id="System.Security.Cryptography.Encoding" version="4.0.0" targetFramework="net462" /> <package id="System.Security.Cryptography.Primitives" version="4.0.0" targetFramework="net462" /> <package id="System.Security.Cryptography.X509Certificates" version="4.1.0" targetFramework="net462" /> <package id="System.Text.RegularExpressions" version="4.1.0" targetFramework="net462" /> <package id="System.Threading.Thread" version="4.0.0" targetFramework="net462" /> </packages>
Based on what you said on the commentary section, I don't think the problem occurs because of some conflict between framework versions. 根据您在评论部分所讲的内容,我认为问题不会由于框架版本之间的某些冲突而发生。 You've said you're porting your library do .NET Core, so perhaps not everything is fully supported.
您已经说过要将.NET Core移植到库中,所以可能不是所有内容都得到完全支持。 The whole "cast to dynamic then decide which method to call" might be creating the problem (and it's not a very nice way to solve this kind of problem), so I'd try to do something like this:
整个“动态转换,然后决定调用哪种方法”可能是造成问题的原因(这不是解决此类问题的好方法),因此,我将尝试执行以下操作:
public interface IMatcher
{
bool Match(object value);
bool Match(string key);
bool Match(DateTime key);
bool Match(long key);
}
public class MyMatcher : IMatcher
{
public bool Match(object value)
{
if (value is string)
{
return Match(value as string);
}
else if (value is DateTime)
{
return Match(value as DateTime);
}
else if (value is long)
{
return Match(value as long);
}
return false;
}
}
This way, you can remove the dynamic cast.. 这样,您可以删除动态演员表。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.