title: IFileProvider does not execute if a cshtml file already exists on disk
body: <p>I am writing a <code>IFileProvider</code> with which I intend to load content from a database.  I have adapted this code below and as a proof-of-concept I'm just hard-coding a string if a particular request matches &quot;contact&quot;.</p>
  <p>On disk, I have a file, <code>contact.cshtml</code> in my Pages folder.  If I do <em>not</em> use my new <code>DatabaseFileProvider</code>, then the <code>contact.cshtml</code> page renders perfectly, as expected.</p>
  <p>When I include the <code>IFileProvider</code> below, the request to the <code>contact.cshtml</code> page is indeed overridden - again, as expected.</p>
  <p>However, if try to intercept a request for a cshtml file that does <em>not</em> exist, my code never actually gets hit.  You can see in my comments for example, that if I replace the work &quot;contact&quot; with &quot;dynamic&quot;, it fails to execute.</p>
  <p>I'm sure this is to do with how I've intertwined my <code>IFileProvider</code> with MVC's default <code>PhysicalFileProvider</code>.</p>
  <p>Here is my setup:</p>
  <pre><code>public class DatabaseFileProvider : IFileProvider
      {
          
          public IFileInfo GetFileInfo(string subpath)
          {
              var result = new DatabaseFileInfo(subpath);
              return result.Exists ? result as IFileInfo : new NotFoundFileInfo(subpath);
          }
      }
  
  public class DatabaseFileInfo : IFileInfo
      {
          private string _viewPath;
          private byte[] _viewContent;
          private DateTimeOffset _lastModified;
          private bool _exists = false;
  
          public DatabaseFileInfo(string viewPath)
          {
              _viewPath = viewPath;
              GetView(viewPath);
          }
          public bool Exists =&gt; _exists;
  
          public bool IsDirectory =&gt; false;
  
          public DateTimeOffset LastModified =&gt; _lastModified;
  
          public long Length
          {
              get
              {
                  using (var stream = new MemoryStream(_viewContent))
                  {
                      return stream.Length;
                  }
              }
          }
  
          public string Name =&gt; Path.GetFileName(_viewPath);
  
          public string PhysicalPath =&gt; null;
  
          public Stream CreateReadStream()
          {
              return new MemoryStream(_viewContent);
          }
  
          private void GetView(string viewPath)
          {
              if (viewPath == null) return;
              if (viewPath.ToLower().IndexOf(&quot;_view&quot;) != -1) return;
  
              // PROBLEM: this only works if the file EXISTS on disk ???!!!  Try switching out &quot;contact&quot; (works) with &quot;dynamic&quot; (doesn't work)
              // Not even the breakpoint gets hit?
  
              if (viewPath.ToLower().ToLower().IndexOf(&quot;contact&quot;) == -1) return;
  
              var html = &quot;This is NOT cshtml&quot;;
  
              _viewContent = Encoding.UTF8.GetBytes(html);
              _lastModified = DateTime.Now;
              _exists = true;
          }
      }
  </code></pre>
  <p>...and in my <code>Startup.cs</code> file:</p>
  <pre><code>public void ConfigureServices(IServiceCollection services)
          {
              services.AddMvc();
              
              services.Configure&lt;RazorViewEngineOptions&gt;(opts =&gt; {
                      opts.FileProviders.Clear();
                      opts.FileProviders.Add(new DatabaseFileProvider());
                      opts.FileProviders.Add(Environment.ContentRootFileProvider);
  
                      /*
                      opts.FileProviders.Clear();
                      opts.FileProviders.Add(new CompositeFileProvider(
                          Environment.ContentRootFileProvider,
                          new DatabaseFileProvider()
                      )); 
                      */
                  }
              );
              
          }
  </code></pre>
  <p>As you can see, I've left in a second implementation using a <code>CompositeFileProvider</code>, but the issue remains.  I've also changed the order of providers around.</p>
  <p>I'm sure I'm doing something silly - can somebody point me in the right direction?</p>