In principle, every solution in Dynamics 365 for Finance and Operations should be free of best-practice deviations, but sometimes there is the need to suppress them.
Such a case are for example, event handlers that have a predefined parameter profile, but if one of these parameters is not used, it causes a BP deviation.
class MyFreeTextInvoiceHeaderFooterTmpEH
{
[DataEventHandler(tableStr(FreeTextInvoiceHeaderFooterTmp), DataEventType::Inserting)]
public static void FreeTextInvoiceHeaderFooterTmp_onInserting(Common sender, DataEventArgs e)
{
FreeTextInvoiceHeaderFooterTmp freeTextInvoiceHeaderFooterTmp;
freeTextInvoiceHeaderFooterTmp = sender;
if (freeTextInvoiceHeaderFooterTmp.CompanyBankAccount == "")
{
freeTextInvoiceHeaderFooterTmp.CompanyBankName = "Unknown";
}
}
}
With the above EH, the following BP deviation would be output because the parameter e is not used:
BP Rule: [BPParameterNotUsed]:The parameter 'e' is not used.
To prevent this, you can use the attribute SuppressBPWarning in the simplest case:
But it is also possible to collect all these suppressions in a module-bound file. To do this, you must create an XML file in the directory of the module as follows:
<?xml version="1.0" encoding="utf-8"?>
<IgnoreDiagnostics>
<Name>YourModel_BPSuppressions</Name>
<Items>
<Diagnostic>
<DiagnosticType>BestPractices</DiagnosticType>
<Severity>Warning</Severity>
<Path>dynamics://Class/MyFreeTextInvoiceHeaderFooterTmpEH/Method/FreeTextInvoiceHeaderFooterTmp_onInserting</Path>
<Moniker>BPParameterNotUsed</Moniker>
<Justification>Event handler parameters that cannot be removed from the method's signature.</Justification>
</Diagnostic>
</Items>
</IgnoreDiagnostics>
Please note that in XML the name of the model must be adapted to the circumstances.
DiagnosticType is always "BestPractices". Severity, Path and Moniker can usually be read from the error message in the error list of Visual Studio. Unfortunately, in my experience, this is not always the case. In this case you can read on this page if you find a suitable moniker:
I myself have come across the following Monikers so far:
BPParameterNotUsed
BPEmptyCompoundStatement
BPErrorMethodUnbalancedTtsbeginCommit
BPCheckParametersModified
BPUpgradeCodeLateBoundCall
BPErrorClassNewNotProtected
Once you have created such an XML file, you can use the context menu of the Visual Studio project to edit the file: Edit Best Practice Suppressions
By the way, you can store an XML schema for this XML file in the same directory to avoid the following error:
Could not find schema information for the element 'IgnoreDiagnostics'.
Such a schema can be created in Visual Studio under XML > Create schema (this menu is only available if you have just opened an XML file).
To add the XML file (and the schema, if applicable) to the version control, you have to change to the directory of the corresponding model via the Source Control Explorer and select the files via Add Items to Folder.
By the way, I made the experience that you should edit the XML file outside of Visual-Studio.
These post applies to following version: Dynamics 365 for Finance and Operations
In principle, every solution in Dynamics 365 for Finance and Operations should be free of best-practice deviations, but sometimes there is the need to suppress them.
Such a case are for example, event handlers that have a predefined parameter profile, but if one of these parameters is not used, it causes a BP deviation.
With the above EH, the following BP deviation would be output because the parameter e is not used:
To prevent this, you can use the attribute SuppressBPWarning in the simplest case:
But it is also possible to collect all these suppressions in a module-bound file. To do this, you must create an XML file in the directory of the module as follows:
K:\AosService\PackagesLocalDirectory\YourModel\YourModel\
AxIgnoreDiagnosticList\YourModel_BPSuppressions.xml
Please note that in XML the name of the model must be adapted to the circumstances.
DiagnosticType is always "BestPractices". Severity, Path and Moniker can usually be read from the error message in the error list of Visual Studio. Unfortunately, in my experience, this is not always the case. In this case you can read on this page if you find a suitable moniker:
https://docs.microsoft.com/en-us/dynamics365/unified-operations/dev-itpro/dev-tools/customization-analysis-report
I myself have come across the following Monikers so far:
Once you have created such an XML file, you can use the context menu of the Visual Studio project to edit the file: Edit Best Practice Suppressions
By the way, you can store an XML schema for this XML file in the same directory to avoid the following error:
Such a schema can be created in Visual Studio under XML > Create schema (this menu is only available if you have just opened an XML file).
To add the XML file (and the schema, if applicable) to the version control, you have to change to the directory of the corresponding model via the Source Control Explorer and select the files via Add Items to Folder.
By the way, I made the experience that you should edit the XML file outside of Visual-Studio.