Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AspNetCore & FrameworkReference #2412

Closed
wants to merge 36 commits into from

Conversation

TimothyMothra
Copy link
Member

@TimothyMothra TimothyMothra commented Sep 15, 2021

Fix Issue #2251.

Convert AspNetCore and AspNetCore.Tests projects to use FrameworkReference.

Todo

  • confirm if we want to remove netstandard2.0 or keep for backcompat.
  • fix stubborn tests

Changes

Checklist

  • I ran Unit Tests locally.
  • CHANGELOG.md updated with one line description of the fix, and a link to the original issue if available.

For significant contributions please make sure you have completed the following items:

  • Design discussion issue #
  • Changes in public surface reviewed

The PR will trigger build, unit tests, and functional tests automatically. Please follow these instructions to build and test locally.

Notes for authors:

  • FxCop and other analyzers will fail the build. To see these errors yourself, compile localy using the Release configuration.

Notes for reviewers:

  • We support comment build triggers
    • /AzurePipelines run will queue all builds
    • /AzurePipelines run <pipeline-name> will queue a specific build

@TimothyMothra TimothyMothra changed the title [WIP] AspNetCore & FrameworkReference AspNetCore & FrameworkReference Sep 16, 2021

/// <summary>
/// Initializes a new instance of the <see cref="AspNetCoreEnvironmentTelemetryInitializer"/> class.
/// </summary>
/// <param name="environment">HostingEnvironment to provide EnvironmentName to be added to telemetry properties.</param>
public AspNetCoreEnvironmentTelemetryInitializer(IHostingEnvironment environment)
public AspNetCoreEnvironmentTelemetryInitializer(IHostEnvironment environment)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this'd be considered breaking change?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure the best way to handle this. The former type appears to have been removed from .NET.

Error Message:

'IHostingEnvironment' is obsolete: 'This type is obsolete and will be removed in a future version.
The recommended alternative is Microsoft.AspNetCore.Hosting.IWebHostEnvironment.'

dotnet/aspnetcore#7749

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, i think i have a fix for this.
Marking the former constructor using IHostingEnvironment as Obsolete fixes the build errors without breaking the PublicApi.
And then I added a new constructor using the newer IHostEnvironment for NetCore3.1 and Net5.0 support.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think i have a comprehensive fix for this.

Original constructor expected IHostingEnvironment. <-- now obsolete
I've added two new constructors;

  • one expecting IHostEnvironment. <-- This is now the recommended approach.
  • and one expecting both IHostEnvironment and IHostingEnvironment. <-- for backcompat

It appears that the framework can add BOTH to the Dependency Injection was causing the SDK initialization to fail because of "ambiguous constructors".
The constructor with both params solves this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants