> Use Dispose where available (document as IDisposable) or Using for managed code?
How is it relevant here? (Not in general, but for this particular case for which sample code is available)
> "Expose the problem", so a memory issue is why Revit "Hangs" and WaitForPendingFinalizers forces the issue?, Does revit crash?, Does Revit keep CPU running or is it idle?
No, the problem is that finalizer thread is blocked forever (trying to cleanup an RCW, which requires it to call to the main STA, and never getting response) after the call to Application.OpenDocumentFile, if the family file passed to it was of an older version and needed an upgrade.
Explicit calls to GC are needed only to demonstrate the problem (show in an easily underestandable way that the finalizer thread is blocked):
- GC.Collect puts the RCW to the finalizer queue if it was not there yet
- GC.WaitForPendingFinalizers simply waits for the finalizer thread to finish calling pending finalizers (in the way that allows incoming calls to the current apartment, so it itself can't cause the deadlock that way)
> What have you tried to narrow the issue (Revit, Windows, Network etc...)
It's been reproducible by everyone who tried it so far, in plain Revit 2026 without any 3rd party addins etc. (As I mentioned earlier, I can't rule out an effect of some widely used 3rd party component like DirectX, for example, but it's much more likely that Revit is responsible, naturally. At least, it would be much easier for Revit developers (than for us) to at least see that f. ex. they are not accidentally dropping messages used for cross-apartment COM calls somewhere)
> - Examined the Revit Journal, does it provide some clue?
Yes, nothing relevant there.
> - Try the actions in Addin in the UI manually, does that work?
Revit is not responding, as described. (In the real life case it is also not responding in a basically the same way, since many .NET functions internally wait for the finalizer thread to finish, f. ex. Join() functions, so it's enough to call one on the main thread, and Revit hangs.)
> - Any issues with one or more families (Catching the Revit warnings / errors related to families?)
> - Does it work in R2025 (or earlies versions) without the R2026 issue?
Any family (created with Revit 2025 or older) can be used to reproduce it, so it's not a problem with a specific family.
> - What happens if R2026 families are used, so no upgrade is needed?
The problem does not occur (as described).
> Remark to the sample code:
> All families are loaded in one loop, howmany are opened? For 100, of 1000 families this can be a memory issue (don't know if Revit can handle 100 open families in a session)
One. As mentioned in readme.txt, one family is enough to reproduce the problem.
(The loop is only to make it easier to use, no need to specify the name of the family etc., just put any families you want to test into that directory, and the test code will find them)