Skip to content

ILVerify rejects classes which inherit default interface method implementations #46236

@Joe-Sewell-PreEmptive

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.

Metadata

Metadata

Assignees

Labels

area-Tools-ILVerificationIssues related to ilverify tool and IL verification in generalhelp wanted[up-for-grabs] Good issue for external contributors

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions