Azure 如何解决;可能的系统。NullReferenceException“;在获取令牌时
我遵循中提供的示例代码获取令牌以调用Microsoft Graph Api。但是Resharper在wait app.AcquireTokenForClient(scopes.ExecuteAsync()中建议“可能的System.NullReferenceException”;如何解决NullReference异常 克隆代码并查看“可能的System.NullReferenceException”Azure 如何解决;可能的系统。NullReferenceException“;在获取令牌时,azure,azure-active-directory,resharper,msal,Azure,Azure Active Directory,Resharper,Msal,我遵循中提供的示例代码获取令牌以调用Microsoft Graph Api。但是Resharper在wait app.AcquireTokenForClient(scopes.ExecuteAsync()中建议“可能的System.NullReferenceException”;如何解决NullReference异常 克隆代码并查看“可能的System.NullReferenceException” Resharper建议“可能的System.NullReferenceException”,知
Resharper建议“可能的System.NullReferenceException”,知道如何解决吗?处理这种情况的方法是检查null,如果是,则引发异常 假设
app
是方法的输入变量:
void Foo(IApp app) //just using IApp as an example.
{
if (app == null)
throw new ArgumentNullException(nameof(app));
var result = app.Bar(); //no possible null ref here.
}
ReSharper中启用了“悲观”值分析模式,它认为所有内容都可以为“null”,除非显式检查为null或使用“NotNull”或“ContractAnnotation”属性进行注释。
处理此情况的一些选项:
谢谢早些时候,我做了同样但同样的事情。这里的应用程序是机密客户端应用程序。请勾选Ok,在这种情况下:它应该是一个
无效操作异常
。但情况依然如此。在你使用它的第88行之前进行检查,重新竖琴的建议应该消失了。如果没有:在jetbrains/resharper上提交一个bug。感谢Stefan的帮助。
void Foo(IApp app) //just using IApp as an example.
{
if (app == null)
throw new ArgumentNullException(nameof(app));
var result = app.Bar(); //no possible null ref here.
}