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


Please Login to see the rest of the answer

Answer: 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.


Write an Article
If you log in, you will be notified when someone leaves a comment.

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


© 2022 - ErnesTech - Privacy