我正在围绕.NET Core 2.1 中的新包编写序列化/反序列化框架。System.IO.Pipelines我在生成 IL 以调用具有泛型类上新的“in”修饰符的参数的虚拟方法时遇到了问题。这基本上是我试图调用的方法签名:public virtual T DoSomething(in ReadOnlySpan<byte> memory, T o);如果我去掉虚拟修饰符,我的代码运行良好。添加虚拟修饰符MethodNotFound后,尝试调用生成的代码时会出现异常。我还注意到,如果我不在in方法参数的任何地方使用修饰符,它仍然可以正常工作。如果我从类中取出泛型参数(并保留in参数),则该调用也可以与 virtual 修饰符一起使用。它仅在使用修饰符并且似乎使用泛型类型时才会崩溃in。我已将我的代码缩减为您可以在下面看到的最小示例(对于代码转储,我认为代码中有很多内容与整个问题有关)。using System;using System.Collections.Generic;using System.Reflection;using System.Reflection.Emit;using System.Runtime.CompilerServices;using System.Runtime.InteropServices;using System.Text;namespace MessageStream.Bug{ public class BugReproduction { public static void Main(string[] args) { var test = new TestClass<int>(); var span = new ReadOnlySpan<byte>(new byte[] { 1 }); test.OuterDoSomething(span, 10); } } public class TestClass<T> where T : new() { private ITestInterface<T> testInterfaceImpl; public TestClass() { Initialize(); } public T OuterDoSomething(in ReadOnlySpan<byte> memory, T o) { return testInterfaceImpl.DoSomething(in memory, o); }有任何想法吗?几个星期以来,我一直在努力解决这个问题。您可以在我的存储库中找到实际的真实世界代码。检查基准项目以了解正在发生的事情/如何使用它。
1 回答

皈依舞
TA贡献1851条经验 获得超3个赞
这是 CoreCLR 中的一个已知错误: https ://github.com/dotnet/corefx/issues/29254
解决该问题的 PR已提交并合并,但遗憾的是尚未发布修复程序。在.NET Core 2.2.0 中可以预期。
在那之前,您对此无能为力,因为在本次讨论结束时也说过。
- 1 回答
- 0 关注
- 214 浏览
添加回答
举报
0/150
提交
取消