Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP Fix Exception when trying to analyze custom attribute that is being defined in different file #995

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions Rules/UseShouldProcessCorrectly.cs
Original file line number Diff line number Diff line change
Expand Up @@ -312,17 +312,27 @@ private bool SupportsShouldProcess(string cmdName)
var funcInfo = cmdInfo as FunctionInfo;
if (funcInfo != null
&& funcInfo.CmdletBinding
&& funcInfo.ScriptBlock != null
&& funcInfo.ScriptBlock.Attributes != null)
&& funcInfo.ScriptBlock != null)
{
foreach (var attr in funcInfo.ScriptBlock.Attributes)
try
{
var cmdletBindingAttr = attr as CmdletBindingAttribute;
if (cmdletBindingAttr != null)
if (funcInfo.ScriptBlock.Attributes != null)
{
return cmdletBindingAttr.SupportsShouldProcess;
foreach (var attr in funcInfo.ScriptBlock.Attributes)
{
var cmdletBindingAttr = attr as CmdletBindingAttribute;
if (cmdletBindingAttr != null)
{
return cmdletBindingAttr.SupportsShouldProcess;
}
}
}
}
catch (RuntimeException)
{
// The call to .Attributes on funcInfo.ScriptBlock.Attributes can throw if the attribute is custom and defined in a different file, therefore no action is being taken in this case
}

}

return false;
Expand Down