问题描述
我正在尝试使用通用类编写一个 C# 应用程序,目标是 ESP32。启动调试器时,Visual Studio nanoFramework 扩展的调试过程似乎在“加载部署程序集”步骤陷入无限循环。
这是我在 VS2019 调试窗口中看到的输出:
Waiting for nanoDevice to initialize...
Debugger found. Resuming boot sequence.
Create Type System.
Loading Deployment Assemblies.
Assembly: Esp32NanoframeworkScratch (1.0.0.0) (212 RAM - 488 ROM - 226 @R_404_5635@DATA)
AssemblyRef = 4 bytes ( 1 elements)
TypeRef = 8 bytes ( 2 elements)
FieldRef = 4 bytes ( 1 elements)
MethodRef = 16 bytes ( 4 elements)
TypeDef = 16 bytes ( 2 elements)
FieldDef = 4 bytes ( 1 elements)
MethodDef = 12 bytes ( 5 elements)
StaticFields = 0 bytes ( 0 elements)
Attributes = 0 bytes ( 0 elements)
typespec = 0 bytes ( 0 elements)
Resources = 0 bytes ( 0 elements)
Resources Files = 0 bytes ( 0 elements)
Resources Data = 0 bytes
Strings = 96 bytes
Signatures = 22 bytes
ByteCode = 40 bytes
Assembly: mscorlib (1.10.3.0) (3948 RAM - 31220 ROM - 18795 @R_404_5635@DATA)
AssemblyRef = 0 bytes ( 0 elements)
TypeRef = 0 bytes ( 0 elements)
FieldRef = 0 bytes ( 0 elements)
MethodRef = 0 bytes ( 0 elements)
TypeDef = 1112 bytes ( 139 elements)
FieldDef = 200 bytes ( 99 elements)
MethodDef = 1568 bytes ( 783 elements)
StaticFields = 144 bytes ( 12 elements)
Attributes = 40 bytes ( 5 elements)
typespec = 4 bytes ( 1 elements)
Resources = 0 bytes ( 0 elements)
Resources Files = 0 bytes ( 0 elements)
Resources Data = 0 bytes
Strings = 2609 bytes
Signatures = 2095 bytes
ByteCode = 9686 bytes
Resolving.
Assembly: mscorlib (1.10.3.0) (3948 RAM - 31220 ROM - 18795 @R_404_5635@DATA)
…(repeats the mscorlib assembly table forever)
默认的 NFProject 模板在我的硬件上构建、启动和调试都没有问题。但是,添加泛型类会导致如上所示的无限循环:
using System.Threading;
namespace Esp32NanoframeworkScratch
{
public class Program
{
public static void Main()
{
_ = new GenericBox<object> { Value = new object() };
Thread.Sleep(Timeout.Infinite);
}
class GenericBox<T>
{
public T Value { get; set; }
}
}
}
这个 repro 不受泛型类是否为内部类的影响,也不受所使用的特定类型参数的影响。如果我实例化并调用 Func<T>
,问题也会重现。
我注意到 in 2018(请参阅文章下方的最终评论)nanoFramework 项目的一名成员报告说,不支持泛型。但是,我找不到有关泛型支持/不支持的任何文档。环顾四周,我发现 this merged pull request 似乎增加了对泛型的支持,而 this blog post 描述了对 System.Collections.Generic
和 Linq 的支持“不一致”。
nanoframework 目前是否支持泛型?如果没有,该项目是否打算在未来支持泛型?
解决方法
泛型支持它的工作。目前唯一缺少的部分是在 VS 调试器库中添加对它的支持。我们计划尽快解决这个问题。