Skip to content

Fix Revit hard crash: run status/model_info in API context - #52

Open
drpauloguimaraesjr wants to merge 1 commit into
mcp-servers-for-revit:masterfrom
drpauloguimaraesjr:local-fix-sta-crash
Open

Fix Revit hard crash: run status/model_info in API context#52
drpauloguimaraesjr wants to merge 1 commit into
mcp-servers-for-revit:masterfrom
drpauloguimaraesjr:local-fix-sta-crash

Conversation

@drpauloguimaraesjr

Copy link
Copy Markdown

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.

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>
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.

1 participant