How to fix RazorEngine issue with Html.HiddenFor

400 Views Asked by At

asp.net mvc4 app, targetting .NET framework 4.5.2, working with VS 2019

I am getting a CS0012 error on a razor page at @Html.HiddenFor(x => x.InvoiceId)

error message

pointing to the missing assembly reference 'System.Core'.

The strange thing is, that the error only pops up when the page is opened the VS solution explorer but the solution compiles and runs without error!

I do not have a reference to 'System.Core' in my project and from posts I learned that it is referenced internally. So I changed the key for PublicKeyToken as suggested in the error message but that did not remove the error and caused a runtime error.

Then I used the workaround posted by Serge

<input type="hidden" value="@Html.AttributeEncode(Model.InvoiceId)" id="InvoiceId" name="InvoiceId" />

which works properly.

But I would like to find out what causes this error and how to remove it.

Help and suggestions will be gratefully appreciated.

1

There are 1 best solutions below

0
On BEST ANSWER

I found this answer by warabino:

And what I did was that I copied that dll from C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.6.1\System.Core.dll and I pasted these lib into my project bin. Later u can see that inside your project the dll is added automatically in the reference.

I did alike (using the dll from C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5) and that solved the issue.

However, I do not know whether the dll (and its reference) was present in my project before and got lost or became necessary after some updates I made.