Skip to content

Commit a8c4ba3

Browse files
authored
Merge pull request #2374 from MicrosoftDocs/master
6/27 AM Publish
2 parents c842955 + b6facd8 commit a8c4ba3

File tree

133 files changed

+1932
-1126
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

133 files changed

+1932
-1126
lines changed

docs/code-quality/ca1300-specify-messageboxoptions.md

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@ ms.assetid: 9357a724-026e-4a3d-a03a-f14635064ec6
1414
author: gewarren
1515
ms.author: gewarren
1616
manager: douge
17+
dev_langs:
18+
- CSharp
19+
- VB
1720
ms.workload:
1821
- "multiple"
1922
---
2023
# CA1300: Specify MessageBoxOptions
24+
2125
|||
2226
|-|-|
2327
|TypeName|SpecifyMessageBoxOptions|
@@ -26,23 +30,29 @@ ms.workload:
2630
|Breaking Change|Non-breaking|
2731

2832
## Cause
29-
A method calls an overload of the <xref:System.Windows.Forms.MessageBox.Show%2A?displayProperty=fullName> method that does not take a <xref:System.Windows.Forms.MessageBoxOptions?displayProperty=fullName> argument.
3033

31-
## Rule Description
32-
To display a message box correctly for cultures that use a right-to-left reading order, the <xref:System.Windows.Forms.MessageBoxOptions> and <xref:System.Windows.Forms.MessageBoxOptions> members of the <xref:System.Windows.Forms.MessageBoxOptions> enumeration must be passed to the <xref:System.Windows.Forms.MessageBox.Show%2A> method. Examine the <xref:System.Windows.Forms.Control.RightToLeft%2A?displayProperty=fullName> property of the containing control to determine whether to use a right-to-left reading order.
34+
A method calls an overload of the <xref:System.Windows.Forms.MessageBox.Show%2A?displayProperty=fullName> method that does not take a <xref:System.Windows.Forms.MessageBoxOptions?displayProperty=fullName> argument.
35+
36+
## Rule description
37+
38+
To display a message box correctly for cultures that use a right-to-left reading order, pass the [MessageBoxOptions.RightAlign](<xref:System.Windows.Forms.MessageBoxOptions.RightAlign>) and [MessageBoxOptions.RtlReading](<xref:System.Windows.Forms.MessageBoxOptions.RtlReading>) fields to the <xref:System.Windows.Forms.MessageBox.Show%2A> method. Examine the <xref:System.Windows.Forms.Control.RightToLeft%2A?displayProperty=fullName> property of the containing control to determine whether to use a right-to-left reading order.
39+
40+
## How to fix violations
3341

34-
## How to Fix Violations
35-
To fix a violation of this rule, call an overload of the <xref:System.Windows.Forms.MessageBox.Show%2A> method that takes a <xref:System.Windows.Forms.MessageBoxOptions> argument.
42+
To fix a violation of this rule, call an overload of the <xref:System.Windows.Forms.MessageBox.Show%2A> method that takes a <xref:System.Windows.Forms.MessageBoxOptions> argument.
3643

37-
## When to Suppress Warnings
38-
It is safe to suppress a warning from this rule when the code library will not be localized for a culture that uses a right-to-left reading order.
44+
## When to suppress warnings
45+
46+
It is safe to suppress a warning from this rule when the code library will not be localized for a culture that uses a right-to-left reading order.
3947

4048
## Example
41-
The following example shows a method that displays a message box that has options that are appropriate for the reading order of the culture. A resource file, which is not shown, is required to build the example. Follow the comments in the example to build the example without a resource file and to test the right-to-left feature.
4249

