Skip to content

PostSharp build fails when Newtonsoft.Json is in the GAC (error 0x80131050) #8

@gfraiteur

Description

@gfraiteur

Summary

PostSharp's build-time compiler fails to load its bundled Newtonsoft.Json when a different binary of the same assembly (same version 13.0.0.0, same public key token, but different build) is registered in the GAC. The CLR rejects the load with error 0x80131050.

Root Cause

PostSharp ships its own copy of Newtonsoft.Json 13.0.0.0 in its installation directory. At build time, the PostSharp compiler (running as a 64-bit process) attempts to load this bundled copy. However, the CLR detects that an assembly with the same identity (version + public key token) but different binary content already exists in the GAC, and refuses to load the PostSharp-bundled copy.

The AMD64 reference visible in PostSharp logs is a red herring — it is just the first GAC probe attempt by PostSharp's internal assembly resolution. It falls back to MSIL, which is the actual GAC entry.

Reproduction

  • Have Newtonsoft.Json 13.0.0.0 registered in the GAC (e.g., installed by another application).
  • Build a project with PostSharp — the build fails with error 0x80131050.
  • The issue does not occur on machines where Newtonsoft.Json is not in the GAC.

Workarounds

  • Remove Newtonsoft.Json from the GAC.
  • Replace the GAC copy with the exact binary that PostSharp bundles (may break other GAC consumers).

Possible Fixes

  1. Investigate whether Newtonsoft.Json still needs to be bundled with PostSharp.
  2. Give priority to GAC copies over PostSharp's bundled copies.
  3. Mask this assembly from the GAC during PostSharp's assembly resolution.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions