Skip to content

.NET version detection doesn't work as expected for netstandard2.0 builds #192

@onyxmaster

Description

@onyxmaster

Hi!

Currently, there are multiple TFMs for the project, which include netstandard2.0 and net462. For some cases it can be required to use netstandard2.0 build under .NET Framework (for example 4.7.2) instead of net462 (in our case it's done to prevent using HttpWebRequest pipeline in favor of StandardSocketsHttpHandler). Unfortunately, in this case the GetNetCoreVersion is used, which does not function properly under .NET Framework, returning null, which then leads to ANE on initialization. To work around this issue, currently we're forced to use something like this in our code:

#if NETFRAMEWORK
            // This is a workaround for Elastic.Transport issue (ANE) with detecting .NET version when using .NET Standard 2.0 build on .NET Framework
            try
            {
                Environment.SetEnvironmentVariable("DOTNET_RUNNING_IN_CONTAINER", "true");
                Environment.SetEnvironmentVariable("DOTNET_VERSION", "4.7.2");
                using (new Elastic.Clients.Elasticsearch.ElasticsearchClientSettings())
                {
                }
            }
            finally
            {
                Environment.SetEnvironmentVariable("DOTNET_VERSION", null);
                Environment.SetEnvironmentVariable("DOTNET_RUNNING_IN_CONTAINER", null);
            }
#endif

While we're mostly okay with this workaround, I think that the non-Framework builds of Elastic.Transport should function normally under .NET Framework. If you do not think that this should be changed, given that .NET Standard 2.0 requires at least .NET Framework 4.6.1 to load correctly, it is safe to assume that if the other checks failed the version is, well, 4.6.1 and return it instead of null to prevent crashing.

I understand that this issue is of low-priority because this is not a typical configuration, but I decided that I have to point out the problem instead of just keeping it in our internal documentation only.

Thanks for reading.

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