{"id":2508,"date":"2022-08-30T15:25:27","date_gmt":"2022-08-30T15:25:27","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/01\/27\/razor-syntax-with-errors-compiles-when-it-should-not-compile-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:25:27","modified_gmt":"2022-08-30T15:25:27","slug":"razor-syntax-with-errors-compiles-when-it-should-not-compile-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/razor-syntax-with-errors-compiles-when-it-should-not-compile-collection-of-common-programming-errors\/","title":{"rendered":"razor syntax with errors compiles when it should not compile-Collection of common programming errors"},"content":{"rendered":"<p>So I an into an error at runtime with my asp.net mvc3 app, when I checked the code I see that it has a red line on it, the <strong>error list<\/strong> says <em>there is no such function defined<\/em> but <strong>it will still compile fine<\/strong>. The error shows up only at runtime? I&#8217;m using <strong>T4MVC<\/strong> and I was hoping it would help me dodge problems like this!?<\/p>\n<p>Is this by design or am I doing something wrong here?<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/Dcghb.jpg\" \/><\/p>\n<p>The code above should NOT compile because there is no such method there!<\/p>\n<p>It fails at runtime :<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/eF7oV.jpg\" \/><\/p>\n<p>This kinda of thing happens a lot, not just for un defined methods, but even variables, etc.<\/p>\n<ol>\n<li>\n<p>This is by design. The build of of MVC views is disabled by default. You can enable the build of your MVC views in Visual Studio like that:<\/p>\n<ul>\n<li>Right click on your project in Visual Studio<\/li>\n<li><strong>Unload project<\/strong><\/li>\n<li>\n<p><strong>Edit project<\/strong><\/p>\n<\/li>\n<li>\n<p>Change the value for <strong><code>MvcBuildViews<\/code><\/strong> from false to <strong>true<\/strong><\/p>\n<p><code>...<\/code><br \/>\n<code>true<\/code><br \/>\n<code>...<\/code><\/li>\n<li>\n<p><strong>Reload project<\/strong><\/p>\n<\/li>\n<\/ul>\n<p>Next time you compile and there are errors in your MVC views, it will not compile. The downside is, the compilation process will take longer.<\/p>\n<p><strong>Update<\/strong><\/p>\n<p>Here is an answer on SO, explaining how to avoid the error:<\/p>\n<blockquote>\n<p>It is an error to use a section registered as allowDefinition=&#8217;MachineToApplication&#8217; beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS<\/p>\n<\/blockquote>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2014-01-27 08:42:38. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>So I an into an error at runtime with my asp.net mvc3 app, when I checked the code I see that it has a red line on it, the error list says there is no such function defined but it will still compile fine. The error shows up only at runtime? I&#8217;m using T4MVC and [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2508","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2508","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=2508"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2508\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=2508"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=2508"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=2508"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}