KirillOsenkov / MSBuildStructuredLog

A logger for MSBuild that records a structured representation of executed targets, tasks, property and item values.
MIT License
1.41k stars 188 forks source link

Missing Method Exception Version 2.2.158 #746

Closed groogiam closed 5 months ago

groogiam commented 5 months ago

I'm getting the following exception in version 2.2.158 when calling Microsoft.Build.Logging.StructuredLogger.BinaryLog.ReadBuild(binlogPath);

System.MissingMethodException: Method not found: 'Microsoft.Build.Logging.StructuredLogger.Build Microsoft.Build.Logging.StructuredLogger.BinaryLog.ReadBuild(System.String)'.

When I revert back to any previous version the error goes away.

My code is running in inside a mcr.microsoft.com/dotnet/sdk:7.0 linux container.

KirillOsenkov commented 5 months ago

when you update to the version 2.2.158, do you recompile the .dll that references StructuredLogger.dll? You need to recompile, there was a binary breaking change in the API. You can't just replace the StructuredLogger.dll unfortunately.

FYI @JanKrivanek we missed a binary breaking change to a public API. It's not a big deal, but I'm considering adding the overload back that doesn't have the second ReaderSettings parameter. Not sure if it's too late or still worth doing.

Presumably if people recompile from source it'll work fine because the new parameter is optional. However substituting the binary breaks.

KirillOsenkov commented 5 months ago

image

JanKrivanek commented 5 months ago

I'm voting for adding it back - to make update as easy as possible. It might actually be perfect time now - the new binlog format will go out wit .net 9 P1 - so the main wave of need for update might not have yet come

groogiam commented 5 months ago

when you update to the version 2.2.158, do you recompile the .dll that references StructuredLogger.dll? You need to recompile, there was a binary breaking change in the API. You can't just replace the StructuredLogger.dll unfortunately.

I am recompiling my dlls each time. This happens both locally and from CI/CD pipelines. The ci pipeline cleans sources each build and then runs publish. These publish output is stored as an artifact then used by the docker build in a subsequent release pipeline.

JanKrivanek commented 5 months ago

I am recompiling my dlls each time. This happens both locally and from CI/CD pipelines. The ci pipeline cleans sources each build and then runs publish. These publish output is stored as an artifact then used by the docker build in a subsequent release pipeline.

This is strange - is there a chance that you are recompiling just portion of the assemblies or have the calling code somewhere cached (nuget cache, artifacts cache etc.)? If not, a minimal repro code sample might be helpful here (or you can possibly just wait for an updated version once the methods are reintroduced)

KirillOsenkov commented 5 months ago

Indeed, MissingMethodException is a sign that something is going wrong on your end, it means mismatched binaries. Specifically, it means that you have a binary compiled against the old version of StructuredLogger.dll, but is used with the new version of StructuredLogger.dll. Could you please double-check that the binary that you compiled against the new version is the one being actually used?

Even though Jan will fix the API in the PR above, you shouldn't be impacted as long as you rebuild against the latest version.

groogiam commented 5 months ago

Indeed, MissingMethodException is a sign that something is going wrong on your end, it means mismatched binaries. Specifically, it means that you have a binary compiled against the old version of StructuredLogger.dll, but is used with the new version of StructuredLogger.dll. Could you please double-check that the binary that you compiled against the new version is the one being actually used?

Even though Jan will fix the API in the PR above, you shouldn't be impacted as long as you rebuild against the latest version.

It is indeed very strange. Locally I have cleaned sources and, deleted my bin and obj folders in all projects and it still happens. I have also downloaded the published artifacts from ci pipelines as well as downloaded the dll's from my containers and checked the versions. The references seem to match so I'm at a loss. I have reverted to the previous version for the time being.

KirillOsenkov commented 5 months ago

I normally use ILSpy to open the dlls in question and validate that the call site is calling the method overload I expect.