Import-DbaParquet - Stop leaving an assembly resolver registered for the whole process - #10541
Merged
Merged
Conversation
…the whole process The AssemblyResolve handler that finds the Parquet.NET dependencies is a PowerShell scriptblock, and a scriptblock cannot run on a thread that has no runspace. It was registered once per process and never removed, so anything that resolved an assembly on another thread afterwards invoked it from a thread it cannot run on. New-DbaDacPackage does exactly that: TSqlModel.Validate() runs on DacFx worker threads. In a full suite run that surfaced as the caught error "Model validation failed: There is no Runspace available to run scripts in this thread". Run directly after the Parquet tests in one Windows PowerShell process it was worse - the process died with an access violation, faulting module clr.dll, exception 0xc0000005. The handler is only needed while the assemblies are loaded, so it is registered right before that and removed again in a finally. Same process, same two test files, the only difference being whether the handler is still registered: registered means the process dies, removed means the DacPackage tests pass 9 of 9. (do *Parquet*) Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This was referenced Aug 8, 2026
Member
|
thank you 🙏🏼 |
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.
Fixes #10536.
Using
Import-DbaParquetand thenNew-DbaDacPackagein the same Windows PowerShell session killed thesession - no error record, no exception, the process was simply gone with exit code
-1073741819.The cause
The
AssemblyResolvehandler that finds the Parquet.NET dependencies is a PowerShell scriptblock cast to[System.ResolveEventHandler], and a scriptblock cannot run on a thread that has no runspace. It wasregistered once per process and never removed, so anything that resolved an assembly on another thread later
on invoked it from a thread it cannot run on.
New-DbaDacPackagedoes exactly that -TSqlModel.Validate()runs on DacFx worker threads. There are twooutcomes depending on where the resolve lands:
Model validation failed: There is no Runspace available to run scripts in this thread(the real inner reason, unwrapped by New-DbaDacPackage - Report the real reason model validation failed #10527).New-DbaDacPackageis only the command that was noticed. Any multi-threaded .NET work that triggers assemblyresolution after an import was exposed.
The fix
The handler is only needed while the assemblies are being loaded, so it is registered right before the
Add-Typecalls and removed again in afinally. Thefinallyalso covers the failure path, which returnsearly.
Testing
Same process, same two test files, the only difference being whether the handler is still registered when the
second file runs:
New-DbaDacPackage.Tests.ps1-1073741819The reason the handler was needed at all still holds - it is the load path that requires it, not the read path:
Import-DbaParquet.Tests.ps1on Windows PowerShell 5.1Import-DbaParquet.Tests.ps1on PowerShell 7.4Import-DbaParquet.Tests.ps1thenNew-DbaDacPackage.Tests.ps1, one processNote
This touches the same file as #10538 but a different part of it, and the two merge cleanly - verified by
merging them locally and running the tests above against the combination.
Note
Unrelated and pre-existing, seen while testing this: on PowerShell 7 the Parquet test file intermittently
fails Pester's
TestDrivecleanup withThe process cannot access the file 'staging.ecdc_parquet_test.parquet' because it is being used by another process. The 17 tests pass every time; it is the cleanup that fails,roughly every other run, which looks like a file handle released only by the garbage collector. It predates
this change and is not addressed here.
🤖 Generated with Claude Code