Skip to content
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

[BUG] dotnet-provider method referenced rule not found on sample project #694

Open
djzager opened this issue Aug 23, 2024 · 1 comment
Open
Labels
kind/bug Categorizes issue or PR as related to a bug. priority/critical-urgent Highest priority. Must be actively worked on as someone's top priority right now. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Milestone

Comments

@djzager
Copy link
Member

djzager commented Aug 23, 2024

Construct a very simple .NET Project.

Start by creating a dotnet-example directory. Then create a project file...so it will build

// Goes in dotnet-example/DotnetExample.csproj
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

</Project>

Then write the program.

// This would go in dotnet-example/Program.cs
using System;
using System.Net;
using System.IO;

// Copied from https://learn.microsoft.com/en-us/dotnet/api/system.net.webclient?view=net-8.0
public class Test
{
    public static void Main(string[] args)
    {
        if (args == null || args.Length == 0)
        {
            throw new ApplicationException("Specify the URI of the resource to retrieve.");
        }
        using WebClient client = new WebClient();

        // Add a user agent header in case the
        // requested URI contains a query.

        client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");

        using Stream data = client.OpenRead(args[0]);
        using StreamReader reader = new StreamReader(data);
        string s = reader.ReadToEnd();
        Console.WriteLine(s);
    }
}

Write a very basic rule

// ./dotnet-example/rule-example.yaml
- message: 'System.Net.WebClient found. Consider replacing with System.Net.Http.HttpClient.'
  ruleID: dotnet-deprecated-001
  effort: 2
  when:
    dotnet.referenced:
      namespace: "System.Net"
      pattern: WebClient

Run kantra against this rule: kantra analyze --input ./dotnet-example --output ./report --rules ./dotnet-example/rule-example.yaml --log-level 10.

Provider does not find the rule.

NOTE It is worth pointing out that we can find the "NonPortableMethod" in the HelloWorld example. Maybe this is a problem with how assemblies paths are shown in .net8?

@djzager djzager added kind/bug Categorizes issue or PR as related to a bug. priority/critical-urgent Highest priority. Must be actively worked on as someone's top priority right now. triage/accepted Indicates an issue or PR is ready to be actively worked on. labels Aug 23, 2024
@djzager djzager added this to Planning Aug 23, 2024
@github-project-automation github-project-automation bot moved this to 🆕 New in Planning Aug 23, 2024
@djzager djzager added this to the v0.5.2 milestone Aug 23, 2024
@djzager
Copy link
Member Author

djzager commented Aug 23, 2024

@dymurray When I was working through what @shawn-hurley was experiencing I had kind of chalked it up to not being a method call, maybe it was just hard to make the query correct or we should change the query.

@dymurray dymurray changed the title [BUG] dotnet-provider can't find the most basic of methods [BUG] dotnet-provider method referenced rule not found on sample project Aug 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug. priority/critical-urgent Highest priority. Must be actively worked on as someone's top priority right now. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
Status: 🆕 New
Development

No branches or pull requests

1 participant