I am currently getting the following error when trying to access the "RemoteGateways" Properties:
Here is the call where it is failing
And here is the property:
Would anyone know how this exception is caused/how it can be fixed? We didn't change anything about those properties, so what could cause this error to suddenly start happening?
Thanks in advance!
UPDATE:
I found that the change that broke it was changing const fields to static readonly:
Reverting these changes fixed the issue! However, I am still unsure why. So the second part of the question is answered. But I still would like to know why that breaks it?
The GetRawConstantValue method will try to retrieve the value from the Constant metadata table of the assembly. When using static readonly, there will be no entry in that table and therefore throw an InvalidOperationException (You can inspect the metadata with a disassembler such as dotPeek.)
You could use the GetValue method instead.
Besides what Pedro says, that is correct, you should not use reflection for that purpose, it creates unnecessary delay.
You should instead have an HashSet with the fixed values, that will make getting the value and the contains much faster.