MVC4 Modules

Topics: Writing modules
Mar 4, 2013 at 7:50 AM
Hi

I am completely new to Orchard, and am following through a number of older tutorials on creating modules. I've used the command line to create an empty module in an Orchard 1.6 implementation.

Where I'm confused is that web.config in the root of the module, and the one in the Views folder specifically target MVC3 and Razor 1 and I thought Orchard 1.6 was supposed to implement MVC4 and Razor 2.

I've read through the code of a number of modules in the Modules folder and they all seem to be the same MVC3/Razor1.

I'm guessing this is just a case of the command line tools not having caught up with the new stuff. Can anybody point me at a defacto set of web.configs for an MVC4/Razor2 module?

Thanks
Coordinator
Mar 4, 2013 at 9:16 AM
You don't need the local configs to point to MVC4/Razor2: the main web.config is redirecting all those to the correct versions. This enables old modules that were built against older versions to compile fine with both old and new versions of Orchard...
Mar 4, 2013 at 1:10 PM
OK - thanks. Sounds clever :-)

The reason I started this investigation is because I'm getting the following error:
ASP.NET runtime error: [A]System.Web.WebPages.Razor.Configuration.HostSection cannot be cast to [B]System.Web.WebPages.Razor.Configuration.HostSection. Type A originates from 'System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' in the context 'Default' at location 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.WebPages.Razor\v4.0_1.0.0.0__31bf3856ad364e35\System.Web.WebPages.Razor.dll'. Type B originates from 'System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' in the context 'Default' at location 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.WebPages.Razor\v4.0_2.0.0.0__31bf3856ad364e35\System.Web.WebPages.Razor.dll'. 
This made me think that it was a version conflict
Mar 4, 2013 at 1:16 PM
Is there any downside to updating the codegen to make web configs that reference 4.0? Does referencing 3.0 affect the intellisense while editing views within modules at all?
Coordinator
Mar 4, 2013 at 6:09 PM
Yes, the downside is that those modules will not be able to work with previous versions of Orchard. I think the more relevant question would be whether there are downsides to the current solution.

@eggheaddesign: your problem probably is different. From that error message, it looks like you have two different versions of MVC4 installed on your machine, which is obviously wrong (4.0_1 and 4.0_2).
Mar 4, 2013 at 7:57 PM
Edited Mar 4, 2013 at 9:44 PM
About the downsides, I was getting at that with the question about intellisense.

I'm asking out of curiosity, not implying anything needs to be done.

EDIT: More info: I had some annoyances with intellisense a while back with Visual Studio giving me warnings about some method signatures that it said didn't exist. I don't have a repro now, I have since updated to VS2012 and made other changes to my environment. I've just been wondering if that would have been fixed by assembly binding settings in my module's web.config. if so, maybe allow a command line switch to have the MVC 4.0 settings in the web.config, and make it an opt-in feature.
Mar 4, 2013 at 8:33 PM
OK - thanks. Sounds clever :-)

The reason I started this investigation is because I'm getting the following error:
ASP.NET runtime error: [A]System.Web.WebPages.Razor.Configuration.HostSection cannot be cast to [B]System.Web.WebPages.Razor.Configuration.HostSection. Type A originates from 'System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' in the context 'Default' at location 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.WebPages.Razor\v4.0_1.0.0.0__31bf3856ad364e35\System.Web.WebPages.Razor.dll'. Type B originates from 'System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' in the context 'Default' at location 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.WebPages.Razor\v4.0_2.0.0.0__31bf3856ad364e35\System.Web.WebPages.Razor.dll'. 
This made me think that it was a version conflict
Coordinator
Mar 4, 2013 at 9:59 PM
It is a version conflict, but it has nothing to do with Orchard. You have two versions of MVC 4 installed on your machine. There should be only one.