-
Notifications
You must be signed in to change notification settings - Fork 6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add documentation for CA2255 (new in .NET 6) (#27096)
* Add documentation for CA2255 (new in .NET 6) * Address pr feedback
- Loading branch information
1 parent
27f8137
commit 657431b
Showing
5 changed files
with
45 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
--- | ||
title: "CA2255: The 'ModuleInitializer' attribute should not be used in libraries" | ||
description: "Learn about code analysis rule CA2255: The 'ModuleInitializer' attribute should not be used in libraries" | ||
ms.date: 11/15/2021 | ||
ms.topic: reference | ||
f1_keywords: | ||
- CA2255 | ||
- ModuleInitializerAttributeShouldNotBeUsedInLibraries | ||
helpviewer_keywords: | ||
- ModuleInitializerAttributeShouldNotBeUsedInLibraries | ||
- CA2255 | ||
author: jeffhandley | ||
--- | ||
# CA2255: The `ModuleInitializer` attribute should not be used in libraries | ||
|
||
| | Value | | ||
|-|-| | ||
| **Rule ID** |CA2255| | ||
| **Category** |[Usage](usage-warnings.md)| | ||
| **Fix is breaking or non-breaking** |Non-breaking| | ||
|
||
## Cause | ||
|
||
Applying <xref:System.Runtime.CompilerServices.ModuleInitializerAttribute> to a method within a Class Library. | ||
|
||
## Rule description | ||
|
||
Module initializers are intended to be used by application code to ensure an application's components are initialized before the application code begins executing. If library code declares a method with the <xref:System.Runtime.CompilerServices.ModuleInitializerAttribute>, it can interfere with application initialization and also lead to limitations in that application's trimming abilities. Library code should therefore not utilize the <xref:System.Runtime.CompilerServices.ModuleInitializerAttribute> attribute. | ||
|
||
## How to fix violations | ||
|
||
Instead of using methods with the <xref:System.Runtime.CompilerServices.ModuleInitializerAttribute>, a library should expose methods that can be used to initialize any components within the library, and allow the application to invoke the method during application initialization. | ||
|
||
## When to suppress warnings | ||
|
||
It is safe to suppress warnings from this rule if a solution uses a Class Library for code factoring purposes, and the <xref:System.Runtime.CompilerServices.ModuleInitializerAttribute> method is not part of a shared or distributed library or package. | ||
|
||
## See also | ||
|
||
- [Usage warnings](usage-warnings.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters