I noticed this issue only happens when I used "local const" in the code, specifically when const type is an enum from another assembly.
For example, this method:
public static bool IsMatch(string text, string pattern, CompareInfo compareInfo)
{
const CompareOptions options = CompareOptions.IgnoreSymbols | CompareOptions.StringSort | CompareOptions.IgnoreNonSpace;
return compareInfo.Compare(text, pattern, options) == 0;
}
Simply replacing const CompareOptions options with CompareOptions options will fix the problem, so we have a workaround, though this bug is confusing.
Repro project (both dll project and executable console app):
ClassLibrary1.zip