-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I have a problem, hope you can help me solve it #8
Comments
@q913777031 Difficult to help you here without a reproducable example. Could you run snich from source and see where the exception is thrown? |
I'm also getting this error. It went away when I realised that I had a project with Making sure both projects were set to Hope that helps? |
@patriksvensson would it be helpful to output the stack trace when an unknown exception is hit? |
I also have this error, what can I do to help track it down? the issue happens in this method: private static string GetNearestFrameworkMoniker(this NuGetFramework framework, IEnumerable<string> candidates)
{
var provider = DefaultFrameworkNameProvider.Instance;
var reducer = new FrameworkReducer();
var mappings = new Dictionary<NuGetFramework, string>(
candidates.ToDictionary(
x => NuGetFramework.Parse(x, provider), y => y, new NuGetFrameworkFullComparer()));
return mappings[reducer.GetNearest(framework, mappings.Keys)];
} |
@yooakim I would need some kind of minimal reproducible example to be able to fix it. |
@patriksvensson I'll try to spend some time on this over the holidays ;-) Will see what I find. |
This happens when you dont have the right dotnet installed.. |
The error occurs when there isn't a framework that matches the current target. In my case I was working on a solution that was a net8.0 project that was referencing a net472 lib. // AnalyzerResultExtensions.cs
namespace Snitch.Analysis
{
internal static class AnalyzerResultExtensions
{
+ private static readonly FrameworkReducer FrameworkReducer = new();
+ private static readonly NuGetFrameworkFullComparer NuGetFrameworkFullComparer = new();
public static string? GetProjectAssetsFilePath(this IAnalyzerResult result)
{
return result?.GetProperty("ProjectAssetsFile");
}
- public static string GetNearestFrameworkMoniker(this IEnumerable<IAnalyzerResult> source, string framework)
+ public static IAnalyzerResult? GetNearestFrameworkMoniker(this IEnumerable<IAnalyzerResult> source, string framework)
{
- var current = NuGetFramework.Parse(framework, DefaultFrameworkNameProvider.Instance);
- return current.GetNearestFrameworkMoniker(source.Select(x => x.TargetFramework));
+ var nugetFrameworks = source
+ .ToDictionary(
+ c => NuGetFramework.Parse(c.TargetFramework, DefaultFrameworkNameProvider.Instance),
+ NuGetFrameworkFullComparer);
+
+ var current = NuGetFramework.Parse(framework, DefaultFrameworkNameProvider.Instance);
+ return FrameworkReducer.GetNearest(current, nugetFrameworks.Keys) is { } nuGetFramework
+ ? nugetFrameworks[nuGetFramework]
+ : null;
}
-
- private static string GetNearestFrameworkMoniker(this NuGetFramework framework, IEnumerable<string> candidates)
- {
- var provider = DefaultFrameworkNameProvider.Instance;
- var reducer = new FrameworkReducer();
-
- var mappings = new Dictionary<NuGetFramework, string>(
- candidates.ToDictionary(
- x => NuGetFramework.Parse(x, provider), y => y, new NuGetFrameworkFullComparer()));
-
- return mappings[reducer.GetNearest(framework, mappings.Keys)];
- }
}
} // ProjectBuilder.cs
namespace Snitch.Analysis
{
internal sealed class ProjectBuilder
{
private IAnalyzerResult? Build(AnalyzerManager manager, Project project, string? tfm, int indentation)
{
// ...
var projectAnalyzer = manager.GetProject(project.Path);
var results = (IEnumerable<IAnalyzerResult>)projectAnalyzer.Build();
if (!string.IsNullOrWhiteSpace(tfm))
{
- var closest = results.GetNearestFrameworkMoniker(tfm);
+ if (results.GetNearestFrameworkMoniker(tfm) is not { } closest)
+ {
+ throw new Exception(
+ $"""
+ Incompaitble frameworks detected!
+ The framework '{tfm}' is not a valid for the project {project.Name}, possible frameworks:
+ {string.Join("\n", results.Select(k => $" * {k.TargetFramework}"))}
+ """);
+ }
results = results.Where(p => p.TargetFramework.Equals(closest.TargetFramework, StringComparison.OrdinalIgnoreCase));
}
return results.FirstOrDefault();
}
}
} Obviously you can change the behaviour to just skip the project if you want, but I think a hard fail is a good error to show to he user. |
When I follow the steps, I get the following error.
Error: Value cannot be null. (Parameter 'key')
I have no idea deal with this ,please help me,thanks
The text was updated successfully, but these errors were encountered: