Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 12, 2025

Code examples incorrectly show GetData() returning null when it actually returns a NotSupportedException instance when BinaryFormatter deserialization is required but not enabled.

Changes

  • C# ObsoletePatterns.cs: Update comments (lines 23, 34) and null check (line 35) to reflect exception-based behavior
  • VB ObsoletePatterns.vb: Update comments (lines 19, 29) and null check (line 30) to reflect exception-based behavior

Context

The main documentation correctly states the behavior, but code examples contradict it:

// Current (incorrect):
object data = Clipboard.GetData("MyApp.Person");
// Always returns null on a custom object type
if (data != null) { /* ... */ }

// Should be:
object data = Clipboard.GetData("MyApp.Person");
// Returns NotSupportedException when BinaryFormatter is required but not enabled
if (data is not NotSupportedException) { /* ... */ }

These examples demonstrate obsolete patterns that developers should avoid, so accuracy is critical for proper migration guidance.

Original prompt

This section details on the original issue you should resolve

<issue_title>Some code examples still show null for Clipboard GetData when instead they return an exception</issue_title>
<issue_description>### Type of issue

Code doesn't work

Description

There was a behavior change from the time the article was written to when it was actually published. Some of the code examples still show, expect, or comment about null being returned when in fact it returns a NotSupportedException instance. These should be fixed.

Page URL

https://learn.microsoft.com/en-us/dotnet/desktop/winforms/migration/clipboard-dataobject-net10

Content source URL

https://github.com/dotnet/docs-desktop/blob/main/dotnet-desktop-guide/winforms/migration/clipboard-dataobject-net10.md

Document Version Independent Id

d7829387-6c41-1e77-8c93-113d49382167

Platform Id

54424045-aea6-3a25-8c01-9c53dc5840ca

Article author

@adegeo

Metadata

  • ID: d7829387-6c41-1e77-8c93-113d49382167
  • PlatformId: 54424045-aea6-3a25-8c01-9c53dc5840ca
  • Service: dotnet-desktop
  • Sub-service: winforms

Related Issues</issue_description>

Comments on the Issue (you are @copilot in this section)

Custom agent used: Issue Planner
Examines an issue and develops a plan of action to address it.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Fix Clipboard GetData examples to handle NotSupportedException Fix clipboard GetData() examples showing null instead of NotSupportedException Nov 12, 2025
Copilot finished work on behalf of adegeo November 12, 2025 22:20
Copilot AI requested a review from adegeo November 12, 2025 22:20
@adegeo
Copy link
Contributor

adegeo commented Nov 12, 2025

@copilot this plan looks good. Perform the actions

@adegeo adegeo closed this Nov 12, 2025
Copilot finished work on behalf of adegeo November 12, 2025 22:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Some code examples still show null for Clipboard GetData when instead they return an exception

2 participants