1

In a VS2017 ASP.NET MVC project I've noticed that my views aren't syntax checked on build/compile even though I have set MvcBuildViews to true. The project is now on MVC 5 but has been upgraded from some earlier version. It also started out being set to AnyCPU but it's now set to x64 (we need a lot of data in memory sometimes, and we always deploy to x64, so...).

I've checked that the .csproj contains the build target that has been mentioned in various places, including several in SO answers. I've tried a few variations, but none has worked.

This is the one that was present but commented out in the .csproj when I started investigating:

<Target Name="BuildViews" Condition="'$(MvcBuildViews)'=='true'" AfterTargets="Build">
  <Message Importance="normal" Text="Precompiling views" />
  <AspNetCompiler VirtualPath="temp" PhysicalPath="$(WebProjectOutputDir)" />
</Target>

If i uncomment it, I get a build error (I've manually translated it from Swedish):

Failed to read the file or assembly MyProjectName or one of its dependencies. An attempt to read a program with invalid format was made.

File: C:\...MyProjectPath...\ASPNETCOMPILER

It was suggested here to specify the x64 ASP.NET compiler: Add this below the <MvcBuildViews> tag:

<AspNetToolPath Condition="'$(Platform)' == 'x64'">$(windir)\Microsoft.NET\Framework64\v4.0.30319</AspNetToolPath>

And add attribute ToolPath="$(AspNetToolPath)" to the target's <AspNetCompiler.../> tag.

Doing so results in another error (again translated by me from Swedish):

Failed to read the file or assembly System.Runtime.InteropServices.RuntimeInformation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a or one of its dependencies. The found assembly's manifest definition doesn't match the assembly reference. (Exception from HRESULT: 0x80131040)

File: C:\temp\global.asax

The assembly in question is pulled into the project by our use of a Stripe card payment NuGet package, which was added after the project was changed from AnyCPU to x64. The System.Runtime.InteropServices.RuntimeInformation package is installed in version 4.3.0. The web.config contains this binding redirect (why don't the version numbers match 4.3.0?):

<dependentAssembly>
  <assemblyIdentity name="System.Runtime.InteropServices.RuntimeInformation" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
  <bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0"/>
</dependentAssembly>

At this point, I'm out of ideas, what to try next. Can anyone help?

Kjell Rilbe
  • 1,331
  • 14
  • 39

1 Answers1

0

Try to register that dll into GAC:

Try these:

1) run update-package -reinstall under Tools-->Nuget Package Manager-->Package Manager Console

2) open developer command prompt for VS as Administrator and then type:

cd C:\Users\xxx\.nuget\packages\system.runtime.interopservices.runtimeinformation\4.3.0\lib\net45

gacutil /i System.Runtime.InteropServices.RuntimeInformation.dll

Also, you can download system.runtime.interopservices.runtimeinformation nuget package version 4.0.0.

After that, register that dll under C:\Users\xxx\.nuget\packages\system.runtime.interopservices.runtimeinformation\4.0.0\lib\net45.

Besides, there is a similar issue.

Mr Qian
  • 21,064
  • 1
  • 31
  • 41
  • Unfortunately I got stuck at step 1 because the project uses a NuGet package that no longer exists (old bundler) and the new one `Microsoft.AspNet.Web.Optimization` has known bug https://stackoverflow.com/questions/28067798/system-web-optimization-jsminify-produces-invalid-javascript that took me quite a while to find. Not sure I can waste more time on it, but if/when I do, I will make sure I give feedback/accept your answer. – Kjell Rilbe Feb 19 '21 at 15:10
  • Did your issue solve? How is your question going now? If the nuget package did not exist, you should abandon it. And suggestion 2 is what I recommend to you. It should do some work. If my answer helps you handle the issue, please do not forget to accept it:) – Mr Qian Feb 21 '21 at 06:31
  • Thanks! I did try to abandon the package but got problems with the replacement due to the bug i mentioned. As things stand I can't waste more time on the precompilation issue right now, so I'm afraid it is going to take a while before I can conclude any outcome of your answers. I will update/accept when I eventuelly get there. – Kjell Rilbe Feb 22 '21 at 08:16
  • Hope your any feedback in the future. – Mr Qian Feb 23 '21 at 08:35