Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

ILVerify rejects classes which inherit default interface method implementations #46236

Description

@Joe-Sewell-PreEmptive

Description

ILVerify 5.0.0 does not verify a class which implements an interface which contains a method which is virtual but not abstract. In other words, it doesn't seem to support default interface methods.

Repro steps:

  1. Create a new C# console application (e.g. dotnet new console).
  2. Ensure the new project has a TargetFramework of net5.0.
  3. Declare an interface and a method within that interface that provides an implementation. E.g.:
    interface I
    {
        public string HasDefaultImplementation()
        {
            return "I::HasDefaultImplementation";
        }
    }
    
  4. Declare a class which implements that interface but does not provide an implementation for that method. E.g:
    class C : I { }
    
  5. Build and run the project to show that there are no errors building or at runtime. (Optionally, you can exercise the types declared, such as by calling HasDefaultImplementation on an instance of C which has been cast to I.)
  6. Install ILVerify as a local tool (e.g. dotnet new tool-manifest then dotnet tool install dotnet-ilverify).
  7. Run ILVerify on the built assembly (e.g. dotnet ilverify bin\Debug\net5.0\ILVerifyRepro.dll -r "C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.0\*.dll").

Expected behavior: the assembly verifies completely.

Actual behavior: the following error is reported:

[MD]: Error: Class implements interface but not method, Class: '[ILVerifyRepro]ILVerifyRepro.C' Interface: '[ILVerifyRepro]ILVerifyRepro.I' Missing method: '[ILVerifyRepro]ILVerifyRepro.I.HasDefaultImplementation()'.

Reproduction (attachment): ILVerifyRepro.zip

Rationale:

It sounds like this issue might already be known, based on this comment, but I figured I should report it as its own issue both for better visibility and tracking, and also to indicate there's some desire outside of Microsoft / the .NET developers for an accurate ILVerify. Specifically, I represent the Dotfuscator team at PreEmptive, and an up-to-date ILVerify would be very helpful in ensuring we continue to obey the runtime's rules when modifying customers' assemblies, in light of the recent changes to interface methods.

Configuration

  • The example console app targets .NET 5.0. Based on the output of --list-runtimes, the only 5.0 runtime I have installed is Microsoft.NETCore.App 5.0.0.
  • Running on Windows 10, Version 1903 (10.0.18362.592).
  • The machine is x64.
  • I would think it unlikely that this issue is configuration-specific.

Regression?

The oldest version of dotnet-ilverify listed on NuGet.org is 5.0.0-preview.7.20364.11. It errors with a different message:

Error: System.Resources.MissingManifestResourceException: Could not find the resource "ILVerification.Strings.resources" among the resources "" 
embedded in the assembly "ILVerify", nor among the resources in any satellite assemblies for the specified culture. Perhaps the resources were embedded with an incorrect name.
   at System.Resources.ManifestBasedResourceGroveler.HandleResourceStreamMissing(String fileName)
   at System.Resources.ManifestBasedResourceGroveler.GrovelForResourceSet(CultureInfo culture, Dictionary`2 localResourceSets, Boolean tryParents, Boolean createIfNotExists)
   at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo culture, Boolean createIfNotExists, Boolean tryParents)
   at System.Resources.ResourceManager.GetString(String name, CultureInfo culture)
   at ILVerify.Verifier.<>c__DisplayClass13_0.<VerifyType>b__1(VerifierError code, Object[] args)
   at Internal.TypeVerifier.TypeVerifier.VerificationError(VerifierError error, Object[] args)
   at Internal.TypeVerifier.TypeVerifier.VerifyInterfaces()
   at Internal.TypeVerifier.TypeVerifier.Verify()
   at ILVerify.Verifier.VerifyType(EcmaModule module, TypeDefinitionHandle typeHandle)
   at ILVerify.Verifier.Verify(PEReader peReader, TypeDefinitionHandle typeHandle, Boolean verifyMethods)+MoveNext()
   at ILVerify.Program.VerifyTypes(PEReader peReader, EcmaModule module, String path, Int32& numErrors, Int32& verifiedTypeCounter, Int32& typeCounter)
   at ILVerify.Program.VerifyAssembly(PEReader peReader, EcmaModule module, String path)
   at ILVerify.Program.Run()
   at ILVerify.Program.Run(Options options)

The next newest version, 5.0.0-preview.8.20407.11, produces the same error as in 5.0.0.

Activity

  1. Dotnet-GitSync-Bot commented on Dec 18, 2020

    @Dotnet-GitSync-Bot
    Collaborator

    I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

  2. added
    untriaged
    on Dec 18, 2020
  3. added
    area-Tools-ILVerification
    on Dec 19, 2020
  4. added
    help wanted
    on Dec 19, 2020
  5. ghost added
    in-pr
    on Dec 26, 2020
  6. ghost removed
    in-pr
    on Dec 27, 2020
  7. MichalStrehovsky commented on Dec 28, 2020

    @MichalStrehovsky
    Member

    This issue is closed, but default interface methods are still not fully supported. I assume e.g. Foo will still fail to ILVerify here:

    interface IFoo { void Frob() }
    interface IBar : IFoo { void IFoo.Frob() { WriteLine("Hello"); } }
    
    class Foo : IBar { }

    We could either reopen this, make a new issue, or just ignore the issue until someone hits it.

  8. jkotas commented on Dec 28, 2020

    @jkotas
    Member

    Let's reopen this issue. @bbartels Would you be interested in taking a look?

  9. reopened this on Dec 28, 2020
  10. bbartels commented on Dec 28, 2020

    @bbartels
    Contributor

    Can do, yes!

  11. added
    needs-further-triage
    and removed
    untriaged
    on Jul 20, 2021
  12. added this to the 6.0.0 milestone on Jul 20, 2021
  13. 1 remaining item

  14. removed
    needs-further-triage
    on Jul 27, 2021
  15. modified the milestones: 6.0.0, Future on Jul 27, 2021
  16. bbartels commented on Jul 28, 2021

    @bbartels
    Contributor

    Hi Julie,
    definitely still interested, however I don't know when I can get around to doing it, uni is keeping me very busy at the moment.

  17. bbartels commented on Nov 3, 2021

    @bbartels
    Contributor

    Hi @JulieLeeMSFT,

    I found some time over the weekend and implemented a fix for this. Ran into another bug on the way, but i'll open a separate issue for that. Could you assign this to me? I'll create a PR later today, once I write the appropriate tests!

  18. EgorBo commented on Nov 3, 2021

    @EgorBo
    Member

    re-assigned to you, thanks!

  19. assigned and unassigned on Nov 3, 2021
  20. ghost added
    in-pr
    on Nov 3, 2021
  21. ghost removed
    in-pr
    on Jan 3, 2022
  22. ghost locked as resolved and limited conversation to collaborators on Feb 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-Tools-ILVerificationhelp wanted

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions