title: Blazor component shows `Microsoft.AspNetCore.Components.RenderFragment` instead of the HTML content
body: <p>I'm using the <a href="https://github.com/louthy/language-ext/" rel="nofollow noreferrer">Language-Ext library</a> to create a generic union type that represents one of three states...</p>
  <pre class="lang-cs prettyprint-override"><code>  [Union]
    public interface LoadingOption&lt;T&gt; {
      LoadingOption&lt;T&gt; Loading();
      LoadingOption&lt;T&gt; Loaded(T value);
      LoadingOption&lt;T&gt; NotLoaded();
    }
  </code></pre>
  <p>I then have a Blazor component that will show one of three render fragments, depending on which of the three states is represented by the instance of the union...</p>
  <pre class="lang-cs prettyprint-override"><code>@typeparam T
  
  @(Data switch {
    Loading&lt;T&gt; =&gt; Loading,
    Loaded&lt;T&gt; t =&gt; Loaded(t.Value),
    NotLoaded&lt;T&gt; =&gt; NotLoaded,
    _ =&gt; Loading
    })
  
  @code {
  
    [Parameter]
    public LoadingOption&lt;T&gt; Data { get; set; }
  
    [Parameter]
    public RenderFragment&lt;Loading&lt;T&gt;&gt; Loading { get; set; }
  
    [Parameter]
    public RenderFragment&lt;Loaded&lt;T&gt;&gt; Loaded { get; set; }
  
    [Parameter]
    public RenderFragment&lt;NotLoaded&lt;T&gt;&gt; NotLoaded { get; set; }
  
  }
  </code></pre>
  <p>Note that the default case in the <code>switch</code> statement is needed to prevent an exception <em>Non-exhaustive switch expression failed to match its input</em> when the page firsts loads.</p>
  <p>However, when I try to use this component, the HTML is never rendered. Instead, I see <code>Microsoft.AspNetCore.Components.RenderFragment</code> on the page, which sounds like it's treating the <code>RenderFragment</code> as a plain object, rather than as a <code>RenderFragment</code></p>
  <p>Sample usage of the <code>Loader.razor</code> component is as follows...</p>
  <pre class="lang-cs prettyprint-override"><code>@page &quot;/LoadingOptionSample&quot;
  &lt;h3&gt;Loader sample&lt;/h3&gt;
  
  &lt;p&gt;&lt;button class=&quot;btn btn-primary&quot; @onclick=&quot;LoadCustomerFound&quot;&gt;Existing customer&lt;/button&gt;
     &lt;button class=&quot;btn btn-secondary&quot; @onclick=&quot;LoadCustomerNotFound&quot;&gt;No such customer&lt;/button&gt;&lt;/p&gt;
  
  &lt;Loader Data=&quot;_customer&quot; Context=&quot;customer&quot;&gt;
    &lt;Loading&gt;
      &lt;p&gt;Please wait while we look for the customer...&lt;/p&gt;
    &lt;/Loading&gt;
    &lt;Loaded&gt;
      &lt;p&gt;Found @customer.Value.Name (id: @customer.Value.Id), who is @customer.Value.Age years old&lt;/p&gt;
    &lt;/Loaded&gt;
    &lt;NotLoaded&gt;
      &lt;p&gt;Big flop, we can't find him&lt;/p&gt;
    &lt;/NotLoaded&gt;
  &lt;/Loader&gt;
  
  @code {
  
    private LoadingOption&lt;Customer&gt; _customer;
  
    private async Task LoadCustomerFound() {
      _customer = new Loading&lt;Customer&gt;();
      // Simulate database access so we can see the Loading HTML...
      await Task.Delay(2000);
      _customer = new Loaded&lt;Customer&gt;(new Customer(1, &quot;Jim Spriggs&quot;, 42));
    }
  
    private async Task LoadCustomerNotFound() {
      _customer = new Loading&lt;Customer&gt;();
      await Task.Delay(2000);
      _customer = new NotLoaded&lt;Customer&gt;();
    }
  
  }
  </code></pre>
  <p>After clicking one of the buttons, the page looks like this...</p>
  <p><a href="https://i.stack.imgur.com/MCX0R.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MCX0R.png" alt="Sample output" /></a></p>
  <p>Doesn't matter which of the buttons I click, the output is the same, and doesn't change. This supports my suspicion that Blazor isn't treating the <code>RenderFragment</code> as such, but treats it as a plain .NET object and renders it by calling <code>ToString()</code>, which is why I see the type, not the content.</p>
  <p>If I do a non-generic version of this, it works fine.</p>
  <p>Note that I have repeatedly restarted VS, as well as trying this in a separate project, but the result is always the same, so it seems the problem is encapsulated in the three files shown above.</p>
  <p>Anyone any idea what I'm doing wrong? Thanks</p>
  <p><strong>Update</strong> I tried using a regular <code>switch</code> statement, instead of the <code>switch</code> expression, but it didn't make any difference. However, while testing this, I discovered that if I didn't have the <code>switch</code> at all, and simply did this...</p>
  <pre class="lang-cs prettyprint-override"><code>  @NotLoaded
  </code></pre>
  <p>...then I still got the type shown on the page.</p>