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

[0.10.0 netstandard] System.MissingMethodException : Method not found: 'Int32 Mono.Cecil.MetadataReader.ReadCodeSize(Mono.Cecil.MethodDefinition)'. #500

Closed
SteveGilham opened this issue Mar 21, 2018 · 10 comments

Comments

@SteveGilham
Copy link
Contributor

This is a change of behaviour since 0.10-beta7 -- loading an assembly built with mcs with a .mdb symbol file used to work quite happily from a .net core process the same as from old-fashioned .net. Old-fashioned .net still works with 0.10 final, but now using a .net core process to load the same assembly, a System.MissingMethodException with this stack trace emerges

Result StackTrace:	
at Mono.Cecil.Mdb.MdbReader.<>c.<ReadCodeSize>b__7_0(MethodDefinition m, MetadataReader reader)
   at Mono.Cecil.ModuleDefinition.Read[TItem,TRet](TItem item, Func`3 read)
   at Mono.Cecil.Mdb.MdbReader.Read(MethodDefinition method)
   at Mono.Cecil.Cil.CodeReader.ReadMethodBody()
   at Mono.Cecil.Cil.CodeReader.ReadMethodBody(MethodDefinition method)
   at Mono.Cecil.ModuleDefinition.Read[TItem,TRet](TRet& variable, TItem item, Func`3 read)
   at Mono.Cecil.MethodDefinition.get_Body()
@jbevain
Copy link
Owner

jbevain commented Mar 21, 2018

How weird. Thanks for reporting this. You're using both the Mono.Cecil.dll and Mono.Cecil.Mdb.dll from the lib/netstandard1.3 nuget?

@SteveGilham
Copy link
Contributor Author

Being a .net core app, it just says <PackageReference Include="Mono.Cecil" Version="0.10.0" /> in the project file, so I'm assuming that doesn't have its wires crossed.

Here's an assembly that shows the issue : Sample1.zip

@jbevain
Copy link
Owner

jbevain commented Mar 21, 2018

Thanks, I'll have a look pronto.

@jbevain
Copy link
Owner

jbevain commented Mar 21, 2018

This actually looks like #495.

@jbevain
Copy link
Owner

jbevain commented Mar 21, 2018

The code looks alright, the method that is called is there, but is internal, which is why we have an InternalsVisibleTo between Mono.Cecil and Mono.Cecil.Mdb

@jbevain
Copy link
Owner

jbevain commented Mar 21, 2018

The reason why it changed between the beta7 and the final is b4f4571 that introduced the call.

@jbevain
Copy link
Owner

jbevain commented Mar 21, 2018

@SteveGilham I can't seem to repro.

I created a new dotnet project:

dotnet new console
dotnet add package Mono.Cecil

Modified the csproj so that it reads:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFrameworks>netcoreapp2.0;net46</TargetFrameworks>
  </PropertyGroup>

  <ItemGroup>
    <None Include="Sample1.exe">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Include="Sample1.exe.mdb">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Mono.Cecil" Version="0.10.0" />
  </ItemGroup>

</Project>

Wrote:

using System;
using System.Linq;

using Mono.Cecil;

namespace _500repro
{
  class Program
  {
    static void Main(string[] args)
    {
      Console.WriteLine("Hello World!");
      
      using (var module = ModuleDefinition.ReadModule("Sample1.exe", new ReaderParameters { ReadSymbols = true }))
      {
        Console.WriteLine($"Module has symbols: {module.HasSymbols}");

        foreach (var method in module.GetTypes().SelectMany(t => t.Methods).Where(m => m.HasBody))
        {
          Console.WriteLine($"On method: {method.FbullName}");
          Console.WriteLine(method.Body);
        }
      }
    }
  }
}

And when running for both frameworks it runs without crashing on getting the method body.

Do you have a way to reproduce this?

@SteveGilham
Copy link
Contributor Author

I'm in the process of cutting down to a simple repro case. Will update later.

@SteveGilham
Copy link
Contributor Author

I've found the culprit. It's the NUnit3TestAdapter v 3.10.0 which includes also Mono.Cecil, from beta6

[assembly: AssemblyInformationalVersion("0.10.0.0-beta6")]
[assembly: AssemblyTitle("Mono.Cecil")]

and that's going to be loaded ahead of any of my code.

@SimonCropp
Copy link
Contributor

It's the NUnit3TestAdapter v 3.10.0 which includes also Mono.Cecil, from beta6

@SteveGilham one of reasons i moved to xunit

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

No branches or pull requests

3 participants