43-
[!code-vb[FxCop.Globalization.SpecifyMBOptions#1](../code-quality/codesnippet/VisualBasic/ca1300-specify-messageboxoptions_1.vb)]
44-
[!code-csharp[FxCop.Globalization.SpecifyMBOptions#1](../code-quality/codesnippet/CSharp/ca1300-specify-messageboxoptions_1.cs)]
50+
The following example shows a method that displays a message box that has options that are appropriate for the reading order of the culture. A resource file, which is not shown, is required to build the example. Follow the comments in the example to build the example without a resource file and to test the right-to-left feature.
51+
52+
[!code-vb[FxCop.Globalization.SpecifyMBOptions#1](../code-quality/codesnippet/VisualBasic/ca1300-specify-messageboxoptions_1.vb)]
53+
[!code-csharp[FxCop.Globalization.SpecifyMBOptions#1](../code-quality/codesnippet/CSharp/ca1300-specify-messageboxoptions_1.cs)]
54+
55+
## See also
4556

46-
## See Also
47-
<xref:System.Resources.ResourceManager?displayProperty=fullName>
48-
[Resources in Desktop Apps](/dotnet/framework/resources/index)
57+
- <xref:System.Resources.ResourceManager?displayProperty=fullName>
58+
- [Resources in desktop apps (.NET Framework)](/dotnet/framework/resources/index)

docs/code-quality/ca1403-auto-layout-types-should-not-be-com-visible.md

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@ ms.assetid: a7007714-f9b4-4730-94e0-67d3dc68991f
1414
author: gewarren
1515
ms.author: gewarren
1616
manager: douge
17+
dev_langs:
18+
- CSharp
19+
- VB
1720
ms.workload:
1821
- "multiple"
1922
---
2023
# CA1403: Auto layout types should not be COM visible
24+
2125
|||
2226
|-|-|
2327
|TypeName|AutoLayoutTypesShouldNotBeComVisible|
@@ -26,28 +30,35 @@ ms.workload:
2630
|Breaking Change|Breaking|
2731

2832
## Cause
29-
A Component Object Model (COM) visible value type is marked with the <xref:System.Runtime.InteropServices.StructLayoutAttribute?displayProperty=fullName> attribute set to <xref:System.Runtime.InteropServices.LayoutKind?displayProperty=fullName>.
3033

31-
## Rule Description
32-
<xref:System.Runtime.InteropServices.LayoutKind> layout types are managed by the common language runtime. The layout of these types can change between versions of the .NET Framework, which will break COM clients that expect a specific layout. Note that if the <xref:System.Runtime.InteropServices.StructLayoutAttribute> attribute is not specified, the C#, [!INCLUDE[vbprvb](../code-quality/includes/vbprvb_md.md)], and C++ compilers specify the <xref:System.Runtime.InteropServices.LayoutKind> layout for value types.
34+
A Component Object Model (COM) visible value type is marked with the <xref:System.Runtime.InteropServices.StructLayoutAttribute?displayProperty=fullName> attribute set to <xref:System.Runtime.InteropServices.LayoutKind.Auto?displayProperty=fullName>.
35+
36+
## Rule description
37+
38+
<xref:System.Runtime.InteropServices.LayoutKind> layout types are managed by the common language runtime. The layout of these types can change between versions of the .NET Framework, which breaks COM clients that expect a specific layout. If the <xref:System.Runtime.InteropServices.StructLayoutAttribute> attribute is not specified, the C#, Visual Basic, and C++ compilers specify [LayoutKind.Auto](<xref:System.Runtime.InteropServices.LayoutKind.Auto>) for value types.
39+
40+
Unless marked otherwise, all public, non-generic types are visible to COM, and all non-public and generic types are invisible to COM. However, to reduce false positives, this rule requires the COM visibility of the type to be explicitly stated. The containing assembly must be marked with the <xref:System.Runtime.InteropServices.ComVisibleAttribute?displayProperty=fullName> set to `false` and the type must be marked with the <xref:System.Runtime.InteropServices.ComVisibleAttribute> set to `true`.
3341

34-
Unless marked otherwise, all public nongeneric types are visible to COM; all nonpublic and generic types are invisible to COM. However, to reduce false positives, this rule requires the COM visibility of the type to be explicitly stated; the containing assembly must be marked with the <xref:System.Runtime.InteropServices.ComVisibleAttribute?displayProperty=fullName> set to `false` and the type must be marked with the <xref:System.Runtime.InteropServices.ComVisibleAttribute> set to `true`.
42+
## How to fix violations
3543

36-
## How to Fix Violations
37-
To fix a violation of this rule, change the value of the <xref:System.Runtime.InteropServices.StructLayoutAttribute> attribute to <xref:System.Runtime.InteropServices.LayoutKind> or <xref:System.Runtime.InteropServices.LayoutKind>, or make the type invisible to COM.
44+
To fix a violation of this rule, change the value of the <xref:System.Runtime.InteropServices.StructLayoutAttribute> attribute to [LayoutKind.Explicit](<xref:System.Runtime.InteropServices.LayoutKind.Explicit>) or [LayoutKind.Sequential](<xref:System.Runtime.InteropServices.LayoutKind.Sequential>), or make the type invisible to COM.
3845

39-
## When to Suppress Warnings
40-
Do not suppress a warning from this rule.
46+
## When to suppress warnings
47+
48+
Do not suppress a warning from this rule.
4149

4250
## Example
43-
The following example shows a type that violates the rule and a type that satisfies the rule.
4451

45-
[!code-csharp[FxCop.Interoperability.AutoLayout#1](../code-quality/codesnippet/CSharp/ca1403-auto-layout-types-should-not-be-com-visible_1.cs)]
46-
[!code-vb[FxCop.Interoperability.AutoLayout#1](../code-quality/codesnippet/VisualBasic/ca1403-auto-layout-types-should-not-be-com-visible_1.vb)]
52+
The following example shows a type that violates the rule and a type that satisfies the rule.
53+
54+
[!code-csharp[FxCop.Interoperability.AutoLayout#1](../code-quality/codesnippet/CSharp/ca1403-auto-layout-types-should-not-be-com-visible_1.cs)]
55+
[!code-vb[FxCop.Interoperability.AutoLayout#1](../code-quality/codesnippet/VisualBasic/ca1403-auto-layout-types-should-not-be-com-visible_1.vb)]
56+
57+
## Related rules
58+
59+
[CA1408: Do not use AutoDual ClassInterfaceType](../code-quality/ca1408-do-not-use-autodual-classinterfacetype.md)
4760

48-
## Related Rules
49-
[CA1408: Do not use AutoDual ClassInterfaceType](../code-quality/ca1408-do-not-use-autodual-classinterfacetype.md)
61+
## See also
5062

51-
## See Also
52-
[Qualifying .NET Types for Interoperation](/dotnet/framework/interop/qualifying-net-types-for-interoperation)
53-
[Interoperating with Unmanaged Code](/dotnet/framework/interop/index)
63+
- [Qualify .NET types for interoperation](/dotnet/framework/interop/qualifying-net-types-for-interoperation)
64+
- [Interoperate with unmanaged code](/dotnet/framework/interop/index)

docs/code-quality/ca2001-avoid-calling-problematic-methods.md

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ ms.workload:
1818
- "multiple"
1919
---
2020
# CA2001: Avoid calling problematic methods
21+
2122
|||
2223
|-|-|
2324
|TypeName|AvoidCallingProblematicMethods|
@@ -26,26 +27,29 @@ ms.workload:
2627
|Breaking Change|Non-breaking|
2728

2829
## Cause
29-
A member calls a potentially dangerous or problematic method.
3030

31-
## Rule Description
32-
Avoid making unnecessary and potentially dangerous method calls.
31+
A member calls a potentially dangerous or problematic method.
32+
33+
## Rule description
3334

34-
A violation of this rule occurs when a member calls one of the following methods.
35+
Avoid making unnecessary and potentially dangerous method calls. A violation of this rule occurs when a member calls one of the following methods:
3536

3637
|Method|Description|
3738
|------------|-----------------|
38-
|<xref:System.GC.Collect%2A?displayProperty=fullName>|Calling GC.Collect can significantly affect application performance and is rarely necessary. For more information, see the [Rico Mariani's Performance Tidbits](http://go.microsoft.com/fwlink/?LinkId=169256) blog entry on MSDN.|
39-
|<xref:System.Threading.Thread.Resume%2A?displayProperty=fullName><br /><br /> <xref:System.Threading.Thread.Suspend%2A?displayProperty=fullName>|Thread.Suspend and Thread.Resume have been deprecated because of their unpredictable behavior. Use other classes in the <xref:System.Threading> namespace, such as <xref:System.Threading.Monitor>, <xref:System.Threading.Mutex>, <xref:System.Threading.Mutex>, and <xref:System.Threading.Semaphore> to synchronize threads or protect resources.|
39+
|<xref:System.GC.Collect%2A?displayProperty=fullName>|Calling GC.Collect can significantly affect application performance and is rarely necessary. For more information, see [Rico Mariani's Performance Tidbits](http://go.microsoft.com/fwlink/?LinkId=169256) blog entry on MSDN.|
40+
|<xref:System.Threading.Thread.Resume%2A?displayProperty=fullName><br /><br /> <xref:System.Threading.Thread.Suspend%2A?displayProperty=fullName>|Thread.Suspend and Thread.Resume have been deprecated because of their unpredictable behavior. Use other classes in the <xref:System.Threading> namespace, such as <xref:System.Threading.Monitor>, <xref:System.Threading.Mutex>, and <xref:System.Threading.Semaphore>, to synchronize threads or protect resources.|
4041
|<xref:System.Runtime.InteropServices.SafeHandle.DangerousGetHandle%2A?displayProperty=fullName>|The DangerousGetHandle method poses a security risk because it can return a handle that is not valid. See the <xref:System.Runtime.InteropServices.SafeHandle.DangerousAddRef%2A> and the <xref:System.Runtime.InteropServices.SafeHandle.DangerousRelease%2A> methods for more information about how to use the DangerousGetHandle method safely.|
4142
|<xref:System.Reflection.Assembly.LoadFrom%2A?displayProperty=fullName><br /><br /> <xref:System.Reflection.Assembly.LoadFile%2A?displayProperty=fullName><br /><br /> <xref:System.Reflection.Assembly.LoadWithPartialName%2A?displayProperty=fullName>|These methods can load assemblies from unexpected locations. For example, see Suzanne Cook's .NET CLR Notes blog posts [LoadFile vs. LoadFrom](http://go.microsoft.com/fwlink/?LinkId=164450) and [Choosing a Binding Context](http://go.microsoft.com/fwlink/?LinkId=164451) on the MSDN Web site for information about methods that load assemblies.|
4243
|[CoSetProxyBlanket](http://go.microsoft.com/fwlink/?LinkID=169250) (Ole32)<br /><br /> [CoInitializeSecurity](http://go.microsoft.com/fwlink/?LinkId=169255) (Ole32)|By the time the user code starts executing in a managed process, it is too late to reliably call CoSetProxyBlanket. The common language runtime (CLR) takes initialization actions that may prevent the users P/Invoke from succeeding.<br /><br /> If you do have to call CoSetProxyBlanket for a managed application, we recommend that you start the process by using a native code (C++) executable, call CoSetProxyBlanket in the native code, and then start your managed code application in process. (Be sure to specify a runtime version number.)|
4344

44-
## How to Fix Violations
45-
To fix a violation of this rule, remove or replace the call to the dangerous or problematic method.
45+
## How to fix violations
46+
47+
To fix a violation of this rule, remove or replace the call to the dangerous or problematic method.
48+
49+
## When to suppress warnings
50+
51+
You should suppress messages from this rule only when no alternatives to the problematic method are available.
4652

47-
## When to Suppress Warnings
48-
You should suppress messages from this rule only when no alternatives to the problematic method are available.
53+
## See also
4954

50-
## See Also
51-
[Reliability Warnings](../code-quality/reliability-warnings.md)
55+
- [Reliability Warnings](../code-quality/reliability-warnings.md)

0 commit comments

Comments
 (0)