Fixing WebAPI Issue 150

Topics: ASP.NET Web API
Jul 6, 2012 at 1:37 AM
Edited Jul 6, 2012 at 1:38 AM

Hello!

aspnetwebstack is inspiring. Thank you for this project. I appreciate you for moving it to opensource. I'd really like to contribute. I'm a newcomer to opensource development. So, I’m asking for advices from experienced colleagues.

I’ve read carefully “Ways to Contribute”. I’ve chosen Web API issue #150. I've composed a unit test to ensure the bug exists. I believe it is an easy first step in opensource development to solve this issue. Could you tell if this issue worth to be solved?

Regards, Alex

Jul 7, 2012 at 4:14 PM

Alex,

Sounds great! To get set up, I recommend you start by looking at the instructions in this blog [0].

The change is in itself very small – changing the method IsControllerType in the type DefaultHttpControllerTypeResolver [1] to look like this:

internal static bool IsControllerType(Type t)

{

Contract.Assert(t != null);

return

t != null &&

t.IsClass &&

t.IsVisible &&

t.Name.EndsWith(DefaultHttpControllerSelector.ControllerSuffix, StringComparison.OrdinalIgnoreCase) &&

!t.IsAbstract &&

TypeHelper.HttpControllerType.IsAssignableFrom(t);

}

The bigger issue is to write tests that cover it in detail to ensure that there are no corner cases. You can find the unit tests for this class at [2].

Hope this helps!

Henrik

[0] http://blogs.msdn.com/b/henrikn/archive/2012/04/10/using-forks-with-asp-net-web-stack-source-on-codeplex.aspx

[1] http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/944ab06b9c54#src%2fSystem.Web.Http%2fDispatcher%2fDefaultHttpControllerTypeResolver.cs

[2] http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/944ab06b9c54#test%2fSystem.Web.Http.Test%2fDispatcher%2fDefaultHttpControllerTypeResolverTest.cs

Jul 8, 2012 at 11:40 PM

Henrik, hi.

This helped! Thanks for a rapid reply.

Tutorial at [0] is helpful but outdated. Pictures should be updated. “git clone https://<UserName>@git01.codeplex.com/forks/<UserName>/aspnetwebstack” is now “git clone https://git01.codeplex.com/forks/<UserName>/aspnetwebstack”.


Thank you for referencing IsControllerType. I have found it recently by myself. By the way, MVC also has IsControllerType at [1]. The change is very small as I wanted to start with simple task.

I uninstalled MVC4. I have an error and a warning while building aspnetwebstack:

d:\Projects\aspnetwebstack_fork>build

Microsoft (R) Build Engine Version 4.0.30319.1

[Microsoft .NET Framework, Version 4.0.30319.269]

