In my company MVC project, after receiving the project, I found out that many reference are added that are unnecessary or related to other framework (.NET Core)... after lots of ups and downs, updating package.config to package reference in *.csproj, and in the end running project, I start seeing a same error.
for my project template, I checked current version, I had runtime reference, but I find nothing related to webconfig that assign version or set hash,... and it wouldn't work until I found this missing in my web.config file in the file history:
<configuration> <!-- ...(for me it was at the end of file... --> <system.codedom> <compilers> <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701" /> <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+" /> </compilers> </system.codedom> </configuration>
Also be wary of DotNetCompilerPlatform version, as I had a bad exprience years ago, around 2017, regarding the version of packages that could only publish with specific version of VS.
NOTE:
I didn't add any reference to Runtime in my web.config but I have it in my *.csproj:
*.csproj or package.config
... <!-- Existing packages --> <PackageReference Include="System.Runtime" Version="4.3.0" /> <PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.0.0" /> <PackageReference Include="System.Runtime.Extensions" Version="4.3.0" /> <PackageReference Include="System.Runtime.InteropServices" Version="4.3.0" /> <PackageReference Include="System.Runtime.InteropServices.RuntimeInformation" Version="4.3.0" /> <PackageReference Include="System.Runtime.Numerics" Version="4.3.0" /> ...
web.config
... <runtime> <!-- Existing assemblyBinding --> <!-- nothing here regarding `runtime` --> </runtime> ...