U4-7734 - Models Builder - YSOD with custom models (non Model Builder models)

Created by Shannon Deminick 14 Jan 2016, 10:17:07 Updated by Shannon Deminick 15 Jan 2016, 16:09:42

Tags: ModelsBuilder

Relates to: U4-7737

Relates to: U4-7731

For example, Articulate uses it's own custom models but when using Articulate a YSOD occurs. I'm presuming this is because of Model Builder's custom View Engine trying to force lookup models in it's own namespace.

The YSOD that occurs when rendering an Articulate page is:

Server Error in '/' Application.

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 

Compiler Error Message: CS0426: The type name 'Models' does not exist in the type 'Umbraco.Web.PublishedContentModels.Articulate'

Source error:

Line 40:     
Line 41:     
Line 42:     public class _Page_App_Plugins_Articulate_Themes_Shazwazza_Views_Partials_Recent_cshtml : UmbracoViewPage<Articulate.Models.IMasterModel> {
Line 43:         
Line 44: #line hidden

Source File: c:\Users\Shannon\AppData\Local\Temp\Temporary ASP.NET Files\vs\6eed43c1\5792fca4\App_Web_recent.cshtml.63863934.l3yoqlkv.0.cs    Line: 42 

The View Engine seems to be wanting to force the model: Umbraco.Web.PublishedContentModels.Articulate which doesn't exist, it seems to be specifically looking for a model in this namespace: Umbraco.Web.PublishedContentModels

Comments

Stephan 14 Jan 2016, 10:29:36

The view engine is not "forcing" the model, it's just compiling the view using Roslyn. What happens here IIC is that (1) there is an Articulate class in Umbraco.Web.PublishedContentModels and that class does not have a Models member and (2) there is an Articulate full or partial namespace or something, that has a Models member. And the compiler tries to resolve the ambiguity (which Articulate are we talking about) as best as it can - and here it picks the one from (1) and fails.

Would fix by replacing Articulate.Models.IMasterModel by Path.To.Articulate.Models.IMasterModel

Making sense?


Shannon Deminick 14 Jan 2016, 10:44:14

It's because the custom view engine is adding a custom using namespace. This is the compiler output giving the error:

Line 1:    #pragma checksum "X:\Projects\Umbraco\Umbraco_7.4\src\Umbraco.Web.UI\App_Plugins\Articulate\Themes\Shazwazza\Views\Partials\Recent.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "8F09B26B12000C0E7070D9C4D23D54E93068B209"
Line 2:    //------------------------------------------------------------------------------
Line 3:    // <auto-generated>
Line 4:    //     This code was generated by a tool.
Line 5:    //     Runtime Version:4.0.30319.42000
Line 6:    //
Line 7:    //     Changes to this file may cause incorrect behavior and will be lost if
Line 8:    //     the code is regenerated.
Line 9:    // </auto-generated>
Line 10:   //------------------------------------------------------------------------------
Line 11:   
Line 12:   namespace ASP {
Line 13:       using System;
Line 14:       using System.Collections.Generic;
Line 15:       using System.IO;
Line 16:       using System.Linq;
Line 17:       using System.Net;
Line 18:       using System.Web;
Line 19:       using System.Web.Helpers;
Line 20:       using System.Web.Security;
Line 21:       using System.Web.UI;
Line 22:       using System.Web.WebPages;
Line 23:       using System.Web.Mvc;
Line 24:       using System.Web.Mvc.Ajax;
Line 25:       using System.Web.Mvc.Html;
Line 26:       using System.Web.Routing;
Line 27:       using Umbraco.Web;
Line 28:       using Umbraco.Core;
Line 29:       using Umbraco.Core.Models;
Line 30:       using Umbraco.Web.Mvc;
Line 31:       using umbraco;
Line 32:       using Examine;
Line 33:       
Line 34:       #line 1 "X:\Projects\Umbraco\Umbraco_7.4\src\Umbraco.Web.UI\App_Plugins\Articulate\Themes\Shazwazza\Views\Partials\Recent.cshtml"
Line 35:       using Articulate;
Line 36:       
Line 37:       #line default
Line 38:       #line hidden
Line 39:       using Umbraco.Web.PublishedContentModels;
Line 40:       
Line 41:       
Line 42:       public class _Page_App_Plugins_Articulate_Themes_Shazwazza_Views_Partials_Recent_cshtml : UmbracoViewPage<Articulate.Models.IMasterModel> {
Line 43:           
Line 44:   #line hidden
Line 45:           
Line 46:           public _Page_App_Plugins_Articulate_Themes_Shazwazza_Views_Partials_Recent_cshtml() {
Line 47:           }
Line 48:           
Line 49:           protected ASP.global_asax ApplicationInstance {
Line 50:               get {
Line 51:                   return ((ASP.global_asax)(Context.ApplicationInstance));
Line 52:               }
Line 53:           }
Line 54:           
Line 55:           public override void Execute() {
Line 56:               
Line 57:               #line 4 "X:\Projects\Umbraco\Umbraco_7.4\src\Umbraco.Web.UI\App_Plugins\Articulate\Themes\Shazwazza\Views\Partials\Recent.cshtml"
Line 58:     
Line 59:       var recent = Umbraco.GetRecentPosts(Model, 5);
Line 60:   
Line 61:               
Line 62:               #line default
Line 63:               #line hidden
Line 64:   BeginContext("~/App_Plugins/Articulate/Themes/Shazwazza/Views/Partials/Recent.cshtml", 137, 8, true);
Line 65:   
Line 66:   WriteLiteral("\r\n\r\n<div");
Line 67:   
Line 68:   EndContext("~/App_Plugins/Articulate/Themes/Shazwazza/Views/Partials/Recent.cshtml", 137, 8, true);
Line 69:   
Line 70:   BeginContext("~/App_Plugins/Articulate/Themes/Shazwazza/Views/Partials/Recent.cshtml", 145, 27, true);
Line 71:   
Line 72:   WriteLiteral(" class=\"widget recentposts\"");
Line 73:   
Line 74:   EndContext("~/App_Plugins/Articulate/Themes/Shazwazza/Views/Partials/Recent.cshtml", 145, 27, true);
Line 75:   
Line 76:   BeginContext("~/App_Plugins/Articulate/Themes/Shazwazza/Views/Partials/Recent.cshtml", 172, 40, true);
Line 77:   
Line 78:   WriteLiteral(">\r\n    <h4>Recent posts</h4>\r\n\r\n    <div");
Line 79:   
Line 80:   EndContext("~/App_Plugins/Articulate/Themes/Shazwazza/Views/Partials/Recent.cshtml", 172, 40, true);
Line 81:   
Line 82:   BeginContext("~/App_Plugins/Articulate/Themes/Shazwazza/Views/Partials/Recent.cshtml", 212, 16, true);
Line 83:   
Line 84:   WriteLiteral(" class=\"content\"");
Line 85:   
Line 86:   EndContext("~/App_Plugins/Articulate/Themes/Shazwazza/Views/Partials/Recent.cshtml", 212, 16, true);
Line 87:   
Line 88:   BeginContext("~/App_Plugins/Articulate/Themes/Shazwazza/Views/Partials/Recent.cshtml", 228, 14, true);
Line 89:   
Line 90:   WriteLiteral(">\r\n        <ul");
Line 91:   
Line 92:   EndContext("~/App_Plugins/Articulate/Themes/Shazwazza/Views/Partials/Recent.cshtml", 228, 14, true);
Line 93:   
Line 94:   BeginContext("~/App_Plugins/Articulate/Themes/Shazwazza/Views/Partials/Recent.cshtml", 242, 20, true);
Line 95:   
Line 96:   WriteLiteral(" class=\"recentPosts\"");
Line 97:   
Line 98:   EndContext("~/App_Plugins/Articulate/Themes/Shazwazza/Views/Partials/Recent.cshtml", 242, 20, true);
Line 99:   
Line 100:  BeginContext("~/App_Plugins/Articulate/Themes/Shazwazza/Views/Partials/Recent.cshtml", 262, 17, true);
Line 101:  
Line 102:  WriteLiteral(" id=\"recentPosts\"");
Line 103:  
Line 104:  EndContext("~/App_Plugins/Articulate/Themes/Shazwazza/Views/Partials/Recent.cshtml", 262, 17, true);
Line 105:  
Line 106:  BeginContext("~/App_Plugins/Articulate/Themes/Shazwazza/Views/Partials/Recent.cshtml", 279, 3, true);
Line 107:  
Line 108:  WriteLiteral(">\r\n");
Line 109:  
Line 110:  EndContext("~/App_Plugins/Articulate/Themes/Shazwazza/Views/Partials/Recent.cshtml", 279, 3, true);
Line 111:  
Line 112:              
Line 113:              #line 13 "X:\Projects\Umbraco\Umbraco_7.4\src\Umbraco.Web.UI\App_Plugins\Articulate\Themes\Shazwazza\Views\Partials\Recent.cshtml"
Line 114:              
Line 115:              
Line 116:              #line default
Line 117:              #line hidden
Line 118:              
Line 119:              #line 13 "X:\Projects\Umbraco\Umbraco_7.4\src\Umbraco.Web.UI\App_Plugins\Articulate\Themes\Shazwazza\Views\Partials\Recent.cshtml"
Line 120:               foreach (var post in recent)
Line 121:              {
Line 122:  
Line 123:              
Line 124:              #line default
Line 125:              #line hidden
Line 126:  BeginContext("~/App_Plugins/Articulate/Themes/Shazwazza/Views/Partials/Recent.cshtml", 340, 22, true);
Line 127:  
Line 128:  WriteLiteral("                <li>\r\n");
Line 129:  
Line 130:  EndContext("~/App_Plugins/Articulate/Themes/Shazwazza/Views/Partials/Recent.cshtml", 340, 22, true);
Line 131:  
Line 132:              
Line 133:              #line 16 "X:\Projects\Umbraco\Umbraco_7.4\src\Umbraco.Web.UI\App_Plugins\Articulate\Themes\Shazwazza\Views\Partials\Recent.cshtml"
Line 134:                      
Line 135:              
Line 136:              #line default
Line 137:              #line hidden
Line 138:              
Line 139:              #line 16 "X:\Projects\Umbraco\Umbraco_7.4\src\Umbraco.Web.UI\App_Plugins\Articulate\Themes\Shazwazza\Views\Partials\Recent.cshtml"
Line 140:                       if (!post.PostImageUrl.IsNullOrWhiteSpace())
Line 141:                      {
Line 142:                          var thumbnail = post.GetCropUrl("postImage", "thumbnail");
Line 143:                          if (!thumbnail.IsNullOrWhiteSpace())
Line 144:                          {
Line 145:  
Line 146:              
Line 147:              #line default
Line 148:              #line hidden
Line 149:  BeginContext("~/App_Plugins/Articulate/Themes/Shazwazza/Views/Partials/Recent.cshtml", 625, 32, true);
Line 150:  
Line 151:  WriteLiteral("                            <img");
Line 152:  
Line 153:  EndContext("~/App_Plugins/Articulate/Themes/Shazwazza/Views/Partials/Recent.cshtml", 625, 32, true);
Line 154:  
Line 155:  BeginContext("~/App_Plugins/Articulate/Themes/Shazwazza/Views/Partials/Recent.cshtml", 657, 14, true);
Line 156:  
Line 157:  WriteLiteral(" class=\"thumb\"");
Line 158:  
Line 159:  EndContext("~/App_Plugins/Articulate/Themes/Shazwazza/Views/Partials/Recent.cshtml", 657, 14, true);
Line 160:  
Line 161:  WriteAttribute("src", Tuple.Create(" src=\"", 671), Tuple.Create("\"", 687)
Line 162:              
Line 163:              #line 21 "X:\Projects\Umbraco\Umbraco_7.4\src\Umbraco.Web.UI\App_Plugins\Articulate\Themes\Shazwazza\Views\Partials\Recent.cshtml"
Line 164:  , Tuple.Create(Tuple.Create("", 677), Tuple.Create<System.Object, System.Int32>(thumbnail
Line 165:              
Line 166:              #line default
Line 167:              #line hidden
Line 168:  , 677), false)
Line 169:  );
Line 170:  
Line 171:  WriteAttribute("alt", Tuple.Create(" alt=\"", 688), Tuple.Create("\"", 704)
Line 172:              
Line 173:              #line 21 "X:\Projects\Umbraco\Umbraco_7.4\src\Umbraco.Web.UI\App_Plugins\Articulate\Themes\Shazwazza\Views\Partials\Recent.cshtml"
Line 174:  , Tuple.Create(Tuple.Create("", 694), Tuple.Create<System.Object, System.Int32>(post.Name
Line 175:              
Line 176:              #line default
Line 177:              #line hidden
Line 178:  , 694), false)
Line 179:  );
Line 180:  
Line 181:  BeginContext("~/App_Plugins/Articulate/Themes/Shazwazza/Views/Partials/Recent.cshtml", 705, 5, true);
Line 182:  
Line 183:  WriteLiteral(" />\r\n");
Line 184:  
Line 185:  EndContext("~/App_Plugins/Articulate/Themes/Shazwazza/Views/Partials/Recent.cshtml", 705, 5, true);
Line 186:  
Line 187:              
Line 188:              #line 22 "X:\Projects\Umbraco\Umbraco_7.4\src\Umbraco.Web.UI\App_Plugins\Articulate\Themes\Shazwazza\Views\Partials\Recent.cshtml"
Line 189:                          }
Line 190:                      }
Line 191:  
Line 192:              
Line 193:              #line default
Line 194:              #line hidden
Line 195:  BeginContext("~/App_Plugins/Articulate/Themes/Shazwazza/Views/Partials/Recent.cshtml", 760, 24, true);
Line 196:  
Line 197:  WriteLiteral("                    <div");
Line 198:  
Line 199:  EndContext("~/App_Plugins/Articulate/Themes/Shazwazza/Views/Partials/Recent.cshtml", 760, 24, true);
Line 200:  
Line 201:  BeginContext("~/App_Plugins/Articulate/Themes/Shazwazza/Views/Partials/Recent.cshtml", 784, 13, true);
Line 202:  
Line 203:  WriteLiteral(" class=\"time\"");
Line 204:  
Line 205:  EndContext("~/App_Plugins/Articulate/Themes/Shazwazza/Views/Partials/Recent.cshtml", 784, 13, true);
Line 206:  
Line 207:  BeginContext("~/App_Plugins/Articulate/Themes/Shazwazza/Views/Partials/Recent.cshtml", 797, 32, true);
Line 208:  
Line 209:  WriteLiteral(">\r\n                        <time");
Line 210:  
Line 211:  EndContext("~/App_Plugins/Articulate/Themes/Shazwazza/Views/Partials/Recent.cshtml", 797, 32, true);
Line 212:  
Line 213:  WriteAttribute("datetime", Tuple.Create(" datetime=\"", 829), Tuple.Create("\"", 859)
Line 214:              
Line 215:              #line 25 "X:\Projects\Umbraco\Umbraco_7.4\src\Umbraco.Web.UI\App_Plugins\Articulate\Themes\Shazwazza\Views\Partials\Recent.cshtml"
Line 216:  , Tuple.Create(Tuple.Create("", 840), Tuple.Create<System.Object, System.Int32>(post.PublishedDate
Line 217:              
Line 218:              #line default
Line 219:              #line hidden
Line 220:  , 840), false)
Line 221:  );
Line 222:  
Line 223:  BeginContext("~/App_Plugins/Articulate/Themes/Shazwazza/Views/Partials/Recent.cshtml", 860, 3, true);
Line 224:  
Line 225:  WriteLiteral(">\r\n");
Line 226:  
Line 227:  EndContext("~/App_Plugins/Articulate/Themes/Shazwazza/Views/Partials/Recent.cshtml", 860, 3, true);
Line 228:  
Line 229:  BeginContext("~/App_Plugins/Articulate/Themes/Shazwazza/Views/Partials/Recent.cshtml", 863, 28, true);
Line 230:  
Line 231:  WriteLiteral("                            ");
Line 232:  
Line 233:  EndContext("~/App_Plugins/Articulate/Themes/Shazwazza/Views/Partials/Recent.cshtml", 863, 28, true);
Line 234:  
Line 235:  BeginContext("~/App_Plugins/Articulate/Themes/Shazwazza/Views/Partials/Recent.cshtml", 892, 48, false);
Line 236:  
Line 237:              
Line 238:              #line 26 "X:\Projects\Umbraco\Umbraco_7.4\src\Umbraco.Web.UI\App_Plugins\Articulate\Themes\Shazwazza\Views\Partials\Recent.cshtml"
Line 239:                         Write(post.PublishedDate.ToString("MMM d, yyyy HH:mm"));
Line 240:  
Line 241:              
Line 242:              #line default
Line 243:              #line hidden
Line 244:  EndContext("~/App_Plugins/Articulate/Themes/Shazwazza/Views/Partials/Recent.cshtml", 892, 48, false);
Line 245:  
Line 246:  BeginContext("~/App_Plugins/Articulate/Themes/Shazwazza/Views/Partials/Recent.cshtml", 940, 87, true);
Line 247:  
Line 248:  WriteLiteral("\r\n                        </time>\r\n                    </div>\r\n\r\n                " +
Line 249:  "    <a");
Line 250:  
Line 251:  EndContext("~/App_Plugins/Articulate/Themes/Shazwazza/Views/Partials/Recent.cshtml", 940, 87, true);
Line 252:  
Line 253:  WriteAttribute("href", Tuple.Create(" href=\"", 1027), Tuple.Create("\"", 1043)
Line 254:              
Line 255:              #line 30 "X:\Projects\Umbraco\Umbraco_7.4\src\Umbraco.Web.UI\App_Plugins\Articulate\Themes\Shazwazza\Views\Partials\Recent.cshtml"
Line 256:  , Tuple.Create(Tuple.Create("", 1034), Tuple.Create<System.Object, System.Int32>(post.Url
Line 257:              
Line 258:              #line default
Line 259:              #line hidden
Line 260:  , 1034), false)
Line 261:  );
Line 262:  
Line 263:  BeginContext("~/App_Plugins/Articulate/Themes/Shazwazza/Views/Partials/Recent.cshtml", 1044, 1, true);
Line 264:  
Line 265:  WriteLiteral(">");
Line 266:  
Line 267:  EndContext("~/App_Plugins/Articulate/Themes/Shazwazza/Views/Partials/Recent.cshtml", 1044, 1, true);
Line 268:  
Line 269:  BeginContext("~/App_Plugins/Articulate/Themes/Shazwazza/Views/Partials/Recent.cshtml", 1046, 9, false);
Line 270:  
Line 271:              
Line 272:              #line 30 "X:\Projects\Umbraco\Umbraco_7.4\src\Umbraco.Web.UI\App_Plugins\Articulate\Themes\Shazwazza\Views\Partials\Recent.cshtml"
Line 273:                                     Write(post.Name);
Line 274:  
Line 275:              
Line 276:              #line default
Line 277:              #line hidden
Line 278:  EndContext("~/App_Plugins/Articulate/Themes/Shazwazza/Views/Partials/Recent.cshtml", 1046, 9, false);
Line 279:  
Line 280:  BeginContext("~/App_Plugins/Articulate/Themes/Shazwazza/Views/Partials/Recent.cshtml", 1055, 59, true);
Line 281:  
Line 282:  WriteLiteral("</a>\r\n                    <div>\r\n                        <a");
Line 283:  
Line 284:  EndContext("~/App_Plugins/Articulate/Themes/Shazwazza/Views/Partials/Recent.cshtml", 1055, 59, true);
Line 285:  
Line 286:  BeginContext("~/App_Plugins/Articulate/Themes/Shazwazza/Views/Partials/Recent.cshtml", 1114, 25, true);
Line 287:  
Line 288:  WriteLiteral(" data-disqus-identifier=\"");
Line 289:  
Line 290:  EndContext("~/App_Plugins/Articulate/Themes/Shazwazza/Views/Partials/Recent.cshtml", 1114, 25, true);
Line 291:  
Line 292:  BeginContext("~/App_Plugins/Articulate/Themes/Shazwazza/Views/Partials/Recent.cshtml", 1140, 14, false);
Line 293:  
Line 294:              
Line 295:              #line 32 "X:\Projects\Umbraco\Umbraco_7.4\src\Umbraco.Web.UI\App_Plugins\Articulate\Themes\Shazwazza\Views\Partials\Recent.cshtml"
Line 296:                                                Write(Model.GetKey());
Line 297:  
Line 298:              
Line 299:              #line default
Line 300:              #line hidden
Line 301:  EndContext("~/App_Plugins/Articulate/Themes/Shazwazza/Views/Partials/Recent.cshtml", 1140, 14, false);
Line 302:  
Line 303:  BeginContext("~/App_Plugins/Articulate/Themes/Shazwazza/Views/Partials/Recent.cshtml", 1154, 1, true);
Line 304:  
Line 305:  WriteLiteral("\"");
Line 306:  
Line 307:  EndContext("~/App_Plugins/Articulate/Themes/Shazwazza/Views/Partials/Recent.cshtml", 1154, 1, true);
Line 308:  
Line 309:  BeginContext("~/App_Plugins/Articulate/Themes/Shazwazza/Views/Partials/Recent.cshtml", 1155, 22, true);
Line 310:  
Line 311:  WriteLiteral(" class=\"comment-count\"");
Line 312:  
Line 313:  EndContext("~/App_Plugins/Articulate/Themes/Shazwazza/Views/Partials/Recent.cshtml", 1155, 22, true);
Line 314:  
Line 315:  WriteAttribute("href", Tuple.Create(" href=\"", 1177), Tuple.Create("\"", 1207)
Line 316:              
Line 317:              #line 32 "X:\Projects\Umbraco\Umbraco_7.4\src\Umbraco.Web.UI\App_Plugins\Articulate\Themes\Shazwazza\Views\Partials\Recent.cshtml"
Line 318:                  , Tuple.Create(Tuple.Create("", 1184), Tuple.Create<System.Object, System.Int32>(post.Url
Line 319:              
Line 320:              #line default
Line 321:              #line hidden
Line 322:  , 1184), false)
Line 323:  , Tuple.Create(Tuple.Create("", 1193), Tuple.Create("#disqus_thread", 1193), true)
Line 324:  );
Line 325:  
Line 326:  BeginContext("~/App_Plugins/Articulate/Themes/Shazwazza/Views/Partials/Recent.cshtml", 1208, 58, true);
Line 327:  
Line 328:  WriteLiteral("></a>\r\n                    </div>\r\n                </li>\r\n");
Line 329:  
Line 330:  EndContext("~/App_Plugins/Articulate/Themes/Shazwazza/Views/Partials/Recent.cshtml", 1208, 58, true);
Line 331:  
Line 332:              
Line 333:              #line 35 "X:\Projects\Umbraco\Umbraco_7.4\src\Umbraco.Web.UI\App_Plugins\Articulate\Themes\Shazwazza\Views\Partials\Recent.cshtml"
Line 334:              }
Line 335:  
Line 336:              
Line 337:              #line default
Line 338:              #line hidden
Line 339:  BeginContext("~/App_Plugins/Articulate/Themes/Shazwazza/Views/Partials/Recent.cshtml", 1281, 33, true);
Line 340:  
Line 341:  WriteLiteral("        </ul>\r\n    </div>\r\n</div>");
Line 342:  
Line 343:  EndContext("~/App_Plugins/Articulate/Themes/Shazwazza/Views/Partials/Recent.cshtml", 1281, 33, true);
Line 344:  
Line 345:          }
Line 346:      }
Line 347:  }
Line 348:  

Pretty sure the error occurs because of this include:

Line 39:       using Umbraco.Web.PublishedContentModels;

Not sure where this using clause is coming from, it must be part of the view engine or similar. Can we have it not inject namespaces and just use the fully qualified model type?


Stephan 14 Jan 2016, 10:49:14

IIRC (checking now) the include is injected because that namespace is added to the list of namespaces in web.config. Per's intention was that when you write a view, you can reference your models without explicitely @using the models namespace. We can get rid of it, I actually would be happy to get rid of it, only it means users must explicitely @using the models namespace. Which might be fine.


Stephan 15 Jan 2016, 11:26:29

Details: was injected by code, has been commented out as it was causing too many issues, see https://github.com/zpqrtbnk/Zbu.ModelsBuilder/commit/36e8ac02636056d73aeb539a6e12b992906967ad - fixed.


Priority: Normal

Type: Bug

State: Fixed

Assignee:

Difficulty: Normal

Category:

Backwards Compatible: True

Fix Submitted:

Affected versions: 7.4.0

Due in version: 7.4.0

Sprint: Sprint 6, Sprint 7

Story Points:

Cycle: