Start a new topic

Runtime error with nested class where parent derives from generic base type

I'm trying to write some code to work with React and I've got it basically working (DuoCode and React could be a really awesome combination, by the way!) but I've got a nice-to-have niggle that highlights a problem in the conversion process, I believe.

I have a base class that all components need to inherit from, so that some magic can be applied in JavaScript to make class work as React components. I've defined this as a generic class, with a single type argument for the "props" type. Then each custom React component will be derived from this and specify a "props" type for that generic type param - eg.    

public class Header : ComponentWrapper<HeaderProps>

 In some cases, it would be nice to define the "props" type as a child class within the component - eg.  

public class Header : ComponentWrapper<Header.Props>

 This will compile fine, but there will be a runtime error. It seems like the specific circumstances required to reproduce this are for a non-generic class to inherit from a generic class and for the generic type param to be a class within the derived type.

The simplest reproduce case is to create a new DuoCode project and to replace Program.cs with the following: 

using System;
using DuoCode.Dom;

namespace HelloDuoCode
    public class WrapperCase<T>

    public class Wrapper : WrapperCase<Wrapper.Child>
        public class Child

    static class Program
        static void Run() // HTML body.onload event entry point, see index.html
                new Wrapper.Child()

It's a bit annoying that it doesn't work (though easy enough to work around by not trying to use a child class for the "props" data), but it's a bit worrying that it compiles fine but fails at runtime.

PS: I'm intending to blog about the React integration some time soon, hopefully it will be of interest to others!

1 Comment

I created a fresh repository on Bitbucket for my example project and then checked it out clean.. and it didn't build. I needed to add the DuoCode compiler as a NuGet package (as a pre-release package since it's not in the stable channel yet).

After doing this and rebuilding, the compiled JavaScript shows 

// Generated by DuoCode Compiler 0.6.1253.0 beta

 instead of 

// Generated by DuoCode Compiler 0.3.878.0 BETA

 and now the problem has gone away!

So I guess this is a fixed problem that needs a later NuGet package installing than comes with the current VSIX installation.

If anyone's interested, the example repo is at

Login or Signup to post a comment