Skip to content

Silence Add-Type CS1701 System.Runtime version warnings #123

@jamescrosswell

Description

@jamescrosswell

Running any sample on PowerShell Core (.NET 8+) prints five copies of:

Add-Type: error CS1701: Assuming assembly reference 'System.Runtime, Version=9.0.0.0, ...' used by 'Sentry' matches identity 'System.Runtime, Version=10.0.0.0, ...' of 'System.Runtime', you may need to supply runtime policy
Add-Type: Cannot add type. Compilation errors occurred.

The warnings are harmless — .NET binds successfully and the module works — but they're noisy and look alarming to anyone running the samples for the first time.

Analysis

The warnings come from the Add-Type call in modules/Sentry/Sentry.psm1 that compiles SentryEventProcessor.cs with -ReferencedAssemblies $sentryDllPath. Roslyn compiles against Sentry.dll, whose metadata references System.Runtime at a version that differs from the version loaded by the host process (e.g. PowerShell on .NET 10 loads System.Runtime 10.0.0.0, while Sentry.dll for net8.0/net9.0 references 9.0.0.0). Each mismatched reference emits one CS1701, hence "five copies".

Solution

Pass -CompilerOptions '/nowarn:CS1701;CS1702' (or equivalent) to the Add-Type call in Sentry.psm1 so Roslyn suppresses the harmless binding-redirect warnings while still surfacing real compile errors.

Reproduces with any sample, e.g. pwsh ./samples/locate-city.ps1 Paris.

Metadata

Metadata

Assignees

No one assigned
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions