|
4362 | 4362 | </ReturnValue>
|
4363 | 4363 | <Parameters />
|
4364 | 4364 | <Docs>
|
4365 |
| - <summary>Get the last platform invoke error on the current thread</summary> |
4366 |
| - <returns>The last platform invoke error</returns> |
| 4365 | + <summary>Get the last platform invoke error on the current thread.</summary> |
| 4366 | + <returns>The last platform invoke error.</returns> |
4367 | 4367 | <remarks>
|
4368 | 4368 | <format type="text/markdown"><![CDATA[
|
4369 | 4369 |
|
4370 | 4370 | ## Remarks
|
4371 | 4371 |
|
4372 |
| -The last platform invoke error corresponds to the error set by either the most recent platform |
4373 |
| - invoke that was configured to set the last error or a call to <xref:System.Runtime.InteropServices.Marshal.SetLastPInvokeError(System.Int32)>. |
| 4372 | +The last platform invoke error corresponds to the error set either by the most recent platform invoke that was |
| 4373 | +configured with <xref:System.Runtime.InteropServices.DllImportAttribute.SetLastError?displayProperty=nameWithType> |
| 4374 | +set to `true` or by a call to <xref:System.Runtime.InteropServices.Marshal.SetLastPInvokeError(System.Int32)>, |
| 4375 | +whichever happened last. |
| 4376 | + |
| 4377 | +This method will only return errors set via the mentioned scenarios. To get the last system error independent of |
| 4378 | +platform invoke usage, use <xref:System.Runtime.InteropServices.Marshal.GetLastSystemError%2A>. |
| 4379 | + |
| 4380 | +This method is functionally equivalent to <xref:System.Runtime.InteropServices.Marshal.GetLastWin32Error%2A>. It is |
| 4381 | +named to better reflect the intent of the API and its cross-platform nature. <xref:System.Runtime.InteropServices.Marshal.GetLastPInvokeError%2A> |
| 4382 | +should be preferred over <xref:System.Runtime.InteropServices.Marshal.GetLastWin32Error%2A>. |
| 4383 | + |
| 4384 | +## Examples |
| 4385 | + |
| 4386 | +The following example defines a p/invoke with <xref:System.Runtime.InteropServices.DllImportAttribute.SetLastError?displayProperty=nameWithType> |
| 4387 | +set to `true` and demonstrates using <xref:System.Runtime.InteropServices.Marshal.GetLastPInvokeError%2A> to get the last p/invoke error. |
| 4388 | + |
| 4389 | +:::code language="csharp" source="~/samples/snippets/csharp/System.Runtime.InteropServices/Marshal/GetLastPInvokeError.cs" id="Snippet1"::: |
4374 | 4390 |
|
4375 | 4391 | ]]></format>
|
4376 | 4392 | </remarks>
|
@@ -4399,14 +4415,17 @@ The last platform invoke error corresponds to the error set by either the most r
|
4399 | 4415 | </ReturnValue>
|
4400 | 4416 | <Parameters />
|
4401 | 4417 | <Docs>
|
4402 |
| - <summary>Get the last system error on the current thread</summary> |
4403 |
| - <returns>The last system error</returns> |
| 4418 | + <summary>Gets the last system error on the current thread.</summary> |
| 4419 | + <returns>The last system error.</returns> |
4404 | 4420 | <remarks>
|
4405 | 4421 | <format type="text/markdown">< on Windows. |
| 4426 | + |
| 4427 | +This method is provided as a low-level API to allow getting the current system error in a cross-platform manner. It is not tied to |
| 4428 | +platform invoke usage. To get the last platform invoke error, use <xref:System.Runtime.InteropServices.Marshal.GetLastPInvokeError%2A>. |
4410 | 4429 |
|
4411 | 4430 | ]]></format>
|
4412 | 4431 | </remarks>
|
@@ -4473,6 +4492,8 @@ You can use this method to obtain error codes only if you apply the <xref:System
|
4473 | 4492 |
|
4474 | 4493 | There is a difference in the behavior of the `GetLastWin32Error` method on .NET Core and .NET Framework when <xref:System.Runtime.InteropServices.DllImportAttribute.SetLastError?displayProperty=nameWithType> is `true`. On .NET Framework, the `GetLastWin32Error` method can retain error information from one P/Invoke call to the next. On .NET Core, error information is cleared before P/Invoke call, and the `GetLastWin32Error` represents only error information from the last method call.
|
4475 | 4494 |
|
| 4495 | +On .NET 6 and later versions, this method is functionally equivalent to <xref:System.Runtime.InteropServices.Marshal.GetLastPInvokeError%2A>, which is named to better reflect the intent of the API and its cross-platform nature. <xref:System.Runtime.InteropServices.Marshal.GetLastPInvokeError%2A> should be preferred over <xref:System.Runtime.InteropServices.Marshal.GetLastWin32Error%2A>. |
| 4496 | + |
4476 | 4497 | ## Examples
|
4477 | 4498 | The following example calls the `GetLastWin32Error` method. The example first demonstrates calling the method with no error present and then demonstrates calling the method with an error present.
|
4478 | 4499 |
|
@@ -9692,9 +9713,17 @@ There is a difference in the behavior of the `GetLastWin32Error` method on .NET
|
9692 | 9713 | <Parameter Name="error" Type="System.Int32" Index="0" FrameworkAlternate="net-6.0" />
|
9693 | 9714 | </Parameters>
|
9694 | 9715 | <Docs>
|
9695 |
| - <param name="error">Error to set</param> |
9696 |
| - <summary>Set the last platform invoke error on the current thread</summary> |
9697 |
| - <remarks>To be added.</remarks> |
| 9716 | + <param name="error">The error to set.</param> |
| 9717 | + <summary>Sets the last platform invoke error on the current thread.</summary> |
| 9718 | + <remarks> |
| 9719 | + <format type="text/markdown"><![CDATA[ |
| 9720 | + |
| 9721 | +## Remarks |
| 9722 | + |
| 9723 | +The last platform invoke error is stored per-thread and can be retrieved using <xref:System.Runtime.InteropServices.Marshal.GetLastPInvokeError%2A>. |
| 9724 | + |
| 9725 | + ]]></format> |
| 9726 | + </remarks> |
9698 | 9727 | </Docs>
|
9699 | 9728 | </Member>
|
9700 | 9729 | <Member MemberName="SetLastSystemError">
|
@@ -9722,14 +9751,14 @@ There is a difference in the behavior of the `GetLastWin32Error` method on .NET
|
9722 | 9751 | <Parameter Name="error" Type="System.Int32" Index="0" FrameworkAlternate="net-6.0" />
|
9723 | 9752 | </Parameters>
|
9724 | 9753 | <Docs>
|
9725 |
| - <param name="error">Error to set</param> |
9726 |
| - <summary>Set the last system error on the current thread</summary> |
| 9754 | + <param name="error">The error to set.</param> |
| 9755 | + <summary>Sets the last system error on the current thread.</summary> |
9727 | 9756 | <remarks>
|
9728 | 9757 | <format type="text/markdown">< on Windows. |
9733 | 9762 |
|
9734 | 9763 | ]]></format>
|
9735 | 9764 | </remarks>
|
|
0 commit comments