.Net Core : About the problem that the contains method of getting string type through reflection reports an error "ambient match found"
During the migration of. Net framework based projects to. Net core based projects, an error of ambiguousexception was thrown in the original project:
After troubleshooting, the problem appears in the following code:
Expression.Call(left, typeof (string).GetMethod("Contains"), right)
When a program dynamically constructs a lambda expression, it needs to obtain the contains method of string type through reflection, but now the contains method seems to be missing
I tried "test".Contains("..") in the IDE, and found that not only are contains still in use, but also there are no problems when using them
Then,I found a solution through the forums.asp.net:
Expression.Call(left, typeof (string).GetMethod("Contains", new[] { typeof(string) }), right)
In other words, the type of parameter should be specified during reflection.
- Link : https://www.zdyla.com/en/post/dot-net-core-about-the-problem-that-the-contains-method-of-getting-string-type-through-reflection-reports-an-error-ambient-match-found.html
- Copyright Notice : Unless otherwise stated, please contact the author for authorization and indicate the source!