title: Asp.net 5 MVC 6 500 Internal Server Error - Angular 2
body: <p>Im trying to post a query to my web server but receive 500 Internal Server Error without calling the Controller, which never is initialized. I need some help figuring out what I'm doing wrong. I have tried convention based routing and Attribute routing but no luck.</p>
  
  <p>I'm ASP.NET 5 MVC 6,
  Angular 2,
  Typescript,
  DNX is: 1.0.0-rc1-update1 clr x86,
  Visual Studio 2015 update 1,
  IIS Express 10</p>
  
  <p>Thanks!</p>
  
  <p>Call from Angular2:</p>
  
  <pre><code>public class DataLoader
  {
      public loadData = () =&gt; {
          var query = new LoadDataQuery();
          var observable = this.get(query);
          observable.subscribe((data: any) =&gt; {
              console.log("Data from server: ", data);
         });
      };
  
  
      public get = &lt;TResult&gt;(query: Query&lt;TResult&gt;): Observable&lt;TResult&gt; =&gt; {
          var queryName = this.getName(query);
          var url = `/query/${queryName}`;
          return this.httpPost&lt;TResult&gt;(url, query);
      };
  
  
      private getName = (action: any): string =&gt; {
          var regex = /function (.{1,})\(/;
          var results = (regex).exec(action.constructor.toString());
          return (results &amp;&amp; results.length &gt; 1) ? results[1] : "";
      };
  
      private httpPost = &lt;TResult&gt;(url: string, data: any):  Observable&lt;TResult&gt; =&gt; {
          var observable = this.http.post(url, data)
              .map&lt;TResult&gt;(response =&gt; response.json());
          return observable;
      };
  }
  </code></pre>
  
  <p>My project.json:</p>
  
  <pre><code>{
    "version": "1.0.0",
    "compilationOptions": {
      "emitEntryPoint": true
    },
    "dependencies": {
      "Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final",
      "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
      "Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final",
      "Microsoft.AspNet.Diagnostics": "1.0.0-rc1-final",
      "Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
      "Movestic.Styles": "1.0.0-*"
    },
    "frameworks": {
      "dnx46": {
        "dependencies": {
          "Pixie.CommandQueryApi": "1.0.0-*"
        }
      }
    },
    "exclude": [
      "wwwroot",
      "node_modules"
    ],
    "publishExclude": [
      "**.user",
      "**.vspscc"
    ],
    "commands": {
      "web": "Microsoft.AspNet.Server.Kestrel"
    }
  }
  </code></pre>
  
  <p>My Startup.cs</p>
  
  <p>I have also tried Attribute Routing...</p>
  
  <pre><code>public class Startup
  {
      // This method gets called by the runtime. Use this method to add services to the container.
      // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
      public void ConfigureServices(IServiceCollection services)
      {
          services.AddSingleton&lt;IQueryExecutor, QueryExecutor&gt;();
          services.AddSingleton&lt;IQueryTypeCollection, QueryTypeReflectionCollection&gt;();
          services.AddSingleton&lt;ICommandExecutor, CommandExecutor&gt;();
          services.AddSingleton&lt;ICommandTypeCollection, CommandTypeReflectionCollection&gt;();
  
          services.AddMvc();
      }
  
      // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
      public void Configure(IApplicationBuilder app)
      {
          app.UseMvc(routes =&gt;
          {
              routes.MapRoute(
                 name: "queryRouter",
                 template: "query/{*queryName}",
                 defaults: new { controller = "Query", action = "Handle" });
          });
  
          app.UseDeveloperExceptionPage();
  
          // Add the platform handler to the request pipeline.
          app.UseIISPlatformHandler();
          app.UseDefaultFiles();
          app.UseStaticFiles();
      }
  
      // Entry point for the application.
      public static void Main(string[] args) =&gt; WebApplication.Run&lt;Startup&gt;(args);
  }
  </code></pre>
  
  <p>My controller:</p>
  
  <pre><code>public class QueryController : Controller
  {
      private readonly IQueryExecutor queryExecutor;
      private readonly IQueryTypeCollection queryTypeCollection;
  
      public QueryController(IQueryExecutor queryExecutor, IQueryTypeCollection queryTypeCollection)
      {
          this.queryExecutor = queryExecutor;
          this.queryTypeCollection = queryTypeCollection;
      }
  
      public async Task&lt;IActionResult&gt; Handle(string queryName)
      {
          var queryType = this.queryTypeCollection.GetTypeForQueryName(queryName);
          var reader = new StreamReader(this.Request.Body);
          var json = await reader.ReadToEndAsync();
          var query = JsonConvert.DeserializeObject(json, queryType) as IQuery;
  
          await this.queryExecutor.ExecuteAsync(query);
          return this.Ok();
      }
  }
  </code></pre>