-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Blazor developers get warnings when they call APIs that aren't available on WebAssembly #42335
Comments
Tagging subscribers to this area: @safern, @ViktorHofer |
@safern @ViktorHofer -- I am going to assign this to someone on my team. Going to assign to myself for the moment. |
@mdh1418 @steveisok Question for you...
Is the correct answer here the following?
That would mean for all assemblies that have at least partial browser support, that we want to see warnings if we call APIs unsupported on browser without also annotating those call sites. |
Makes sense to me. Seems like the easiest way. |
That does seem like the way to go. |
Why enable it for browser only? There are annotations for other configuration as well and all configurations would benefit from additional checks of not using unsupported APIs (e.g. Linux calling Windows only API or Android calling macOS API) |
For <Project>
<ItemGroup>
<!-- Platforms supported by this SDK for analyzer warnings. Spec: https://github.com/dotnet/designs/blob/master/accepted/2020/platform-exclusion/platform-exclusion.md -->
<SupportedPlatform Include="Android" />
<SupportedPlatform Include="iOS" />
<SupportedPlatform Include="Linux" />
<SupportedPlatform Include="macOS" />
<SupportedPlatform Include="Windows" />
</ItemGroup>
</Project> Or If the project is targeting the |
@mdh1418 @steveisok -- @buyaa-n and I were discussing this and we think we can actually apply this attribute even more liberally. For projects that have With that, @buyaa-n is intending to take an approach where |
Checked the For the 1st task, I have added the <ItemGroup Condition="('$(TargetsBrowser)' == 'true' or '$(TargetOS)' == '') and '$(IsTestProject)' != 'true'">
<SupportedPlatform Include="browser"/>
</ItemGroup> And found 97 warnings found in System.Net.HttpListener, System.Security.Cryptography.Algorithms and System.Net.Http projects. With a quick review looks most of them referencing APIs having assembly-level The 3rd task says |
Will this be accurate? Some of this might have <ItemGroup Condition="('$(TargetsBrowser)' == 'true' or '$(TargetOS)' == '' and '$(GeneratePlatformNotSupportedAssemblyMessage )' == '') and '$(IsTestProject)' != 'true'">
<SupportedPlatform Include="browser"/>
</ItemGroup> |
Not sure if that is needed, for now i don't see any invalid warning caused by that. And I see some project generating that conditionally <GeneratePlatformNotSupportedAssemblyMessage Condition="'$(TargetsBrowser)' == 'true'">SR.SystemSecurityCryptographyAlgorithms_PlatformNotSupported</GeneratePlatformNotSupportedAssemblyMessage>
<ApiExclusionListPath Condition="'$(TargetsBrowser)' == 'true'">ExcludeApiList.PNSE.Browser.txt</ApiExclusionListPath> but still has some browser supported functionality TargetsBrowser <ItemGroup Condition=" '$(TargetsBrowser)' == 'true'">
<Compile Include="$(CommonPath)Internal\Cryptography\HashProvider.cs"
Link="Internal\Cryptography\HashProvider.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.GetRandomBytes.cs"
Link="Common\Interop\Unix\System.Native\Interop.GetRandomBytes.cs" />
<Compile Include="$(CommonPath)Interop\Unix\Interop.Libraries.cs"
Link="Common\Interop\Unix\Interop.Libraries.cs" />
<Compile Include="Internal\Cryptography\HashAlgorithmNames.cs" />
<Compile Include="Internal\Cryptography\HashProviderDispenser.Browser.cs" />
<Compile Include="Internal\Cryptography\HMACCommon.cs" />
<Compile Include="Internal\Cryptography\RandomNumberGeneratorImplementation.cs" />
<Compile Include="Internal\Cryptography\RandomNumberGeneratorImplementation.Browser.cs" />
<Compile Include="Internal\Cryptography\SHAHashProvider.Browser.cs" />
<Compile Include="System\Security\Cryptography\RandomNumberGenerator.cs" />
<Compile Include="System\Security\Cryptography\IncrementalHash.cs" />
<Compile Include="System\Security\Cryptography\SHA1.cs" />
<Compile Include="System\Security\Cryptography\SHA1Managed.cs" />
<Compile Include="System\Security\Cryptography\SHA256.cs" />
<Compile Include="System\Security\Cryptography\SHA256Managed.cs" />
<Compile Include="System\Security\Cryptography\SHA384.cs" />
<Compile Include="System\Security\Cryptography\SHA384Managed.cs" />
<Compile Include="System\Security\Cryptography\SHA512.cs" />
<Compile Include="System\Security\Cryptography\SHA512Managed.cs" />
</ItemGroup> |
Ah that is because of the ApiExclusionList. We could check for that as well. If the exclusion list is set then we do have some supported APIs |
Yes but, i meant is checking |
Would that be covered because any place we have If that's true, then I don't think there's any benefit to checking that property in the condition since all call sites in the assembly are already covered by |
I haven't checked all, but for the ones i checked it had My point is even it has |
For #41087, we annotated many APIs with
[UnsupportedOSPlatform("browser")]
, which will allow the Platform Compatibility Analyzer to provide customers with warnings when calling APIs that are unsupported on browser from call sites intended to work on browser. This is working for customer scenarios, but thedotnet/runtime
repo itself isn't currently producing warnings for the scenario.Since support for browser is not implied, the analyzer requires an MSBuild item for
<SupportedPlatform Include="browser" />
to be supplied in order for browser-related warnings to be produced. With #41760, we enabled the analyzer in the master branch, but a quick test during the review of that PR revealed that even with this MSBuild item specified, the errors were still not getting produced within the libraries projects.We need to:
<SupportedPlatform Include="browser" />
specified, and annotate them as such, indicating that the library is intended to be supported on browser/cc @mdh1418 @steveisok
The text was updated successfully, but these errors were encountered: