Fix runtime version detection for netstandard2.0 on .NET Framework#196
Merged
Fix runtime version detection for netstandard2.0 on .NET Framework#196
Conversation
) When the netstandard2.0 build of Elastic.Transport is loaded by a .NET Framework host (e.g. 4.7.2), the `#if !NETFRAMEWORK` code path is taken and `GetNetCoreVersion()` is called instead of `GetFullFrameworkRuntime()`. All detection strategies in `GetNetCoreVersion` fail on .NET Framework: - `Environment.Version.Major` is 4 (not >= 5) - `TargetFrameworkAttribute.FrameworkName` is `.NETFramework,Version=v4.7.2` which doesn't match the `.NETCoreApp,Version=v` prefix - `DOTNET_RUNNING_IN_CONTAINER` env var is not set This caused two problems: 1. On older versions (pre-8f2386d), the returned null was passed to `SemVersion.TryParse` which called `Regex.Match(null)`, throwing an `ArgumentNullException` on client initialization. 2. After the null guard added in 8f2386d, the version silently resolves to "0.0.0" instead of the actual framework version, producing incorrect `net=` values in the metadata telemetry header. This commit adds a fallback in `GetNetCoreVersion` that detects .NET Framework from `RuntimeInformation.FrameworkDescription` (which reports e.g. ".NET Framework 4.8.4614.0") and extracts a semver-compatible major.minor.0 version string. This only activates when all other detection methods have already failed, so existing code paths for .NET Core/.NET 5+ are unaffected. Closes #192 Co-authored-by: Cursor <cursoragent@cursor.com>
flobernd
approved these changes
Feb 23, 2026
Member
flobernd
left a comment
There was a problem hiding this comment.
Thank you! That was on my TODO for way too long already.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #192
GetNetCoreVersion()that detects .NET Framework fromRuntimeInformation.FrameworkDescriptionwhen thenetstandard2.0build is loaded by a .NET Framework hostmajor.minor.0version string (e.g."4.8.0"from".NET Framework 4.8.4614.0")Background
When the
netstandard2.0build runs on .NET Framework (e.g. 4.7.2), the#if !NETFRAMEWORKcode path is taken andGetNetCoreVersion()is called instead ofGetFullFrameworkRuntime(). All detection strategies fail:Environment.Version.Majoris 4 (not >= 5)TargetFrameworkAttribute.FrameworkNameis.NETFramework,Version=v4.7.2— doesn't match the.NETCoreApp,Version=vprefixDOTNET_RUNNING_IN_CONTAINERenv var is not setThis caused two issues:
nullwas passed toSemVersion.TryParse→Regex.Match(null)→ArgumentNullExceptionon client initializationEmpty(0.0.0), producing incorrectnet=0.0.0in the metadata telemetry headerMade with Cursor