Copyright (C) Microsoft Corporation 2007. All rights reserved.

 

  System.Web.Razor -> d:\Projects\aspnetwebstack_fork\bin\Release\System.Web.Razor.dll

  System.Web.WebPages.Deployment -> d:\Projects\aspnetwebstack_fork\bin\Release\System.Web.WebPages.Deployment.dll

  WebMatrix.Data -> d:\Projects\aspnetwebstack_fork\bin\Release\WebMatrix.Data.dll

  Running Code Analysis...

  Microsoft.TestCommon -> d:\Projects\aspnetwebstack_fork\bin\Release\Test\Microsoft.TestCommon.dll

  System.Web.Razor.Test -> d:\Projects\aspnetwebstack_fork\bin\Release\Test\System.Web.Razor.Test.dll

  Code Analysis Complete -- 0 error(s), 0 warning(s)

  System.Web.WebPages -> d:\Projects\aspnetwebstack_fork\bin\Release\System.Web.WebPages.dll

  Running Code Analysis...

  System.Net.Http.Formatting -> d:\Projects\aspnetwebstack_fork\bin\Release\System.Net.Http.Formatting.dll

  Running Code Analysis...

  Code Analysis Complete -- 0 error(s), 0 warning(s)

  Code Analysis Complete -- 0 error(s), 0 warning(s)

  System.Web.Helpers -> d:\Projects\aspnetwebstack_fork\bin\Release\System.Web.Helpers.dll

  Running Code Analysis...

  System.Web.Http -> d:\Projects\aspnetwebstack_fork\bin\Release\System.Web.Http.dll

  Running Code Analysis...

  Code Analysis Complete -- 0 error(s), 0 warning(s)

  System.Web.WebPages.Razor -> d:\Projects\aspnetwebstack_fork\bin\Release\System.Web.WebPages.Razor.dll

  Running Code Analysis...

  Code Analysis Complete -- 0 error(s), 0 warning(s)

  Code Analysis Complete -- 0 error(s), 0 warning(s)

  System.Web.WebPages.Test -> d:\Projects\aspnetwebstack_fork\bin\Release\Test\System.Web.WebPages.Test.dll

  System.Web.WebPages.Deployment.Test -> d:\Projects\aspnetwebstack_fork\bin\Release\Test\System.Web.WebPages.Deployment.Test.dll

  System.Net.Http.Formatting.Test.Unit -> d:\Projects\aspnetwebstack_fork\bin\Release\Test\System.Net.Http.Formatting.Test.dll

  System.Web.Http.SelfHost -> d:\Projects\aspnetwebstack_fork\bin\Release\System.Web.Http.SelfHost.dll

  Running Code Analysis...

  System.Web.Http.Test -> d:\Projects\aspnetwebstack_fork\bin\Release\Test\System.Web.Http.Test.dll

  System.Web.Http.WebHost -> d:\Projects\aspnetwebstack_fork\bin\Release\System.Web.Http.WebHost.dll

  Running Code Analysis...

  Code Analysis Complete -- 0 error(s), 0 warning(s)

  WebMatrix.Data.Test -> d:\Projects\aspnetwebstack_fork\bin\Release\Test\WebMatrix.Data.Test.dll

  Code Analysis Complete -- 0 error(s), 0 warning(s)

  Microsoft.Web.Http.Data -> d:\Projects\aspnetwebstack_fork\bin\Release\Microsoft.Web.Http.Data.dll

  Running Code Analysis...

  SPA -> d:\Projects\aspnetwebstack_fork\src\SPA\bin\Release\SPA.dll

  Code Analysis Complete -- 0 error(s), 0 warning(s)

  System.Web.WebPages.Razor.Test -> d:\Projects\aspnetwebstack_fork\bin\Release\Test\System.Web.WebPages.Razor.Test.dll

  System.Web.Mvc -> d:\Projects\aspnetwebstack_fork\bin\Release\System.Web.Mvc.dll

  Running Code Analysis...

  Code Analysis Complete -- 0 error(s), 0 warning(s)

  WebMatrix.WebData -> d:\Projects\aspnetwebstack_fork\bin\Release\WebMatrix.WebData.dll

  Running Code Analysis...

  Code Analysis Complete -- 0 error(s), 0 warning(s)

  System.Web.Helpers.Test -> d:\Projects\aspnetwebstack_fork\bin\Release\Test\System.Web.Helpers.Test.dll

  System.Net.Http.Formatting.Test.Integration -> d:\Projects\aspnetwebstack_fork\bin\Release\Test\System.Net.Http.Formatting.Test.Integration.dll

  WebMatrix.WebData.Test -> d:\Projects\aspnetwebstack_fork\bin\Release\Test\WebMatrix.WebData.Test.dll

  Microsoft.Web.WebPages.OAuth -> d:\Projects\aspnetwebstack_fork\bin\Release\Microsoft.Web.WebPages.OAuth.dll

  Running Code Analysis...

  System.Web.WebPages.Administration -> d:\Projects\aspnetwebstack_fork\bin\Release\System.Web.WebPages.Administration.dll

  Running Code Analysis...

MSBUILD : warning : CA0060 : The indirectly-referenced assembly 'System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' c

ould not be found. This assembly is not required for analysis, however, analysis results could be incomplete. This assembly was referenced by: d:\Pro

jects\aspnetwebstack_fork\packages\DotNetOpenAuth.Core.4.0.3.12153\lib\net40-full\DotNetOpenAuth.Core.dll. [d:\Projects\aspnetwebstack_fork\src\Micro

soft.Web.WebPages.OAuth\Microsoft.Web.WebPages.OAuth.csproj]

MSBUILD : warning : CA0060 : The indirectly-referenced assembly 'log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821' could n

ot be found. This assembly is not required for analysis, however, analysis results could be incomplete. This assembly was referenced by: d:\Projects\

