No announcement yet.

Dictionary functions accessed incorrectly inside a module

  • Filter
  • Time
  • Show
Clear All
new posts

    Dictionary functions accessed incorrectly inside a module

    Before I begin, a couple prefaces:
    1. It's possible this is a duplicate/related issue to #3778. It seems different at a glance though so I just want to make sure.
    2. The issue (I think anyway) is specific to configuration in bridge.json and I don't see any way on to change these things, so I don't have a link for you there. Sorry. I will paste the code below though

    The problem:
    When the project is compiled as a `UMD` or `CommonJS` module, dictionary methods are throwing Javascript errors. Here's some code that should reproduce the problem:

    using System.Collections.Generic;
    namespace Foo.Bar {
      public class Foo {
        public struct CustomObject
            public readonly string Str;
            public CustomObject (string str)
                this.Str = str;
        public static readonly IReadOnlyDictionary<int, CustomObject> Dict = new Dictionary<int, CustomObject> (new Dictionary<int, CustomObject> {
          { 1, new CustomObject ("yolo") }
      public class Bar {
        public void FooBar() {
          Foo.Dict.TryGetValue(1, out var customObject);
    and the bridge.json module declaration is just:
      "module": {
        "name": "FooBar",
        "type": "UMD"
    When you call (in Javascript)
    (new Bar()).FooBar()
    an error is thrown:
    FooBar.Foo.Bar.Foo.Dict.System$Collections$Generic$IReadOnlyDictionary$2$System$Int32$FooBar$Foo$Bar$Foo$CustomObject$tryGetValue is not a function
    When I debug the Javascript I see that the function exists on the object, but the property name for the function has the $FooBar portion omitted. Removing that portion of the name from the compiled Bar.FooBar source in a text editor and saving it enables the script to run without error.
    Last edited by Jimmy; 2019-04-08 @ 08:02 PM.

    Hi Jimmy,

    Thanks for the excellent post and detailed instructions on how to reproduce. We will investigate and try to figure out what's going wrong here.


      Methinks my report might have been premature. I was still on 17.6 and the error doesn't occur for me on 17.7, so a simple update was all I needed.