Announcement

Collapse
No announcement yet.

Unexpected warning in Bridge.React

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

    Unexpected warning in Bridge.React

    First, I liked to apologize in case this is not the right forum for my Bridge.React inquiry. I was thinking putting it in Extensions and Plugins or the Bridge.React github page, but I was not sure... please let me know for future inquiries. Thanks

    Next I wanted to report the several warnings we're getting in our mini project:
    1>CSC : warning AD0001: Analyzer 'Bridge.React.Analyser.ReactElementAnalyser' threw an exception of type 'System.NullReferenceException' with message 'Object reference not set to an instance of an object.'.
    1>CSC : warning AD0001: Analyzer 'Bridge.React.Analyser.ReactElementAnalyser' threw an exception of type 'System.NullReferenceException' with message 'Object reference not set to an instance of an object.'.
    1>CSC : warning AD0001: Analyzer 'Bridge.React.Analyser.ReactElementAnalyser' threw an exception of type 'System.NullReferenceException' with message 'Object reference not set to an instance of an object.'.
    1>CSC : warning AD0001: Analyzer 'Bridge.React.Analyser.ReactElementAnalyser' threw an exception of type 'System.NullReferenceException' with message 'Object reference not set to an instance of an object.'.
    Here are the few React lines in our mini project:
            public override ReactElement Render()
            {
                return DOM.Div(null,
                    DOM.Button(new ButtonAttributes
                    {
                        ClassName    = "connectButton",
                        OnClick        = new Action<MouseEvent<Bridge.Html5.HTMLButtonElement>>((e)=> { OnConnectDisconnect(); }),
                    }, state.IsConnected ? "Disconnect" : "Connect"),
                    DOM.Div(null,
                    DOM.Button(new ButtonAttributes
                    {
                        ClassName    = "subscribeButton",
                        OnClick        = new Action<MouseEvent<Bridge.Html5.HTMLButtonElement>>((e) => { OnSubscribeUnsubscribe(); }),
                        Disabled    = !state.IsConnected
                    }, state.IsSubscribed ? "Unsubscribe" : "Subscribe")),
                    DOM.Div(null,
                    DOM.Button(new ButtonAttributes
                    {
                        ClassName    = "submitButton",
                        OnClick        = new Action<MouseEvent<Bridge.Html5.HTMLButtonElement>>((e) => { OnSubmit(); }),
                        Disabled    = !state.IsConnected
                    }, "Submit")),
                    DOM.Div(null,
                    DOM.Button(new ButtonAttributes
                    {
                        ClassName    = "chartDataButton",
                        OnClick        = new Action<MouseEvent<Bridge.Html5.HTMLButtonElement>>((e) => { OnGetChartData(); }),
                        Disabled    = !state.IsConnected
                    }, "Get Chart Data"))
                );
            }
    What are we doing wrong and how to get rid of the warnings?

    #2
    Posting in the Bridge Help Forum is fine by us, we just need to ensure ProductiveRage is summoned.

    Bridge.React is a community driven project. The Bridge team will help out where we can.

    ProductiveRage can provide some feedback on where issues and questions are preferred.
    Last edited by geoffrey.mcgill; 2017-03-31 @ 08:11 PM.

    Comment


      #3
      I'm afraid that I couldn't reproduce what you have described. I've expanded your example code slightly so that it is a full component class -

      using System;
      using Bridge.React;
      
      namespace Test
      {
          public class ExampleComponent : Component<ExampleComponent.Props, ExampleComponent.State>
          {
              public ExampleComponent() : base(null) { }
      
              public override ReactElement Render()
              {
                  return DOM.Div(null,
                      DOM.Button(new ButtonAttributes
                      {
                          ClassName = "connectButton",
                          OnClick = new Action<MouseEvent<Bridge.Html5.HTMLButtonElement>>((e) => { OnConnectDisconnect(); }),
                      }, state.IsConnected ? "Disconnect" : "Connect"),
                      DOM.Div(null,
                      DOM.Button(new ButtonAttributes
                      {
                          ClassName = "subscribeButton",
                          OnClick = new Action<MouseEvent<Bridge.Html5.HTMLButtonElement>>((e) => { OnSubscribeUnsubscribe(); }),
                          Disabled = !state.IsConnected
                      }, state.IsSubscribed ? "Unsubscribe" : "Subscribe")),
                      DOM.Div(null,
                      DOM.Button(new ButtonAttributes
                      {
                          ClassName = "submitButton",
                          OnClick = new Action<MouseEvent<Bridge.Html5.HTMLButtonElement>>((e) => { OnSubmit(); }),
                          Disabled = !state.IsConnected
                      }, "Submit")),
                      DOM.Div(null,
                      DOM.Button(new ButtonAttributes
                      {
                          ClassName = "chartDataButton",
                          OnClick = new Action<MouseEvent<Bridge.Html5.HTMLButtonElement>>((e) => { OnGetChartData(); }),
                          Disabled = !state.IsConnected
                      }, "Get Chart Data"))
                  );
              }
      
              private static void OnConnectDisconnect() { }
              private static void OnSubscribeUnsubscribe() { }
              private static void OnSubmit() { }
              private static void OnGetChartData() { }
      
              public class Props { }
      
              public class State
              {
                  public bool IsConnected { get; }
                  public bool IsSubscribed { get; }
              }
          }
      }
      Could you include the code for the full component that is causing the warnings for you and I'll have another look?

      On an unrelated matter, you can make the OnClick handler code a little more succinct by replacing lines such as

      OnClick = new Action<MouseEvent<Bridge.Html5.HTMLButtonElement>>((e) => { OnConnectDisconnect(); }),
      with

      OnClick = e => OnConnectDisconnect(),
      It's possibly a matter of stylistic opinion so feel free to ignore me, I personally just enjoy it when the compiler can infer types for me so that I can get the type safety without the laborious task of writing out the full type names over and over :) (and I think that it improves the signal-to-noise ratio of the code).

      Comment


        #4
        ProductiveRage thanks for looking into...

        I just cut our code down to a minimal React component and still am getting those warnings. I will task my team to further isolate the issue and will get back to you.

        Thanks for the hint on the event handler. I figured that out already, after making my post above :-)

        Comment


          #5
          ProductiveRage is there a log/trace mode available which would help to isolate the cause of trouble?

          Comment


            #6
            I'm afraid that there's no debug mode built in. You could do what I do, which is to clone the Bridge.React repo, paste your sample code in as a ReactElementAnalyser unit test and use Debug Test? So long as you compile in debug mode, Debug Test will stop on any exception.

            Comment


              #7
              >> in as a ReactElementAnalyser unit test and use Debug Test

              We haven't started working on that yet, but I suspect this would be close to impossible, since - as I suspect - the issue is coming from the shared .NET project (11K lines of code) which is included in our Bridge.NET project and which Bridge.React analyzer - for whatever reasons - might have trouble to process.

              Further evidence: I'm even getting those exceptions as I removed all React code from the project -> it definitely is caused by some other code

              Is there any way to add exception handling which would help isolating the issue? Could the analyzer be debugged?

              Comment


                #8
                I should be able to give you a NuGet package tomorrow that includes additional stack trace information in the warning, which could help. I'll also have another look at the code to see if I can work out where the NRE could arise. I could wrap it all in a try-catch but that would just be plastering over what could be a logic error worth getting to the bottom of.

                Another option is that it's possible to start a VS instance with another VS debugger attached to it, then you can break on the analyser exception. I can't remember how to do it off the top of my head but it's definitely another option!

                Comment


                  #9
                  >> I should be able to give you a NuGet package tomorrow that includes additional stack trace information in the warning

                  Excellent! That would be great

                  Comment


                    #10
                    I've uploaded a pre-release version of the Bridge.React package (see https://www.nuget.org/packages/Bridge.React/1.12.6-beta). It will take nuget.org a few minute to index the new version but, when it's ready, you should be able to download a debug build if you select "Include prerelease" when you manage your NuGet packages.

                    I tried to work out where the exception could come in, I experimented with invalid attribute and generic type arguments but couldn't get it to trigger in the way that you described. Hopefully the analyser will now record a warning with two useful pieces of information - where the code is in your project that is confusing the analyser and what line in the analyser is throwing the exception.

                    Comment


                      #11
                      Great, thanks! We'll give it try

                      Comment


                        #12
                        I had a team mate running tests ... turns out this code throws exceptions
                        internal    static    List<object[]>           MailQueue = new List<object[]>();

                        Changing it to this did resolve the issue:
                        internal    static    List<List<object>>    MailQueue = new List<List<object>>();

                        Does this help?

                        Comment


                          #13
                          That's perfect!

                          The ReactElementAnalyser does some type analysis to try to look for places that the ReactElement type is used as a generic type argument in object creation expressions and so it has to recursively examine the generic types on code such as new List<object[]>(); and try to ensure that none of the types relate to ReactElement.

                          To do this, it checks the ContainingAssembly of the type - for some reason, that is null for arrays. Arrays are a bit of a weird structure in .NET anyway (for example, Array is a non-generic type and yet you can pass it anywhere that you require an IEnumerable<T> due to some magic of the compiler) so I'm not completely surprised that it caused a problem (though it is a bit weird still; I would have expected it to claim to come from the System assembly).

                          I've pushed a fix, nuget.org is currently indexing version 1.12.6 (non-pre-release version) that includes the correction.

                          Hopefully you won't have any more problems!

                          (On a side note, I think that I've found a way to avoid needing the ReactElementAnalyser entirely and so I might be able to simplify the code in the future by removing it - but it was still very useful to learn about this null-ContainingAssembly-for-object[]-behaviour in Roslyn).
                          Last edited by geoffrey.mcgill; 2017-04-04 @ 04:06 AM.

                          Comment


                            #14
                            Great, thanks! Confirmed that build above resolves all warnings.
                            Last edited by DierkDroth; 2017-04-04 @ 07:40 AM.

                            Comment

                            Working...
                            X