aspnetwebstack_fork\packages\DotNetOpenAuth.Core.4.0.3.12153\lib\net40-full\DotNetOpenAuth.Core.dll. [d:\Projects\aspnetwebstack_fork\src\Microsoft.W

eb.WebPages.OAuth\Microsoft.Web.WebPages.OAuth.csproj]

  Code Analysis Complete -- 0 error(s), 2 warning(s)

  Microsoft.Web.WebPages.OAuth.Test -> d:\Projects\aspnetwebstack_fork\bin\Release\Test\Microsoft.Web.WebPages.OAuth.Test.dll

  Code Analysis Complete -- 0 error(s), 0 warning(s)

  Microsoft.Web.Helpers -> d:\Projects\aspnetwebstack_fork\bin\Release\Microsoft.Web.Helpers.dll

  Running Code Analysis...

  Code Analysis Complete -- 0 error(s), 0 warning(s)

  Microsoft.Web.Helpers.Test -> d:\Projects\aspnetwebstack_fork\bin\Release\Test\Microsoft.Web.Helpers.Test.dll

  System.Web.WebPages.Administration.Test -> d:\Projects\aspnetwebstack_fork\bin\Release\Test\System.Web.WebPages.Administration.Test.dll

  Microsoft.Web.Http.Data.EntityFramework -> d:\Projects\aspnetwebstack_fork\bin\Release\Microsoft.Web.Http.Data.EntityFramework.dll

  Running Code Analysis...

  Microsoft.Web.Mvc -> d:\Projects\aspnetwebstack_fork\bin\Release\Microsoft.Web.Mvc.dll

  Running Code Analysis...

  Code Analysis Complete -- 0 error(s), 0 warning(s)

  Microsoft.Web.Http.Data.Helpers -> d:\Projects\aspnetwebstack_fork\bin\Release\Microsoft.Web.Http.Data.Helpers.dll

  Running Code Analysis...

  Code Analysis Complete -- 0 error(s), 0 warning(s)

  Code Analysis Complete -- 0 error(s), 0 warning(s)

  System.Web.Mvc.Test -> d:\Projects\aspnetwebstack_fork\bin\Release\Test\System.Web.Mvc.Test.dll

  System.Web.Http.WebHost.Test -> d:\Projects\aspnetwebstack_fork\bin\Release\Test\System.Web.Http.WebHost.Test.dll

  Microsoft.Web.Http.Data.Test -> d:\Projects\aspnetwebstack_fork\bin\Release\Test\Microsoft.Web.Http.Data.Test.dll

  Microsoft.Web.Mvc.Test -> d:\Projects\aspnetwebstack_fork\bin\Release\Test\Microsoft.Web.Mvc.Test.dll

  System.Web.Http.SelfHost.Test -> d:\Projects\aspnetwebstack_fork\bin\Release\Test\System.Web.Http.SelfHost.Test.dll

  System.Web.Http.Integration.Test -> d:\Projects\aspnetwebstack_fork\bin\Release\Test\System.Web.Http.Integration.Test.dll

  xUnit.net MSBuild runner (32-bit .NET 4.0.30319.269)

  xUnit.net MSBuild runner (32-bit .NET 4.0.30319.269)

  xunit.dll:     Version 1.9.1.1600

  Test assembly: d:\Projects\aspnetwebstack_fork\bin\Release\test\Microsoft.Web.Http.Data.Test.dll

  xunit.dll:     Version 1.9.1.1600

  Test assembly: d:\Projects\aspnetwebstack_fork\bin\Release\test\Microsoft.Web.Helpers.Test.dll

    Tests: 23, Failures: 0, Skipped: 0, Time: 7,838 seconds

  xUnit.net MSBuild runner (32-bit .NET 4.0.30319.269)

  xunit.dll:     Version 1.9.1.1600

  Test assembly: d:\Projects\aspnetwebstack_fork\bin\Release\test\Microsoft.Web.Mvc.Test.dll

    Tests: 456, Failures: 0, Skipped: 0, Time: 5,943 seconds

Tracker.exe: Response file C:\Users\kate\AppData\Local\Temp\99a322335ba54548a178ed71da781219.rsp not found.

