Skip to content

Add NullAssemblyResolver and PathAssemblyResolver - #721

Merged
Washi1337 merged 2 commits into
Washi1337:developmentfrom
js6pak:new-resolvers
Mar 5, 2026
Merged

Add NullAssemblyResolver and PathAssemblyResolver#721
Washi1337 merged 2 commits into
Washi1337:developmentfrom
js6pak:new-resolvers

Conversation

@js6pak

@js6pak js6pak commented Feb 24, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@github-actions

This comment has been minimized.

@Washi1337

Copy link
Copy Markdown
Owner

I think ReferencePathAssemblyResolver is fine, as long as we clearly document that it is about file paths, or else I fear people may confuse it for a directory path containing all the reference DLLs (e.g., Microsoft.NETCore.App.Ref)

I think a SearchDirectoryAssemblyResolver is not needed because you can express that as a ReferencePathAssemblyResolver initialized with Directory.GetFiles(searchDirectory). A factory method taking in a search directory/-ies could work though.

@Washi1337 Washi1337 added enhancement dotnet Issues related to AsmResolver.DotNet labels Feb 25, 2026
@Washi1337 Washi1337 modified the milestone: 6.0.0 Feb 25, 2026
@js6pak js6pak changed the title Add NullAssemblyResolver and ReferencePathAssemblyResolver Add NullAssemblyResolver and PathAssemblyResolver Feb 25, 2026
@js6pak
js6pak marked this pull request as ready for review February 25, 2026 18:27
Comment thread src/AsmResolver.DotNet/PathAssemblyResolver.cs Outdated
/// <inheritdoc />
public ResolutionStatus Resolve(AssemblyDescriptor assembly, ModuleDefinition? originModule, out AssemblyDefinition? result)
{
if (assembly.Name is null || !_simpleNameMap.TryGetValue(assembly.Name, out var path) || !File.Exists(path))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the File.Exists check could be moved to the ctor.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about it, but I could see a situation where someone creates the PathAssemblyResolver instance before the files are created, as weird as it might be.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't the same be true of directories?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well.. yeah. But I'd say it's easier to stomach since the purpose of PathAssemblyResolver is not resolving from directories and FromSearchDirectories is just a helper factory method.
It is pretty nasty though.. I wonder if we should just always iterate in Resolve and support both files and directories as valid paths.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the O(1) lookup complexity we get with this. Perhaps it deserves a separate LazyPathAssemblyResolver to handle that niche case.

@Washi1337 Washi1337 Feb 26, 2026

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think O(1) is crucial; IAssemblyResolver is not a hot path anymore given that cache management is done on RuntimeContext level.

That being said, I am not sure I can see a real use-case for a PathAssemblyResolver where its input files do not exist yet. Do you have any specific scenario in mind?

@timcassell timcassell Feb 26, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could keep the lookup built in the ctor, and iterate the search directories as a fallback.

Also I wonder if clashed filenames should be iterated over instead of only trying the first. (Dictionary<string, List<string>>)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could keep the lookup built in the ctor, and iterate the search directories as a fallback.

Including search directories would be against the main purpose of a ReferencePathAssemblyResolver (i.e., specific set of files vs directory search), so I wouldn't really be in favor of this.

Also I wonder if clashed filenames should be iterated over instead of only trying the first. (Dictionary<string, List>)

As far as I know, DLLs are always preferred over EXE files? I could be wrong, I am not too familiar with the inner workings of msbuild or build tasks, but I have not seen the opposite happen at runtime.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking more if assemblies with the same name exist in different search directories, not concerning MSBuild's ReferencePath.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Including search directories would be against the main purpose of a ReferencePathAssemblyResolver (i.e., specific set of files vs directory search), so I wouldn't really be in favor of this.

Maybe better to keep it simple, then, and drop the search directories factory?

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@Washi1337 Washi1337 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small comments.

Also, please make sure to use the explicit keywords for built-in types string, int, string[] etc. in local variable declarations to keep code style consistent.

Other than that, LGTM!

Comment thread src/AsmResolver.DotNet/PathAssemblyResolver.cs Outdated
Comment thread src/AsmResolver.DotNet/PathAssemblyResolver.cs Outdated
@github-actions

github-actions Bot commented Mar 2, 2026

Copy link
Copy Markdown

Test Results

Total Skipped Passed Failed
Unique 2156 5 💤 2156 ✅ 0 ❌
Total 4312 36 💤 4276 ✅ 0 ❌

Failing runs

@Washi1337
Washi1337 merged commit d63dd41 into Washi1337:development Mar 5, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dotnet Issues related to AsmResolver.DotNet enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants