Does .NET nanoFramework on ESP32 support generics

845 views Asked by At

I'm attempting to write a C# application with a generic class, targeting ESP32. When launching the debugger, the Visual Studio nanoFramework extension's debug process appears to be stuck in an infinite loop at the "Loading Deployment Assemblies" step.

Here's the output I see in the VS2019 debug window:

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)

The default NFProject template builds, launches, and debugs without issue on my hardware. However, adding a generic class causes the infinite loop shown above:

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; }
        }
    }
}

This repro is not affected by whether the generic class is inner, nor by the specific type parameter used. The problem also reproduces if I instantiate and invoke a Func<T>.


I note that in 2018 (see the final comment below the article) a member of the nanoFramework project reported that generics were not supported. However, I'm not able to find any documentation regarding generics support / non-support. Searching around I've found this merged pull request that appears to add support for generics, and this blog post that describes support for System.Collections.Generic and Linq to be "inconsistent".

Does nanoframework currently support generics? And if not, does the project intend to support generics in the future?

1

There are 1 answers

3
José Simões On BEST ANSWER

Generics support it's on the works. Currently the only missing piece is adding support of it in the VS debugger library. We plan to tackle that soon.