3

我正在尝试使用针对 ESP32 的泛型类编写 C# 应用程序。启动调试器时,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 METADATA)

   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 METADATA)

   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 METADATA)
…(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; }
        }
    }
}

此重现不受泛型类是否是内部的影响,也不受使用的特定类型参数的影响。如果我实例化并调用Func<T>.


我注意到,在 2018 年(请参阅文章下方的最终评论),nanoFramework 项目的一名成员报告说不支持泛型。但是,我找不到任何关于泛型支持/不支持的文档。环顾四周,我发现这个合并的拉取请求似乎增加了对泛型的支持,而这篇描述对和 Linq 的支持的System.Collections.Generic文“不一致”。

nanoframework 目前是否支持泛型?如果没有,该项目是否打算在未来支持仿制药?

4

1 回答 1

2

泛型支持它的工作。目前唯一缺少的部分是在 VS 调试器库中添加对它的支持。我们计划尽快解决这个问题。

于 2021-05-02T17:24:05.107 回答