Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Error notification when LocationPaths is missing .dll file(s) #2201

Closed
marcospgp opened this issue Jul 29, 2021 · 1 comment · Fixed by #2202
Closed

Error notification when LocationPaths is missing .dll file(s) #2201

marcospgp opened this issue Jul 29, 2021 · 1 comment · Fixed by #2202

Comments

@marcospgp
Copy link

Is there any way we can get an error when one of the LocationPaths does not contain a .dll? Otherwise it's relatively easy for analyzers to silently stop working.

image

@bjorkstromm
Copy link
Member

Looking at the code and currently no.

I'd say an error might probably be too intrusive, but maybe a warning or at least a debug log could be added.

Relevant code is around here:

[ImportingConstructor]
public ExternalFeaturesHostServicesProvider(IAssemblyLoader loader, OmniSharpOptions options, IOmniSharpEnvironment environment)
{
var builder = ImmutableArray.CreateBuilder<Assembly>();
var roslynExtensionsLocations = options.RoslynExtensionsOptions.GetNormalizedLocationPaths(environment);
if (roslynExtensionsLocations?.Any() == true)
{
foreach (var roslynExtensionsLocation in roslynExtensionsLocations)
{
builder.AddRange(loader.LoadAllFrom(roslynExtensionsLocation));
}
}
Assemblies = builder.ToImmutable();
}

public IEnumerable<string> GetNormalizedLocationPaths(IOmniSharpEnvironment env)
{
if (LocationPaths == null || LocationPaths.Length == 0) return Enumerable.Empty<string>();
var normalizePaths = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
foreach (var locationPath in LocationPaths)
{
if (Path.IsPathRooted(locationPath))
{
normalizePaths.Add(locationPath);
}
else
{
normalizePaths.Add(Path.Combine(env.TargetDirectory, locationPath));
}
}
return normalizePaths;
}
}

public IReadOnlyList<Assembly> LoadAllFrom(string folderPath)
{
if (string.IsNullOrWhiteSpace(folderPath)) return Array.Empty<Assembly>();
try
{
var assemblies = new List<Assembly>();
foreach (var filePath in Directory.EnumerateFiles(folderPath, "*.dll"))
{
var assembly = LoadFrom(filePath);
if (assembly != null)
{
assemblies.Add(assembly);
}
}
return assemblies;
}
catch (Exception ex)
{
_logger.LogError(ex, $"An error occurred when attempting to access '{folderPath}'.");
return Array.Empty<Assembly>();
}
}

Thoughts, @filipw @david-driscoll?

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants