<p>I have a strange problem when I publish my website. I inherited this project and the problem started before I arrived so I don't know what conditions lead to the creation of the problem.</p>

<p>Basically, 3 folders below the website project fail to publish properly. When the PrecompiledWeb is transferred to the host these three folders have to be manually copied from the Visual Studio project (i.e. they are no longer the published versions) to the host for it to work.</p>

<p>If the results of the publish operation are left, any page in the folder results in the following error:</p>

<blockquote>
  <p>Server Error in '/' Application.
  Unable to cast object of type
  'System.Web.Compilation.BuildResultNoCompilePage'
  to type
  'System.Web.Compilation.BuildResultCompiledType'.
  Description: An unhandled exception
  occurred during the execution of the
  current web request. Please review the
  stack trace for more information about
  the error and where it originated in
  the code.</p>
  
  <p>Exception Details:
  System.InvalidCastException: Unable to
  cast object of type
  'System.Web.Compilation.BuildResultNoCompilePage'
  to type
  'System.Web.Compilation.BuildResultCompiledType'.</p>
  
  <p>Source Error:</p>
  
  <p>An unhandled exception was generated
  during the execution of the current
  web request. Information regarding the
  origin and location of the exception
  can be identified using the exception
  stack trace below.</p>
  
  <p>Stack Trace:</p>
  
  <p>[InvalidCastException: Unable to cast
  object of type
  'System.Web.Compilation.BuildResultNoCompilePage'
  to type
  'System.Web.Compilation.BuildResultCompiledType'.]
  System.Web.UI.PageParser.GetCompiledPageInstance(VirtualPath
  virtualPath, String inputFile,
  HttpContext context) +254<br>
  System.Web.UI.PageParser.GetCompiledPageInstance(String
  virtualPath, String inputFile,
  HttpContext context) +171<br>
  URLRewrite.URLRewriter.ProcessRequest(HttpContext
  context) +2183<br>
  System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
  +405    System.Web.HttpApplication.ExecuteStep(IExecutionStep
  step, Boolean&amp; completedSynchronously)
  +65</p>
  
  <p>Version Information: Microsoft .NET
  Framework Version:2.0.50727.832;
  ASP.NET Version:2.0.50727.832</p>
</blockquote>

<p>Does anyone have any idea what the possible causes of these pages not publishing correctly could be? Anything I can look at that may indicate the root of the problem?</p>

<p><strong>Addition:</strong>
It is a completely clean build each time, so there shouldn't be a problem with old bin files lying around. I've also checked the datestamp on the items in the bin folder and they are up-to-date.</p>

<p><strong>Second Addition:</strong>
The project was originally created as a <em>Web Site</em>, not a Web Application. Sorry for the ambiguity.</p>

[{'answer_id': 64105, 'author': 'Sklivvz', 'author_id': 7028, 'author_profile': 'https://Stackoverflow.com/users/7028', 'pm_score': 1, 'selected': False, 'text': '<p>I would try cleaning the bin\\ folder.\nIn any case our shop completely dropped websites in favour of web form applications, which are arguably far better.</p>\n\n<p>EDIT: <a href="http://webproject.scottgu.com/CSharp/Migration2/Migration2.aspx" rel="nofollow noreferrer">Migration HOW TO here</a></p>\n'}, {'answer_id': 64309, 'author': 'Sean Hanley', 'author_id': 7290, 'author_profile': 'https://Stackoverflow.com/users/7290', 'pm_score': 1, 'selected': False, 'text': '<p>You might look into trying Microsoft\'s <a href="http://msdn.microsoft.com/en-us/asp.net/aa336619.aspx" rel="nofollow noreferrer">Web Deployment Projects</a>.  They give you much more control over MSBuild, essentially, but it might help solve your deployment/pre-compiling woes.</p>\n\n<p>Are we to infer you are using a Web Site project type (and <em>not</em> Web Application)?</p>\n'}, {'answer_id': 73741, 'author': 'Mcbeev', 'author_id': 12762, 'author_profile': 'https://Stackoverflow.com/users/12762', 'pm_score': 1, 'selected': False, 'text': '<p>Im guessing that because when you publish, it is compiling your Web Site project and it is hitting a duplicate class name somewhere across different folders or sub folders. Make sure you check your inherit tags and class names so that you dont call 2 classes the same thing. This is fine and wont error when it happens in different folders when coding and debugging, but when you go to publish / deploy it will error. ... Hope that makes sense.</p>\n'}, {'answer_id': 1123019, 'author': 'Mircea Grelus', 'author_id': 119138, 'author_profile': 'https://Stackoverflow.com/users/119138', 'pm_score': 0, 'selected': False, 'text': '<p>I had a similar problem a while back, where the publish would say it was successful, but the publish folder remained empty.</p>\n\n<p>Besides looking at the <a href="http://msdn.microsoft.com/en-us/asp.net/aa336619.aspx" rel="nofollow noreferrer">Web Deployment Projects</a> you should also set the verbosity to Diagnostic (Tools=> Options=>Project and Solutions =>Build and Run=> Msbuild project build output verbosity)</p>\n\n<p>This, in my case had the effect of displaying meaningful compiler errors that helped me resolve the issue. </p>\n\n<p>You could then also run the <code>aspnet_compiler</code> with the <code>-errorstack</code> directive in the shell prompt to display additional errors.</p>\n'}, {'answer_id': 32035009, 'author': 'Abhilash Thomas', 'author_id': 1716548, 'author_profile': 'https://Stackoverflow.com/users/1716548', 'pm_score': 0, 'selected': False, 'text': '<p>The best answer for this please open you web.config file and add below two setting add in the compilation tag</p>\n\n<pre><code>&lt;compilation targetFramework="4.0" debug="false" batch="false"&gt;\n</code></pre>\n\n<p>Keep coidng, Also i tried following things when i get the same error in my application which i tried to host in the server</p>\n\n<p>1.Click Start, click Run, type iisreset /stop, and then click OK. </p>\n\n<p>2.Open the C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\Temporary ASP.NET Files directory.</p>\n\n<p>3.Delete all files and all folders in the directory that you located in step </p>\n\n<p>4.Click Start, click Run, type iisreset /start, and then click OK. </p>\n\n<p>5.Do a build again and then try to access your site. </p>\n'}]
['https://Stackoverflow.com/questions/64046', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/8152/']