Fix Revit hard crash: run status/model_info in API context - #52
Open
drpauloguimaraesjr wants to merge 1 commit into
Open
Fix Revit hard crash: run status/model_info in API context#52drpauloguimaraesjr wants to merge 1 commit into
drpauloguimaraesjr wants to merge 1 commit into
Conversation
pyRevit's routes dispatcher decides whether to marshal a handler onto the Revit API context by inspecting its signature for uiapp/uidoc/doc (routes/server/handler.py, wants_api_context). revit_status() and get_model_info() declared no parameters, so they ran on the HTTP server's background thread and reached for revit.doc there. That access raises, the except branch calls logger.error, and pyRevit's ScriptIO lazily constructs its WPF output window from that non-STA thread. The resulting InvalidOperationException is unhandled off the main thread and terminates the Revit process (0xe0434352). Declaring doc restores API-context dispatch. Verified on Revit 2027.2 (.NET 10) with pyRevit 6.5.4: /status/ returns 503 with no document and 200 with one, /model_info/ returns model data, Revit survives both. Upstream issue mcp-servers-for-revit#47. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
pyRevit's routes dispatcher decides whether to marshal a handler onto the Revit API context by inspecting its signature for uiapp/uidoc/doc (routes/server/handler.py, wants_api_context). revit_status() and get_model_info() declared no parameters, so they ran on the HTTP server's background thread and reached for revit.doc there.
That access raises, the except branch calls logger.error, and pyRevit's ScriptIO lazily constructs its WPF output window from that non-STA thread. The resulting InvalidOperationException is unhandled off the main thread and terminates the Revit process (0xe0434352).
Declaring doc restores API-context dispatch. Verified on Revit 2027.2 (.NET 10) with pyRevit 6.5.4: /status/ returns 503 with no document and 200 with one, /model_info/ returns model data, Revit survives both.
Upstream issue #47.