You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Introduce an EntityFrameworkExperimentalAttribute, which works like the EntityFrameworkInternalAttribute, except that it indicates a feature is experimental for the current release, rather than internal.
RequiresPreviewFeaturesAttribute was created in .NET 6 and is part of the shared framework, with an analyzer that reports builds errors if the caller hasn't opted in to using preview features. I'd be interested to know if that attribute could meet these needs instead of having another mechanism.
Build correctly warns for using EF internal code, but nothing for the preview attribute:
PS C:\local\code\TestPreviewFeature> dotnet build
Microsoft (R) Build Engine version 17.0.0-preview-21458-01+2c5510013 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.
Determining projects to restore...
All projects are up-to-date for restore.
You are using a preview version of .NET. See: https://aka.ms/dotnet-core-preview
C:\local\code\TestPreviewFeature\Program.cs(61,9): warning EF1001: Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter<string?, string?> is an internal API that supports the Entity Framework Core infrastructure and not subject to the same compatibility standards as public APIs. It may be changed or removed without notice in any release. [C:\local\code\TestPreviewFeature\TestPreviewFeature.csproj]
TestPreviewFeature -> C:\local\code\TestPreviewFeature\bin\Debug\net6.0\TestPreviewFeature.dll
Build succeeded.
C:\local\code\TestPreviewFeature\Program.cs(61,9): warning EF1001: Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter<string?, string?> is an internal API that supports the Entity Framework Core infrastructure and not subject to the same compatibility standards as public APIs. It may be changed or removed without notice in any release. [C:\local\code\TestPreviewFeature\TestPreviewFeature.csproj]
1 Warning(s)
0 Error(s)
Time Elapsed 00:00:01.96
Running also results in no errors:
PS C:\local\code\TestPreviewFeature> dotnet run
Found: RequiresPreviewFeaturesAttribute
Found: EntityFrameworkInternalAttribute
warn: 10/6/2021 12:08:53.212 CoreEventId.SensitiveDataLoggingEnabledWarning[10400] (Microsoft.EntityFrameworkCore.Infrastructure)
Sensitive data logging is enabled. Log entries and exception messages may include sensitive application data; this mode should only be enabled during development.
info: 10/6/2021 12:08:53.243 CoreEventId.ContextInitialized[10403] (Microsoft.EntityFrameworkCore.Infrastructure)
Entity Framework Core 6.0.0-dev initialized 'SomeDbContext' using provider 'Microsoft.EntityFrameworkCore.InMemory:6.0.0-dev' with options: SensitiveDataLoggingEnabled StoreName=Test
info: 10/6/2021 12:08:53.307 InMemoryEventId.ChangesSaved[30100] (Microsoft.EntityFrameworkCore.Update)
Saved 1 entities to in-memory store.
info: 10/6/2021 12:08:53.328 CoreEventId.ContextInitialized[10403] (Microsoft.EntityFrameworkCore.Infrastructure)
Entity Framework Core 6.0.0-dev initialized 'SomeDbContext' using provider 'Microsoft.EntityFrameworkCore.InMemory:6.0.0-dev' with options: SensitiveDataLoggingEnabled StoreName=Test
X
I'm unsure from those details if you have 6.0 RC2+ SDK in place. The CA2252 (Preview Feature) analyzer was only recently set to report build errors when usage of preview features was detected--it was reporting as info level when it was first introduced. Otherwise, it does look to me like referencing the base constructor should report a diagnostic. If you are indeed using RC2+ SDK, let me know and we can pair up to figure out what's happening.
I wonder if this is related to using <ProjectReference> rather than <PackageReference> - I've seen many cases where this impacts things (especially since an analyzer is involved)...
@roji I tried it with a direct assembly reference, rather than a project reference, and there was no difference. Didn't try building it into a package.
Thanks for this. I meant to leave a comment earlier--I'm investigating this. It's not behaving as I expected it to, and I've repro'd this behavior with an even simpler scenario. I'll follow back up later.
@ajcvickers Thanks a bunch for trying this out and letting me know it wasn't working as expected. This uncovered that we had a 6.0 GA ship-blocker issue lurking here that had gone undetected. That fix is now in place and it will make the GA snap.
To work around the bug until you take in an SDK build with the fix though, you can select the CA2252 analyzer from your dependencies and set it to Error severity in your project's editorconfig.
Activity
jeffhandley commentedon Oct 5, 2021
RequiresPreviewFeaturesAttributewas created in .NET 6 and is part of the shared framework, with an analyzer that reports builds errors if the caller hasn't opted in to using preview features. I'd be interested to know if that attribute could meet these needs instead of having another mechanism.ajcvickers commentedon Oct 5, 2021
Thanks @jeffhandley. I'll look into this tomorrow. We may be able to use it in 6.0 for #26232.
ajcvickers commentedon Oct 6, 2021
@jeffhandley I can't seem to make RequiresPreviewFeaturesAttribute work. I don't get any warnings or errors when using it. What am I missing here?
I'm using a local build of EF Core. My code checks that the attribute is present:
csproj:
Build correctly warns for using EF internal code, but nothing for the preview attribute:
Running also results in no errors:
jeffhandley commentedon Oct 7, 2021
I'm unsure from those details if you have 6.0 RC2+ SDK in place. The
CA2252(Preview Feature) analyzer was only recently set to report build errors when usage of preview features was detected--it was reporting asinfolevel when it was first introduced. Otherwise, it does look to me like referencing thebaseconstructor should report a diagnostic. If you are indeed using RC2+ SDK, let me know and we can pair up to figure out what's happening.Thanks!
ajcvickers commentedon Oct 7, 2021
SDK is 6.0.100-rc.2.21505.57
ajcvickers commentedon Oct 7, 2021
@jeffhandley I tried creating a minimal class library and a console app referencing it (no EF), and I still can't get it to work. See attached.
TMin.zip
roji commentedon Oct 7, 2021
I wonder if this is related to using
<ProjectReference>rather than<PackageReference>- I've seen many cases where this impacts things (especially since an analyzer is involved)...ajcvickers commentedon Oct 7, 2021
@roji I tried it with a direct assembly reference, rather than a project reference, and there was no difference. Didn't try building it into a package.
roji commentedon Oct 7, 2021
Could be worth a try, we know that analyzers and assembly/project/package references are tricky..
jeffhandley commentedon Oct 14, 2021
Thanks for this. I meant to leave a comment earlier--I'm investigating this. It's not behaving as I expected it to, and I've repro'd this behavior with an even simpler scenario. I'll follow back up later.
ajcvickers commentedon Oct 14, 2021
Thanks @jeffhandley
jeffhandley commentedon Oct 16, 2021
@ajcvickers Thanks a bunch for trying this out and letting me know it wasn't working as expected. This uncovered that we had a 6.0 GA ship-blocker issue lurking here that had gone undetected. That fix is now in place and it will make the GA snap.
To work around the bug until you take in an SDK build with the fix though, you can select the CA2252 analyzer from your dependencies and set it to Error severity in your project's editorconfig.
KennethHoff commentedon Jul 22, 2023
Should this be closed with the addition of [Experimental] Attribute in .Net 8?
roji commentedon Jul 22, 2023
@KennethHoff yeah, probably - removing from the backlog to re-triage.