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

.NET 8 Upgrade (Multi Framework targetting) #2181

Merged
merged 17 commits into from May 9, 2024
Merged

Conversation

seantleonard
Copy link
Contributor

@seantleonard seantleonard commented Apr 22, 2024

Why make this change?

What is this change?

    <TargetFrameworks>net8.0;net6.0</TargetFrameworks>
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
  <PackageVersion Include="Microsoft.AspNetCore.Authorization" Version="8.0.4" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
  <PackageVersion Include="Microsoft.AspNetCore.TestHost" Version="6.0.29" />
</ItemGroup>
GetHttpContext().Request.Headers[AuthorizationResolver.CLIENT_ROLE_HEADER];

Changed to be a conditional check:

if (!GetHttpContext().Request.Headers.TryGetValue(AuthorizationResolver.CLIENT_ROLE_HEADER, out StringValues headerValues) && headerValues.Count != 1)
  • Due to stricter .NET 8 nullability checks, DabCacheService specification of return type now specifies nullable jsonElement? to be consistent with method signature.
async (FusionCacheFactoryExecutionContext<JsonElement?> ctx, CancellationToken ct) =>
  • Startup class also gets a fix for stricter nullability when processing config file name. Previously a null value was possible according to the compiler:
    OLD:
string configFileName = Configuration.GetValue<string>("ConfigFileName", FileSystemRuntimeConfigLoader.DEFAULT_CONFIG_FILE_NAME);

NEW

string configFileName = Configuration.GetValue<string>("ConfigFileName") ?? FileSystemRuntimeConfigLoader.DEFAULT_CONFIG_FILE_NAME;

How was this tested?

This isn't a feature addition, but ensure that all existing tests pass.

  • Integration Tests
  • Unit Tests

…ues that weren't causing issues in .net6. Also removed "ISystemClock" from authenticationhandlers as it is deprecated in .net8. Internally .net8 provides replacement so only change on our part was removing the param. all references to headerdictionary use trygetvalue and check that result count is 1 to make sure user didn't supply >1 role. when that is fulfilled , the stringvalues object is converted to string and the nullable error goes away.
Add framework dependent constructors for EasyAuth/SimulatorAuthenticationHandlers. Directory.Packages.Props now has framework dependent section to define separate package versions.
@JerryNixon
Copy link
Contributor

We know there are performance improvements from this even if we do not measure for them. This includes improvements to JIT compilation and reduced memory consumption. The .NET team has bragged about this too much for us not to see those benefits coming for free. But the best part is the improved developer experience with the latest C# language features—that's the win!

By the way, .NET 8 is set to be EOL in 2026 (compared to .NET 7 in 2024). The team alternates LTS with only even versions (similar to DAB), which means our next upgrade will be .NET 10, not .NET 9 - which is considered a maintenance version. I bring this up because .NET 9 is right around the corner, and I don't want the team to feel discouraged to see .NET 9 coming out at the same time we upgrade to .NET 8. We're upgrading to the right version, LTS version of .NET, and it's perfect.

@seantleonard
Copy link
Contributor Author

Issue: dotnet/aspnetcore#53332

System.InvalidOperationException: Unable to resolve service for type 'Microsoft.AspNetCore.Routing.EndpointDataSource' while attempting to activate 'Microsoft.AspNetCore.Authorization.Policy.AuthorizationPolicyCache'.

Present in ClientRoleHeaderAuthorizationMiddlewareTests

Copy link
Contributor

@Aniruddh25 Aniruddh25 left a comment

Choose a reason for hiding this comment

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

Waiting for usage of nuget.org

.pipelines/templates/build-pipelines.yml Show resolved Hide resolved
src/Directory.Packages.props Outdated Show resolved Hide resolved
src/Core/Models/GraphQLFilterParsers.cs Show resolved Hide resolved
Nuget.config Outdated Show resolved Hide resolved
@Aniruddh25
Copy link
Contributor

Also, check if we get different binaries for each of the target framework, and if not, would the same binary work for both .net 8/.net6

@seantleonard
Copy link
Contributor Author

Issue: dotnet/aspnetcore#53332

System.InvalidOperationException: Unable to resolve service for type 'Microsoft.AspNetCore.Routing.EndpointDataSource' while attempting to activate 'Microsoft.AspNetCore.Authorization.Policy.AuthorizationPolicyCache'.

Present in ClientRoleHeaderAuthorizationMiddlewareTests

Fixed this via: dotnet/aspnetcore#53332 (comment)

…aimtypes aren't used. (dotnet8 change, but this test modification is backwards compatible per successful "net6 tests".)

update usings
update notice file generation with latest sqlclient version
behind scenes updated nuget dependency versions in our upstream feed. updating build pipeline comments. added mitigating helper function that is backwards compatible with net6 so that we don't get unhandled json exception that halts startup.
revert accidental nuget feed change.
@seantleonard
Copy link
Contributor Author

/azp run

Ignore seralize/deserialize unit test due to attempting to serialize when latest .net guidance says not to. Attached github discussion link from dotnet/runtime.
@seantleonard
Copy link
Contributor Author

/azp run

…nstall to dwsql/mssql windows pipelines. Not just linux.
@seantleonard
Copy link
Contributor Author

/azp run

…ction string in configs in both net6 and net8 folders.
@seantleonard
Copy link
Contributor Author

/azp run

Dockerfile Outdated Show resolved Hide resolved
…and net8.0 target frameworks explicitly and then optionally zip all the output.

Updated create-manifest-file to accommodate the net8 and net6 multitarget builds.
@seantleonard
Copy link
Contributor Author

/azp run

Copy link
Contributor

@Aniruddh25 Aniruddh25 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@ayush3797 ayush3797 left a comment

Choose a reason for hiding this comment

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

LGTM!

…t to preserve running on .net6 and apply fix to running on .net8 by removing object converter. After testing , this still works but a better solution may exist. moved Microsoft.Extensions.Configuration.Json/Binder to targetframework specific directory.packages.props section to align dependency versions with dotnetruntime versions. this helped ensure .net6 version of serializationdeserialization test to pass on both runtimes.
@seantleonard
Copy link
Contributor Author

/azp run

@seantleonard seantleonard merged commit 85323c7 into main May 9, 2024
7 checks passed
@seantleonard seantleonard deleted the dev/sean/dotnet8upgrade branch May 9, 2024 22:01
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.

.NET 8 upgrade
4 participants