Tracker.exe: Response file C:\Users\kate\AppData\Local\Temp\99a322335ba54548a178ed71da781219.rsp not found.

  xUnit.net MSBuild runner (32-bit .NET 4.0.30319.269)

  xunit.dll:     Version 1.9.1.1600

  Test assembly: d:\Projects\aspnetwebstack_fork\bin\Release\test\Microsoft.Web.WebPages.OAuth.Test.dll

    Tests: 20, Failures: 0, Skipped: 0, Time: 3,683 seconds

  xUnit.net MSBuild runner (32-bit .NET 4.0.30319.269)

  xunit.dll:     Version 1.9.1.1600

  Test assembly: d:\Projects\aspnetwebstack_fork\bin\Release\test\System.Net.Http.Formatting.Test.dll

    Tests: 199, Failures: 0, Skipped: 0, Time: 23,136 seconds

  xUnit.net MSBuild runner (32-bit .NET 4.0.30319.269)

  xunit.dll:     Version 1.9.1.1600

  Test assembly: d:\Projects\aspnetwebstack_fork\bin\Release\test\System.Web.Helpers.Test.dll

    Tests: 416, Failures: 0, Skipped: 0, Time: 9,165 seconds

  xUnit.net MSBuild runner (32-bit .NET 4.0.30319.269)

  xunit.dll:     Version 1.9.1.1600

  Test assembly: d:\Projects\aspnetwebstack_fork\bin\Release\test\System.Web.Http.Integration.Test.dll

    Tests: 374, Failures: 0, Skipped: 0, Time: 15,266 seconds

  xUnit.net MSBuild runner (32-bit .NET 4.0.30319.269)

  xunit.dll:     Version 1.9.1.1600

  Test assembly: d:\Projects\aspnetwebstack_fork\bin\Release\test\System.Web.Http.SelfHost.Test.dll

    Tests: 4037, Failures: 0, Skipped: 0, Time: 26,640 seconds

  xUnit.net MSBuild runner (32-bit .NET 4.0.30319.269)

  xunit.dll:     Version 1.9.1.1600

  Test assembly: d:\Projects\aspnetwebstack_fork\bin\Release\test\System.Web.Http.Test.dll

    Tests: 144, Failures: 0, Skipped: 0, Time: 7,325 seconds

  xUnit.net MSBuild runner (32-bit .NET 4.0.30319.269)

  xunit.dll:     Version 1.9.1.1600

  Test assembly: d:\Projects\aspnetwebstack_fork\bin\Release\test\System.Web.Http.WebHost.Test.dll

    Tests: 171, Failures: 0, Skipped: 0, Time: 3,727 seconds

  xUnit.net MSBuild runner (32-bit .NET 4.0.30319.269)

  xunit.dll:     Version 1.9.1.1600

  Test assembly: d:\Projects\aspnetwebstack_fork\bin\Release\test\System.Web.Mvc.Test.dll

    Tests: 1698, Failures: 0, Skipped: 0, Time: 17,120 seconds

  xUnit.net MSBuild runner (32-bit .NET 4.0.30319.269)

  xunit.dll:     Version 1.9.1.1600

  Test assembly: d:\Projects\aspnetwebstack_fork\bin\Release\test\System.Web.Razor.Test.dll

    Tests: 1358, Failures: 0, Skipped: 0, Time: 3,439 seconds

  xUnit.net MSBuild runner (32-bit .NET 4.0.30319.269)

  xunit.dll:     Version 1.9.1.1600

  Test assembly: d:\Projects\aspnetwebstack_fork\bin\Release\test\System.Web.WebPages.Administration.Test.dll

    Tests: 75, Failures: 0, Skipped: 0, Time: 5,453 seconds

  xUnit.net MSBuild runner (32-bit .NET 4.0.30319.269)

  xunit.dll:     Version 1.9.1.1600

  Test assembly: d:\Projects\aspnetwebstack_fork\bin\Release\test\System.Web.WebPages.Deployment.Test.dll

    Tests: 52, Failures: 0, Skipped: 0, Time: 3,303 seconds

  xUnit.net MSBuild runner (32-bit .NET 4.0.30319.269)

  xunit.dll:     Version 1.9.1.1600

  Test assembly: d:\Projects\aspnetwebstack_fork\bin\Release\test\System.Web.WebPages.Razor.Test.dll

    Tests: 46, Failures: 0, Skipped: 0, Time: 2,960 seconds

  xUnit.net MSBuild runner (32-bit .NET 4.0.30319.269)

  xunit.dll:     Version 1.9.1.1600

  Test assembly: d:\Projects\aspnetwebstack_fork\bin\Release\test\System.Web.WebPages.Test.dll

    Tests: 2822, Failures: 0, Skipped: 0, Time: 30,047 seconds

  xUnit.net MSBuild runner (32-bit .NET 4.0.30319.269)

  xunit.dll:     Version 1.9.1.1600

  Test assembly: d:\Projects\aspnetwebstack_fork\bin\Release\test\WebMatrix.Data.Test.dll

    Tests: 23, Failures: 0, Skipped: 0, Time: 2,363 seconds

  xUnit.net MSBuild runner (32-bit .NET 4.0.30319.269)

  xunit.dll:     Version 1.9.1.1600

  Test assembly: d:\Projects\aspnetwebstack_fork\bin\Release\test\WebMatrix.WebData.Test.dll

