The following declaration causes the error:
private static IDictionary<int, string> Dic = new Dictionary<int, string>();
While the following does not:
private static IDictionary<int, string> Dic;
What the…? I know I can initialize the dictionary in a static constructor, but what I really want to use is a literal initializer (same problem).
Edit: It appears the issue is related to the static constructor. If I declare a static constructor, I get the same error. No doubt by initializing the field, the compiler generates a default static constructor. Parts of our app use reflection to select a class to instantiate — I think it may be getting confused by the static constructor method.
In fact, I can add any static field (static int i = 0;) with an initializer and get the same results. This actually has something to do with the architecture of our whole app. I am going another way with this. Thanks for all your input.
We were using Activator.CreateInstance to create instances of our presentation classes. The binding flags included a flag that turned on searching for static constructors. Removing this flag eliminated the error. As I said in the question, it seems initializing a static field will cause the compiler to generate a static construtor.