RuntimeBinderException: The best overloaded method match for 'Microsoft.AspNetCore.DataProtection.IDataProtector.Protect(byte[])' has some invalid arguments

Question: How do you solve the error:

RuntimeBinderException: The best overloaded method match for 'Microsoft.AspNetCore.DataProtection.IDataProtector.Protect(byte[])' has some invalid arguments

Solution: This error happens when you passed in dynamic IList content. The compilation might pass but the runtime might have errors passing the code.
- In order to resolve this issue, extract the content you want to protect into a separate variable then pass that variable into a Protect() function.

- If you haven't registered the Service you might get an error that says: InvalidOperationException: No service for type 'Microsoft.AspNetCore.DataProtection.IDataProtector' has been registered.
 This is because you can not inject an IDataProtector in the View, the way you use DataProtection is by Protecting and then Unprotecting the variable in the same function that protected it.


Edit this Article
.Net5 asp.net core 3.1 Technology published
Was this page helpful?
Yes Yes! this solution to the problem was helpful. No No! this solution to the problem was not helpful.. Leave ErnesTech Feedback.Feedback
If you log in, you will be notified when someone leaves a comment.

Other users would like to know if this solution helped you.

Your Session is Ending
Login to Continue

© 2021 - ErnesTech - Privacy