d:\Projects\aspnetwebstack_fork\tools\WebStack.xunit.targets(12,9): error : WebMatrix.WebData.Test.SimpleMembershipProviderTest.GenerateTokenHtmlEnco

desValues: Assert.Equal() Failure

d:\Projects\aspnetwebstack_fork\tools\WebStack.xunit.targets(12,9): error : Position: First difference is at position 2

d:\Projects\aspnetwebstack_fork\tools\WebStack.xunit.targets(12,9): error : Expected: fGH/eKcjvW//P+5BOEW1

d:\Projects\aspnetwebstack_fork\tools\WebStack.xunit.targets(12,9): error : Actual:   fGF5eKcjP295pmlBOEW1

d:\Projects\aspnetwebstack_fork\tools\WebStack.xunit.targets(12,9): error :    at WebMatrix.WebData.Test.SimpleMembershipProviderTest.GenerateTokenHt

mlEncodesValues() in d:\Projects\aspnetwebstack_fork\test\WebMatrix.WebData.Test\SimpleMembershipProviderTest.cs:line 169

    Tests: 16, Failures: 1, Skipped: 0, Time: 7,499 seconds

  xUnit.net MSBuild runner (32-bit .NET 4.0.30319.269)

  xunit.dll:     Version 1.9.1.1600

  Test assembly: d:\Projects\aspnetwebstack_fork\bin\Release\test\System.Net.Http.Formatting.Test.Integration.dll

    Tests: 860, Failures: 0, Skipped: 0, Time: 25,225 seconds

    Tests: 331, Failures: 0, Skipped: 0, Time: 13,793 seconds

 

*** BUILD FAILED ***

 

How should I fix them? 


I am developing web-project in a team that based on the recent public version of aspnetwebstack v4. I had to remove MVC4 from my PC to contribute to aspnetwebstack . What the best way you can suggest to stay consistent in both directions?

Regards,

  Alex

 

[0] http://blogs.msdn.com/b/henrikn/archive/2012/04/10/using-forks-with-asp-net-web-stack-source-on-codeplex.aspx

[1] http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/944ab06b9c54#src%2fSystem.Web.Mvc%2fControllerTypeCache.cs

Jul 15, 2012 at 6:30 PM

I am not sure what the issue is. Could you please try and get the latest source and try compiling from within VS?

Jul 16, 2012 at 11:57 PM
Edited Jul 17, 2012 at 12:54 AM

 

Thank you for answering.

Sure. Build results for the latest source is as follows:

 

    Tests: 16, Failures: 1, Skipped: 0, Time: 10,480 seconds

    Tests: 860, Failures: 0, Skipped: 0, Time: 24,818 seconds

 

*** BUILD FAILED ***

 

 

Test failure:

 

Test assembly: d:\Projects\aspnetwebstack_fork\bin\Release\test\WebMatrix.WebData.Test.dll
d:\Projects\aspnetwebstack_fork\tools\WebStack.xunit.targets(12,9): error : WebMatrix.WebData.Test.SimpleMembershipProviderTest.GenerateTokenHtmlEncodesValues: Assert.Equal() Failure

d:\Projects\aspnetwebstack_fork\tools\WebStack.xunit.targets(12,9): error : Position: First difference is at position 2

d:\Projects\aspnetwebstack_fork\tools\WebStack.xunit.targets(12,9): error : Expected: fGH/eKcjvW//P+5BOEW1

d:\Projects\aspnetwebstack_fork\tools\WebStack.xunit.targets(12,9): error : Actual:   fGF5eKcjP295pmlBOEW1

d:\Projects\aspnetwebstack_fork\tools\WebStack.xunit.targets(12,9): error :    at WebMatrix.WebData.Test.SimpleMembershipProviderTest.GenerateTokenHtmlEncodesValues() in d:\Projects\aspnetwebstack_fork\test\WebMatrix.WebData.Test\SimpleMembershipProviderTest.cs:line 169

 

Same result in VS. src build is successful. Same test is failed.

 

I am still searching for the way how to contribute to the latest sources while having MVC4 RC insalled . I found the post [1]. Will it work with the latest sources? I suppose that recent build assemblies and MVC4 RC assemblies have different versions for now. So, it seems like it is now possible to contribute to aspnetwebstack and have MVC4 RC installed. But this should be temporary.

 

[1] http://aspnetwebstack.codeplex.com/discussions/354771

Jul 17, 2012 at 11:17 PM

Should this class be valid or invalid ApiController?

 

    public class GenericController<T> : ApiController
    {
    }