tags:

views:

1135

answers:

3

I'm following the ASP.Net MVC "TaskList" example video and on clicking Run in Visual Studio (~14:00 min into the video) I'm getting the following error message in the browser:

Server Error in '/' Application.

Bad IL format.
Description: An unhandled exception occurred during the execution of the 
current webrequest. Please review the stack trace for more information 
about the error andwhere it originated in the code.

Exception Details: System.BadImageFormatException: Bad IL format.

Source Error:

Line 12:         ' (2) URL with parameters
Line 13:         ' (3) Parameter defaults
Line 14:         routes.MapRoute( _
Line 15:             "Default", _
Line 16:             "{controller}/{action}/{id}", _


Source File: C:\Users\...\TaskList\TaskList\Global.asax.vb    Line: 14

Stack Trace:

[BadImageFormatException: Bad IL format.]
   VB$AnonymousType_0`3..ctor(T0 controller, T1 action, T2 id) +0
   TaskList.MvcApplication.RegisterRoutes(RouteCollection routes) in
    C:\Users\...\TaskList\TaskList\Global.asax.vb:14
   TaskList.MvcApplication.Application_Start() in
    C:\Users\...\TaskList\TaskList\Global.asax.vb:23


Version Information:
   Microsoft .NET Framework Version:2.0.50727.1434;
   ASP.NET Version:2.0.50727.1434

I've double-checked the code I've typed in, what am I missing?

Thank you!

Versions:

  • ASP.Net MVC Beta (16th October 2008)
  • Visual Studion 2008 (9.0.21022.8 RTM)
  • Vista Ultimate SP1
  • IIS 7.0.6000.16386
A: 

It seems to have something to do with your anonymous type on Line 17. Make sure you code looks like

routes.MapRoute( _
    "Default", _
    "{controller}/{action}/{id}", _
    New With { .controller = "Home", .action = "Index" }
)

If you need any further help please post your routes in Application_Start

Nick Berardi
+1  A: 

Very interesting. Could you upload the full source or compiled DLL (might have to get it out of the temporary ASP.NET folder)? I highly doubt the VB compiler should generate invalid IL under any circumstance - so you might have hit a bug in the compiler.

MichaelGG
Will do - but the code is at home so I'll post it tonight :o)
Andrew
I was about to post the code, when I found the problem - see my answer: http://stackoverflow.com/questions/215719/aspnet-mvc-error-bad-il-format#219769
Andrew
+2  A: 

D'oh!

Found the problem, it's in the HomeController.vb:

Public Class HomeController
    Inherits System.Web.Mvc.Controller

    ' Display a list of tasks
    Function Index()
        Return View()
    End Function

    ' Dislpay a form for creating a new task
    Function Create() As ActionResult
        Return View()
    End Function

    ' Adding a new task to the database
    Function CreateNew(ByVal task As String) As ActionResult
        ' add the new task to the database
        Return RedirectToAction("Index")
    End Function

    ' Mark a task as complete
    Function Complete()
        ' database logic
        Return RedirectToAction("Index")
    End Function

End Class

the Function Complete() is missing the return type, it should read:

    ' Mark a task as complete
    Function Complete() As ActionResult
        ' database logic
        Return RedirectToAction("Index")
    End Function

Thanks for the suggestions, I guess I need to tripple-check my code next time!

(though it would be nice if the compiler pointed to my code, rather than the Global.asax.vb, which made me think this was a configuration issue)

Andrew
Still that sounds like a bug if it's generating invalid IL...
MichaelGG
Agreed, where's the best place to raise this with Microsoft as a suggestion? - I've looked through http://www.asp.net/mvc and the best place seems to be the forums, but I think this is more of a bug or feature request.. any suggestions?
Andrew