SqlPersistenceTask: An unhandled exception occurred: Could not find assembly 'NServiceBus.Persistence.Sql, Version=9.0.0.0#1898
Conversation
|
@bording Given this is not an area I'm super knowledgeable in, I'd appreciate your review |
There was a problem hiding this comment.
Pull request overview
This PR fixes an issue where the MSBuild task failed to resolve referenced assemblies when using MetadataLoadContext to read custom attributes. The task runs after compilation using the intermediate assembly from the obj/ folder, where dependencies aren't yet copied. The solution passes the @(ReferencePath) item group from MSBuild, which contains full paths to all referenced assemblies, ensuring the MetadataLoadContext can resolve them properly.
Changes:
- Added
ReferencePathparameter to the MSBuild task and targets file to pass referenced assembly paths - Modified
ScriptGeneratorto accept and use reference paths when creating thePathAssemblyResolver - Added comprehensive tests to verify the fix works in isolated assembly scenarios
Reviewed changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| SqlPersistenceScriptBuilderTask.cs | Added ReferencePath property and passes it to InnerTask |
| NServiceBus.Persistence.Sql.targets | Passes @(ReferencePath) from MSBuild to the task |
| InnerTask.cs | Accepts referencePaths parameter and forwards to ScriptGenerator |
| ScriptGenerator.cs | Implements CollectAssemblyFiles method to include reference paths in assembly resolution |
| SettingsAttributeReader.cs | Minor code style modernization (collection expressions) |
| InnerTaskTests.cs | Added tests for isolated assembly scenarios with and without reference paths |
| InnerTaskTests approval file | Renamed to match updated test name |
| APIApprovals.Approve.approved.txt | Updated to reflect new public API surface |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
…nerator (#1899) * Initial plan * Refactor foreach loops to use explicit .Where() filtering Co-authored-by: danielmarbach <174258+danielmarbach@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: danielmarbach <174258+danielmarbach@users.noreply.github.com>
|


The issue was that the MetadataLoadContext needed to resolve referenced assemblies (like NServiceBus.Persistence.Sql) when reading custom attributes, but the MSBuild task runs
AfterTargets="AfterCompile"using the intermediate assembly from theobj/folder, where dependencies might not be copied yet.The fix passes the
@(ReferencePath)item group from MSBuild to the script generator, which contains the full paths to all referenced assemblies. These are then included in the PathAssemblyResolver so theMetadataLoadContextcan resolve them.