简体   繁体   English

在另一个dll中的接口上调用带有ImmutableArray <>的Method时抛出System.MissingMethodException

[英]System.MissingMethodException is thrown when calling a Method with ImmutableArray<> on an interface in a different dll

Problem 问题

I have the below code in the two respective dlls. 我在两个相应的dll中有以下代码。 dll1 depends on dll2. dll1取决于dll2。

When DoWork() is called it will execute myInterface.MyListMethod(ImmutableList<byte>.Empty); 当调用DoWork() ,它将执行myInterface.MyListMethod(ImmutableList<byte>.Empty); fine. 精细。 When it goes to execute myInterface.MyArrayMethod(ImmutableArray<byte>.Empty); 当它去执行myInterface.MyArrayMethod(ImmutableArray<byte>.Empty); the following exception is thrown: 抛出以下异常:

Exception:System.MissingMethodException: Method not found: Namespace.MyArrayMethod(System.Collections.Immutable.ImmutableArray'1<Byte>)

dll1.dll dll1.dll

public class TestClass
{
    public void DoWork()
    {
        IMyInterface myInterface = new MyInterface();
        myInterface.MyListMethod(ImmutableList<byte>.Empty);
        myInterface.MyArrayMethod(ImmutableArray<byte>.Empty);          
    }
}

dll2.dll 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);
}

Testing 测试

From my point of view it seems that ImmutableArray<> is at fault as I've tried this with multiple types, including as you can see above, with other types in the Immutable namespace. 从我的观点来看,似乎ImmutableArray<>是错误的,因为我已尝试使用多种类型,包括如上所述,使用Immutable命名空间中的其他类型。 It only happens with ImmutableArray<> as far as I've tried. 就我所尝试而言,它只发生在ImmutableArray<>

I've also made sure that both the dlls are the current dlls and there isn't some old cached version hanging around the gac. 我还确保这两个dll都是当前的dll,并且没有一些旧的缓存版本挂在gac周围。 Updating the Interface to have another method then calling that before MyArrayMethod works as expected. 更新接口以使另一个方法在MyArrayMethod按预期工作之前调用该方法。

Visual Studios specifically doesn't pick up calling references to the method on the interface that contains the ImmutableArray<> param but it will for methods with the ImmutableList<> . Visual Studios特别没有在包含ImmutableArray<> param的接口上调用对该方法的引用,但是它将用于具有ImmutableList<> It will also pick up references if you remove the ImmutableArray<> param from the method. 如果从方法中删除ImmutableArray<> param,它也会获取引用。

MyArrayMethod只有一个引用

The solution builds fine however, it's only when it tries to JIT at run-time that this error is thrown. 然而,解决方案构建正常,只有当它在运行时尝试JIT时才抛出此错误。

If I add a project reference to 'System.Runtime' everything works fine. 如果我将项目引用添加到'System.Runtime',一切正常。 That's it. 而已。

I ended up solving the problem when I was trying to repro it there was a Culture issue that VS solved by auto added a project reference to System.Runtime . 当我试图重复它时,我最终解决了问题,有一个文化问题,VS解决了自动添加了对System.Runtime的项目引用。 This ended up fixing the larger problem. 这最终解决了更大的问题。 The references in VS are working fine now and the code runs without an issue. VS中的引用现在工作正常,代码运行没有问题。

When I pass null it will build without System.Runtime but when I call the method it will throw the exception. 当我传递null时,它将在没有System.Runtime情况下构建,但是当我调用该方法时,它将抛出异常。 However when try and pass a default ImmutableArray it requires I add the System.Runtime . 但是,当尝试并传递默认的ImmutableArray它需要我添加System.Runtime This resolves the issue. 这解决了这个问题。

I have no idea why this fixed my issue but it did. 我不知道为什么这解决了我的问题,但确实如此。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 抛出异常:System.Private.CoreLib.dll 中的“System.MissingMethodException” - Exception thrown: 'System.MissingMethodException' in System.Private.CoreLib.dll dll 中的方法抛出 System.MissingMethodException:找不到方法 - Method in dll throwing System.MissingMethodException: Method not found System.MissingMethodException:找不到方法? - System.MissingMethodException: Method not found? mscorlib.dll中的&#39;System.MissingMethodException&#39;异常 - 'System.MissingMethodException' exception in mscorlib.dll Ironbarcode.dll: System.MissingMethodException - Ironbarcode.dll : System.MissingMethodException System.MissingMethodException:无法创建接口的实例 - System.MissingMethodException: Cannot create an instance of an interface System.MissingMethodException:找不到 Bigquery 的方法 - System.MissingMethodException: Method not found for Bigquery 运行到System.MissingMethodException:使用PrivateObject找不到方法 - Running into System.MissingMethodException: Method Not Found with PrivateObject 找不到System.MissingMethodException方法Crystal报表 - System.MissingMethodException Method Not Found Crystal Reports 当我关闭C#应用程序时,DLL中的System.MissingMethodException - System.MissingMethodException in a dll when I shut down c# application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM