Efcore: Analyzer: detect usage of public internal code

Created on 22 May 2018  路  19Comments  路  Source: dotnet/efcore

(I thought we already had an issue for this but I couldn't find it)

In the discussion with provider writers at https://github.com/aspnet/EntityFrameworkCore/issues/11266#issuecomment-377675119 there was some consensus that an analyzer would be the best way to prevent anyone from unintentionally taking a dependency on public internal code.

closed-fixed type-enhancement

Most helpful comment

image

image

All 19 comments

Hey, once this is done can we maybe remove all the XML docs about APIs being internal?

Those XML docs shows up in intellisense I think. So we may still want them.

That's true, although if you're using the analyzer you're getting a much stronger warning squiggly instead... Do we think there's enough value in keeping them for intellisense?

I think their main purpose is for the API Docs since there's no infrastructure to exclude classes by namespace.

Additional idea by @bricelam: have a test which runs the analyzer over our providers, to make sure no internal usages creep in. Apparently analyzers don't get executed when brought in via <ProjectReference>, only <PackageReference> (馃槙 )

@roji Going forward, can you add the "closed-fixed" label when you close and issue because it has been done?

Oops, sure thing!

How am I supposed to be able to tell what part of my code is causing this analyzer warning? All I'm seeing is this:

EF1001: Internal EF Core API usage.

No indication which method or line or file in my application code is the culprit.

@Yuck where exactly are you seeing these warnings without method/line/file? When building either in VS, the command or any other IDE you should be seeing regular warning messages which include those as always.

image

image

@reft which VS version?
Reload your solution/restart VS

@Reft that UI simply shows the analyzers active in the project and the diagnostics they potentially produce - it is not a list of actual warnings in your project's code.

Build the project and open the build errors/warnings pane.

That's a terrible way to present it in the IDE then. Why does the "dependencies" node have the warning icon over if nothing is _actually_ wrong? In projects that don't have analyzers which _might_ produce a warning, that icon is not present.

At-a-glance it's confusing as it seems that there's something wrong with my project, if it includes one of these analyzers. I'll eventually train myself to ignore this visual noise, at which point having this detail in that part of the project pane is useless.

I may be a slightly wrong, as I don't use VS on a regular basis - this may indicate that there are some warnings coming from that analyzer; am not sure about that, but try fixing the warnings and see whether the warning disappears. The actual warnings with their file and line numbers will be seen in the build error/warnings pane, just like any warning coming from the compiler. Either way, this doesn't really have anything to do with EF Core, we just provider a standard analyzer.

@Yuck repeat: which VS version?

Reload solution/restart VS, IT is a VS gui issue, nothing to do with this particular analyser.

@ErikEJ Yes, obviously I have "turned it off and back on again".

It may well be a VS UI issue, but then why do you suppose the UI only shows one of the many warnings that the analyzer can generate? Is there any chance whatsoever that the analyzer is defective in a way that _causes_ the UI to show one that one condition (EF1001)?

@Yuck Yes, it's possible. But so far we have not been able to reproduce this--if you have a way to consistently reproduce, then please post that so that we can investigate more.

Solution that is working for me in VS 2019 (Version 16.4.3) is to Unload the project and then reload the project. clean solution and recompile.

Thanx @AizazZaidee that worked :-)

Was this page helpful?
0 / 5 - 0 ratings