0

I have an MVC 5 web application that I'd prefer to save time with startup by pre-compiling on publication. However, when I choose "Precompile during publishing", I get the following Error:

Error   5082    Could not load file or assembly 'DotNetOpenAuth.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=2780ccd10d57b246' 
or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040).
error ASPRUNTIME    0   0   USIS

The Web.Config Does have a binding redirect for this Reference

  <dependentAssembly>
    <assemblyIdentity name="DotNetOpenAuth.Core" publicKeyToken="2780CCD10D57B246" culture="neutral" />
    <bindingRedirect oldVersion="1.0.0.0-4.1.0.0" newVersion="4.1.0.0" />
  </dependentAssembly>

This builds and deploys fine if I do not have this precompile option checked, and the Web is working fine without issues. I just cannot publish with this precompile option checked.

I'd really like to have the website compile all views and etc only on publish, and never recompile in the live production site. Some Documentation I was looking at was suggesting this was the propose of these features... but I'm having no luck.

EDIT: I have had some success. I realized that I was purposely not deploying the Web.Config file such that a developer doesn't accidently harm the production environment configuration, but it appears that the precompile build was copying files to a temporary location, and without the Web.Config file being deployed, no Web.Config file was there, meaning no Dependency translations.

So, Now it looks like I'm going to have to deploy the Web.Config if I want to pre-compile (I had set its Build Action from "Content" to "None", and now I've set it back again.) This means I'm going to need to look into Web.Config Transformations, or etc.

Thanks, Greg

Greg
  • 2,410
  • 21
  • 26

2 Answers2

0

The only thing precompilation does is compile the views. The fact that this happens only when precompilation is set means that there's something in one of your views that is generating this error. That's kind of irrelevant, though.

The best way I've found to correct this particular error is to uninstall and reinstall the offending Nuget package.

Just go into the Package Manager Console, make sure the project that generates the error is selected for "Default Project", and then run:

> Uninstall-Package DotNetOpenAuth.Core -Force
> Install-Package DotNetOpenAuth.Core

That should resolve the issue and allow your site to publish and run fine, with or without precompilation.

Chris Pratt
  • 232,153
  • 36
  • 385
  • 444
  • Good advice perhaps for most. I discovered that by not publishing the Web.config file, a personal choice, that such was never copied to the temporary location, hence the binding redirects were not being made, and simplying including this made the pre-compilations succeeded. – Greg Feb 12 '15 at 20:51
0

Solution: It turns out that since I wasn't publishing the Web.config file, that the binding redirects were not being made. The solution was to change this file back to being published (Build Action from "None" to "Content"), and then the pre-compilation was succeeding.

For others with an MVC or ASP.NET web site that runs slow each time hitting a new page/view, I'd recommend giving this pre-compilation feature with publishing a try. It's just hidden under file options in the publication settings (VS 2012.) I chose to Precompile, and to make the site not-updatable to avoid the dynamic view/page compilations. See for more information: What effect does the new precompile during publishing option have on MVC4 applications? .

Also, to push the correct settings and connection strings to Live and Test I started using the Translation Templates "Web.Release.config" and "Web.Debug.config". These will swap out Web.config lines when deploying only. See http://go.microsoft.com/fwlink/?LinkId=125889 for more information.

Community
  • 1
  • 1
Greg
  • 2,410
  • 21
  • 26
  • I recently had another problem with precompile on publish. I was getting a CS1528, because a view had "ViewBag.En" on a code line. Clearly someone started typing something that they never finished (and checked in), but it builds and other pages run fine locally when you aren't trying to pre-compile the views... – Greg Mar 20 '15 at 17:10
  • So, if you've been able to publish precompiled previously, and suddenly it starts having problems, consider the fact that the precompile on publish compile errors are very likely within your views. The Likely culprit is then likely in the same folder as the last precompiled item, or in the following folder. – Greg Mar 20 '15 at 17:14