Friday, September 19, 2014

ASP.NET Web API issue: This method or property is not supported after HttpRequest.Form, Files, InputStream, or BinaryRead has been invoked.

When calling an ASP.NET Web API it failed with the following error message:

"An error has occurred." ExceptionMessage "This method or property is not supported after HttpRequest.Form, Files, InputStream, or BinaryRead has been invoked."

ExceptionType "System.Web.HttpException" StackTrace at System.Web.HttpRequest.GetInputStream(Boolean persistEntityBody, Boolean disableMaxRequestLength) at System.Web.HttpRequestWrapper.GetBufferedInputStream() at System.Web.Http.WebHost.SeekableBufferedRequestStream..ctor(HttpRequestBase request) at System.Web.Http.WebHost.HttpControllerHandler.c__DisplayClass11.b__b() at System.Web.Http.WebHost.HttpControllerHandler.LazyStreamContent.get_StreamContent() at System.Web.Http.WebHost.HttpControllerHandler.LazyStreamContent.CreateContentReadStreamAsync() at System.Net.Http.HttpContent.ReadAsStreamAsync() at System.Net.Http.HttpContentExtensions.d__0`1.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at System.Web.Http.ModelBinding.FormatterParameterBinding.d__0.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at System.Web.Http.Controllers.HttpActionBinding.d__0.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at System.Web.Http.Controllers.ActionFilterResult.d__2.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at System.Web.Http.Filters.AuthorizationFilterAttribute.d__2.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at System.Web.Http.Dispatcher.HttpControllerDispatcher.d__0.MoveNext()"

Before you start digging into the issue and lose a couple of hours(like I did), first check which version of the ‘Microsoft.AspNet.WebApi’ package you have installed.

Is it version 5.1.0.?

Don’t look any further, there is a bug inside version 5.1.0. that is causing this issue. So don’t waist more time and just update to Microsoft.AspNet.WebApi version 5.1.1 where the issue is fixed…

Thursday, September 18, 2014

Angular.js and KendoUI: be careful when specifying widget options

Although combining Angular.js and Kendo UI is really easy, there is one thing that bit me in the food when I first started combining the two.

Let’s have a look at some code I wrote:

And then have a look at this code:

Do you see the difference?

If you look carefully you should notice that the string ‘c2’ (to format the number as a currency) is quoted inside the attribute values. Without the single inside they will be interpreted as variable names and Angular-Kendo will look for $scope.c2.

Luckily Angular-Kendo will emit a warning in the JS console when such variables are not found.

Wednesday, September 17, 2014

Combining Angular.js and KendoUI

Thanks to the built-in support, using Kendo UI together with Angular.js is really easy. For all widgets you have an Angular directive available.

Here are the steps you need to take to get it up and running:

  • Include the necessary script references:
    • Either include the kendo.angular.min.js script file or use the kendo.all.min.js(which contains all widgets including the angular.js integration)
  • Add a dependency to Kendo UI inside your Angular app:
    • var productsApp = angular.module('productsApp', ['ngRoute', 'kendo.directives']);
  • Use the Kendo UI directive inside your views. A specific naming pattern is used. You even have 2 options(let’s use for example the NumericTextBox widget):
    • Option 1:  kendo-numeric-text-box
    • Option 2: kendo-numerictextbox
  • Widget options also follow a specific naming pattern. The option name is converted from camelCase to dash-separated-words, and prefixing it with k-. For example:
    • <input kendo-numerictextbox k-min="1" k-max="10" k-up-arrow-text="'Increment'" k-down-arrow-text="'Decrement'" />

More information can be found on the Kendo UI website.

Tuesday, September 16, 2014

Angular.js debugging tip

Here is a quick debugging tip when you want to debug the scope for a specific element:

  • Open up your Angular.js application in Chrome
  • Use the selection tool(magnifying glass) to select the element you want to inspect
    • When the element is selected Chrome will store this element inside a ‘$0’ property
  • Now that we have an element reference, we can open up the console and write some code to get to the scope:

Monday, September 15, 2014

Angular.js: controller as and routing

I talked about the new ‘controller as’ syntax before. It allows you to create an alias for your controller on your scope and use that inside your views:

If you don’t want to specify your controller inside your view and still want to use the ‘controller as’ syntax, this is also possible. On the $routeProvider an extra property is available which allows you to specify the alias there:

Friday, September 12, 2014

Using font-face and .woff files in IIS

After pushing an ASP.NET MVC Web app into acceptance, some users complained that the fonts looked ugly. When investigating the issue we noticed that on Chrome and Firefox a 404 error was thrown when loading a .woff font file in the browser. This prevented the @fontcase specification in our CSS to load the correct font and style our text.

We discovered that the MIME type is missing for .woff files in IIS. Luckily, this is an easy one to fix. Open up your web.config and add the following section:

Thursday, September 11, 2014

TF400917: The current configuration is not valid for this feature. This feature cannot be used until you correct the configuration

While upgrading a Team Foundation Server instance to the latest bits, I ended up with the following error (again):

TF400917: The current configuration is not valid for this feature. This feature cannot be used until you correct the configuration.

This time the issue was not related to some missing work item states, but to an invalid configuration of one of the Add panels. The Add panel allows you to quickly add new work items in the web access:

image

In our case the Add Panel was customized to show some extra fields and these fields were no longer available after the TFS upgrade.

To fix it, I exported the process configuration file using witadmin exportprocessconfig and removed the invalid field from the AddPanel configuration:

image

Afterwards I imported the process configuration again using witadmin importprocessconfig.

This article brought me to the solution: http://www.codeproject.com/Articles/739438/TF-The-current-configuration-is-not-valid-for-this.