GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Skip publishing sys.clr_data when BinaryFormatter is unavailable (#2282) by AtwoodTM · Pull Request #2749 · pythonnet/pythonnet

Conversation

@AtwoodTM

@AtwoodTM AtwoodTM commented Oct 6, 2026

Copy link
Copy Markdown

What does this implement/fix? Explain your changes.

When BinaryFormatter cannot run, RuntimeData.Stash falls back to NoopFormatter and still published a zero-length sys.clr_data capsule. NoopFormatter.Serialize writes nothing. The next PythonEngine.Initialize saw that capsule and called Deserialize, which throws.

Stash now returns before building or publishing the capsule when the formatter is a NoopFormatter. An existing capsule is cleared so a later Initialize builds a fresh runtime instead of restoring an empty one. Runtimes where BinaryFormatter still works, including .NET Framework, keep the real stash.

Does this close any currently open issues?

#2282

Any other comments?

#2639 already catches the BinaryFormatter failure and returns NoopFormatter, so Shutdown itself no longer throws NotSupportedException. This change stops that fallback from leaving a capsule the next Initialize cannot read.

The new embed test calls Py_Finalize after the assertion, then Initialize. A second Shutdown in the same process deallocates types from the previous runtime and hits MetaType.tp_dealloc in a debug build. GlobalTestsSetup would do that second shutdown.

Local run, with PYTHONNET_PYDLL set:

dotnet test src/embed_tests/Python.EmbeddingTest.csproj -f net10.0

242 passed, 5 skipped, 0 failed. net472 was not run here. This machine has no mono.

Checklist

  • Make sure to include one or more tests for your change
  • If an enhancement PR, please create docs and at best an example
  • Ensure you have signed the .NET Foundation CLA
  • Add yourself to AUTHORS
  • Updated the CHANGELOG

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
AtwoodTM added 2 commits October 6, 2026 04:54
@AtwoodTM
Skip publishing sys.clr_data when BinaryFormatter is unavailable (pyt…
0958ef5
…honnet#2282)

NoopFormatter serializes nothing. An empty capsule makes the next
Initialize call Deserialize and throw. Leave sys.clr_data unset.
@AtwoodTM
Leave AUTHORS.md unchanged
06f9c1d
A single fix does not need a new credits entry.
@filmor

filmor commented Oct 6, 2026

Copy link
Copy Markdown
Member

As it stands, we can't safely re-Initialize after a shutdown.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@AtwoodTM

AtwoodTM commented Oct 6, 2026

Copy link
Copy Markdown
Author

You're right, thanks for taking a look. I went back and tested master on net8.0, net9.0 and net10.0. Shutdown() works fine there now (looks like #2639 fixed it), and the only thing still failing is calling Initialize() again afterwards, which isn't supported. All this PR did was let the second Initialize() start fresh on top of the old interpreter state, which is worse than the exception. Closing.

Side question: is there anything left on #2282, or can that one be closed too? It still shows up as open when people search for the BinaryFormatter error.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@AtwoodTM AtwoodTM closed this Oct 6, 2026
@AtwoodTM
AtwoodTM deleted the fix/develop/2282-noop-stash branch October 6, 2026 09:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@AtwoodTM @filmor
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.