You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Microsoft Visual Studio Professional 2022
Version 17.8.0 Preview 2.0
VisualStudio.17.Preview/17.8.0-pre.2.0+34112.27
Microsoft .NET Framework
Version 4.8.09037
Steps to Reproduce:
Compile the following code:
using System.Runtime.CompilerServices;
var c = new object();
c.ToString(); // fine
c?.ToString(); // error CS9151
static class Interceptors
{
[InterceptsLocation("Program.cs", 4, 3)]
[InterceptsLocation("Program.cs", 5, 4)]
public static string Interceptor1(this object obj) => "ToString call";
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
public class InterceptsLocationAttribute : Attribute
{
public InterceptsLocationAttribute(string path, int line, int character) { }
}
}
Expected Behavior:
Both invocations are intercepted
Actual Behavior:
An error is reported for the ?. invocation
Error CS9151: Possible method name 'ToString' cannot be intercepted because it is not being invoked. (10, 4)
It'd be rather strange if conditional access will not be compatible with interceptors and you'll have to fall back to good old if statements if you want to use interceptors.
Moreover, the error is very confusing - the method ToString() is obviously invoked at the given location.
I think this needs to be addressed before the interceptors feature can be considered stable. However, I moved to backlog because possible larger-scale design changes may "obsolete" this bug.
Version Used:
Steps to Reproduce:
Compile the following code:
Expected Behavior:
Both invocations are intercepted
Actual Behavior:
An error is reported for the
?.
invocationIt'd be rather strange if conditional access will not be compatible with interceptors and you'll have to fall back to good old if statements if you want to use interceptors.
Moreover, the error is very confusing - the method
ToString()
is obviously invoked at the given location.[jcouv update:] Relates to test plan #67421
The text was updated successfully, but these errors were encountered: