简体   繁体   English

获取异常找不到方法:'System.Runtime.CompilerServices.CallSiteBinder

[英]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.

相关问题 无法定义利用“动态”编译器的类或成员,而找不到所需类型“ System.Runtime.CompilerServices.DynamicAttribute” - Cannot define a class or member that utilizes 'dynamic' compiler required type 'System.Runtime.CompilerServices.DynamicAttribute' not found 我如何 app.Invoke 具有多个参数的后门方法? 在运行时我得到 System.Exception:“没有找到这样的方法” - How do I app.Invoke backdoor method with multiple parameters? At runtime I'm getting System.Exception: “No such method found” "发现无法解决的“System.Runtime.CompilerServices.Unsafe”不同版本之间的冲突" - Found conflicts between different versions of "System.Runtime.CompilerServices.Unsafe" that could not be resolved .NET Standard 库中的 System.Runtime.CompilerServices - System.Runtime.CompilerServices in .NET Standard library System.Runtime.CompilerServices.Unsafe在Xamarin表单中产生意外行为 - System.Runtime.CompilerServices.Unsafe produce unexpected behavior in Xamarin Forms 如何在CoreCLR和CoreFX中使用System.Runtime.CompilerServices.RuntimeHelpers.PrepareMethod? - How to use System.Runtime.CompilerServices.RuntimeHelpers.PrepareMethod with CoreCLR and CoreFX? API 给出错误 {{System.Runtime.CompilerServices.AsyncTaskMethodBuilder1+AsyncStateMachineBox1}} - API is giving Error {{System.Runtime.CompilerServices.AsyncTaskMethodBuilder1+AsyncStateMachineBox1}} 无法加载文件或程序集 System.Runtime.CompilerServices.Unsafe - Could not load file or assembly System.Runtime.CompilerServices.Unsafe 无法加载文件或程序集“System.Runtime.CompilerServices.Unsafe” - Could not load file or assembly 'System.Runtime.CompilerServices.Unsafe' System.Runtime.CompilerServices.AsyncTaskMethodBuilder 上的 System.IO.FileNotFoundException - System.IO.FileNotFoundException on System.Runtime.CompilerServices.AsyncTaskMethodBuilder
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM