0

I have been playing around Mono and ASP.NET MVC 3 for a couple of days. It runs Razor almost fine.
When i comment or delete lines where i'm using ViewBag it works fine.
But when i want to use ViewBag it gives an exception

Invalid IL code in Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo:Create (Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfoFlags,string): method body is empty.

Description: HTTP 500. Error processing request.

Stack Trace:

System.InvalidProgramException: Invalid IL code in Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo:Create (Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfoFlags,string): method body is empty.  

NerdDinnerV3.Controllers.HomeController.Index () [0x0000a] in /home/telebovich/Projects/EmptyMvc2Application/EmptyMvc2Application/Controllers/HomeController.cs:13 at (wrapper dynamic-method) object.lambda_method     (System.Runtime.CompilerServices.Closure,System.Web.Mvc.ControllerBase,object[]) <IL 0x00006, 0x0002f>
at System.Web.Mvc.ActionMethodDispatcher.Execute (System.Web.Mvc.ControllerBase,object[]) <IL 0x00008, 0x0001b>
at System.Web.Mvc.ReflectedActionDescriptor.Execute (System.Web.Mvc.ControllerContext,System.Collections.Generic.IDictionary`2<string, object>) <IL 0x00072, 0x00103>
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod (System.Web.Mvc.ControllerContext,System.Web.Mvc.ActionDescriptor,System.Collections.Generic.IDictionary`2<string, object>) <IL 0x00003, 0x00019>
at System.Web.Mvc.ControllerActionInvoker/<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12 () <IL 0x0002d, 0x00068>
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter (System.Web.Mvc.IActionFilter,System.Web.Mvc.ActionExecutingContext,System.Func`1<System.Web.Mvc.ActionExecutedContext>) <IL 0x00031, 0x000b6>  

Stack trace is pointing out 13th line which is below:

ViewBag.Message = "Welcome to ASP.NET MVC!";  

Am i missing any assembly reference maybe?
Can you help me please?

Thank you in advance.

  • Take a look at this answer: http://stackoverflow.com/questions/4239645/does-the-razor-view-engine-work-for-mono Also I would recommend you using view models instead of ViewData/ViewBag. – Darin Dimitrov Aug 08 '11 at 17:09

3 Answers3

0

ViewBag is implemented as a dynamic and requires .NET 4.0. Is it possible you are not running your site under .NET 4.0?

mgnoonan
  • 7,060
  • 5
  • 24
  • 27
  • The OP stated that if he comments out the `ViewBag` line his ASP.NET MVC 3 Razor application works fine. An ASP.NET MVC 3 application cannot possibly work fine if he is not targeting .NET 4.0. – Darin Dimitrov Aug 08 '11 at 17:22
  • I'm not a Mono guy, but target/compile in .NET 4 doesn't mean the site's app pool is running under .NET 4. Will the site crash outright if the pool is configured for a different version? Sorry for using IIS terms when talking about Mono... – mgnoonan Aug 08 '11 at 17:35
  • no the site will not even compile. ASP.NET MVC 3 assemblies depend on .NET 4.0. – Darin Dimitrov Aug 08 '11 at 17:36
0

I am not sure why my post was deleted. I just wanted to say that I used ViewBag with mono and it worked - this can be quite important as the question can be understood as 'Does Razor works with Mono?' or - more importantly - 'Does it work with ViewBag too?'. I was also asking about versions of mono and xsp, because I had some issues which were fixed by upgrading to freshly compiled git version. To OP: please provide such information, maybe I will be able to help more.

Argie
  • 1
  • Yes, my site works with ASP.NET MVC 3 + Razor. But it doesnt work with `ViewBag`. I need to comment/delete it. – telebovich Aug 08 '11 at 19:42
  • Can you tell me, which versions you are using? – Argie Aug 08 '11 at 20:00
  • Mono Runtime Version: 2.10.2 (tarball ??? ??? 1 16:03:03 EEST 2011); ASP.NET Version: 4.0.30319.1. Ubuntu 11.04. MonoDevelop 2.4(.0?) – telebovich Aug 08 '11 at 20:15
  • I had some problems on 2.10.2 (however not exactly this). Could you upgrade to git HEAD? (Do it with Mono and xsp, if help needed, just write). – Argie Aug 08 '11 at 20:24
0

ViewBag works great foe me using Razor on Mono 2.10 running under Linux. Make sure you host it using eg. xsp4 (instead xsp2) which supports .Net/Clr 4 and therefore dynamics.

Marc
  • 4,715
  • 3
  • 27
  • 34
  • Mono 2.10.6 fixed the problem. – telebovich Dec 28 '11 at 20:10
  • I had it working with 2.10.1 (I guess) and now with 2.10.6. Nice it is fixed for you as well. Btw: what webserver did you use? xsp4, appache? for appache, njinx etc. its also important to use the version-4 module (webserver4). using xsp you need to make sure you are using xsp4 to get the .Net 4 stuff like dynamics and therefore ViewBag support. – Marc Dec 29 '11 at 06:21