Commit Graph
466 Commits
Author SHA1 Message Date
Stephen Toub 0c4ee9e749 Use u8 in more places (#69995)
* Use u8 in more places

Primarily replacing Encoding.UTF8/ASCII.GetBytes("literal") with "literal"u8.ToArray()

* Address PR feedback (and fix some vars)
2022-06-07 13:42:23 -04:00
Eric Erhardt de27aa1584 Add Stream ReadAtLeast and ReadExactly (#69272)
* Add Stream ReadAtLeast and ReadExactly

Adds methods to Stream to read at least a minimum amount of bytes, or a full buffer, of data from the stream.
ReadAtLeast allows for the caller to specify whether an exception should be thrown or not on the end of the stream.

Make use of the new methods where appropriate in net7.0.

Fix #16598

* Add ReadAtLeast and ReadExactly unit tests

* Add XML docs to the new APIs

* Preserve behavior in StreamReader.FillBuffer when passed 0.

* Handle ReadExactly with an empty buffer, and ReadAtLeast with minimumBytes == 0.

Both of these cases are a no-op. No exception is thrown. A read won't be issued to the underlying stream. They won't block until data is available.
2022-05-20 09:20:06 -05:00
Levi Broderick 52fd1a576e Call simpler overloads of Substring and Slice (#68937) 2022-05-10 23:23:22 -07:00
Adeel Mujahid 4141913109 Fix typos (#69011) 2022-05-07 11:55:53 -07:00
Viktor Hofer 24cabc6eb0 Update solution files to include missing deps (#68668) 2022-05-02 20:14:05 +02:00
Eric Erhardt 5f7f7e8a5d Remove unnecessary throwOnPrematureClosure in ManagedWebSocket. (#68745)
* Remove unnecessary throwOnPrematureClosure in ManagedWebSocket.

This parameter is always true, so it can be removed and simplify the code.
2022-05-01 19:53:43 -05:00
Viktor HoferandJeremy Barton ba055bd94e Minimize the build graph by deleting unnecessary references (#68603)
* Minimize the build graph by deleting references

Minimizing projects' dependency graph. There are tons of unnecessary
Reference and ProjectReference items which aren't required anymore as
the referenced projects became full facade assemblies. Removing those
from a leaf's graph makes the graph smaller and therefore the project's
evaluation and build faster.

* Update src/libraries/System.Net.Quic/ref/System.Net.Quic.csproj

Co-authored-by: Jeremy Barton <[email protected]>

* Update Versions.props

Co-authored-by: Jeremy Barton <[email protected]>
2022-04-28 15:04:26 +02:00
Eric Erhardt 18be907176 Change Nullable to default to enable in libraries src and ref projects (#68102)
* Change the default Nullable to enabled for src projects

* Set Nullable=enable as the default for ref projects

* Fixup merge conflicts

* Disable nullable on shim projects and EventLog.Messages

* Set Nullable to blank on EventLog.Messages

This way no CodeAnalysis attributes are emitted into the assembly.
2022-04-25 11:15:37 -05:00
Stephen Toub 215b39abf9 Remove usage of !! from dotnet/runtime (#68178)
* Remove usage of !! from dotnet/runtime

- Use ArgumentNullException.ThrowIfNull instead where possible.  It's only usable for projects that only target .NET 6+, and it can't be used in places like this(...) or base(...).
- In other cases, if the project already has a ThrowHelper, augment it for null as needed and use that.
- For most of the extensions projects, add a ThrowHelper.ThrowIfNull that replicates ArgumentNullException.ThrowIfNull.
- For everything else, just use "throw new".

* Address PR feedback

* Address PR feedback

* Remove false positives from searches

* Address PR feedback
2022-04-21 13:25:52 -04:00
Marek Safar 6a889d2342 Enable CA1822 (Mark members as static) analyzer (#66333) 2022-03-25 12:06:33 +01:00
Eric Erhardt 7508080ebc Update coding-style to include target-typed new() guideline (#67061)
* Update coding-style to include target-typed new guideline

Similar to `var` usage, `new()` usage is only allowed when the Type can be understood from the same line.

Fix #53369

* Fix coding style violations
2022-03-23 18:54:51 -06:00
JK Park a6f52bc558 Fix typo in comment (#66497)
thta => that
2022-03-11 06:18:20 -05:00
Elinor Fung a0635832f1 Rename DllImportGenerator project to LibraryImportGenerator (#66029) 2022-03-03 22:17:23 -08:00
Viktor Hofer 7671b5084a Use TargetFramework singular for tests
Use TargetFramework instead of TargetFrameworks property whenever a
test project targets a single target framework only.
This avoid unnecessary outer builds and evaluations and makes the build
faster.
2022-02-24 12:32:04 +01:00
Viktor Hofer febaf76743 Fix slngen.proj and update solution files (#65711)
* Fix slngen.proj

The SolutionName property is defined by the SDK and hence the condition was always true. Also the star (*) didn't expand when using the ValurOrDefault msbuild function. Fixing this by using a different name `SolutionNameOverride` and avoiding the ValueOrDefault msbuild function.

* Update solution files

Updating the solution files as those changed because of
microsoft/slngen@cb57e28 and apparently the solution files never were
updated.
2022-02-22 17:18:54 +01:00
WraithandVlad Brezae ddb22ef2ac Remove S.R.CS.Unsafe and Intrinsify Unsafe (#64861)
* private assemblies moved from Internal to System Runtime.CompilerServices

* reformat existing unsafe vm intrinsics

* implement Copy, CopyBlock, CopyBlockUnaligned, InitBlock, InitBlockUnaligned, Unbox, Add, Subtract, SubtractByteOffset

* remove System.Runtime.CompilerServices.Unsafe il project and replace with forward only cs project

* change all ilproj references to csproj

* remove nativeaot Unsafe

* add conditional package reference for S.R.CS.Unsafe on netcoreapp 6.0

* regenerate solutions

* mono interp

* [mono][interp] Implement Copy and Unbox intrinsics

* [mono][jit] Implement Copy and Unbox intrinsics

Co-authored-by: Vlad Brezae <[email protected]>
2022-02-19 21:50:14 -08:00
Viktor Hofer 20e8f905d0 Don't use Targets* helper properties in libs (#64500)
* Don't use Targets* helper properties in libs projs

This change makes it possible to migrate 200+ (ref+src) projects to use
TargetFramework instead of TargetFrameworks which avoids the additional
outer build evaluation and invocation which ultimately makes the overall
build faster.

Targets* properties (i.e. TargetsWindows, TargetsAnyOS, TargetsUnix,
etc.) rely on the TargetFramework property which usually are set
inside a project. The TargetFramework property is only
available before a project specifies it if it's explicitly set in a props
file or if the project is cross-targeting and the outer-build dispatches
into the inner-build. During the dispatch, the TargetFramework property
is passed in as a global property.

Until now that behavior wasn't a problem because every libraries project
cross-targeted (by setting the TargetFrameworks property) even though
many only include a single TargetFramework (i.e. NetCoreAppCurrent).

To allow projects to use the TargetFramework property instead of
TargetFrameworks, the Targets* helper properties can't be calculated
anymore early in a props file as the TargetFramework property isn't set
at that time.

In general, the guidance by the SDK/msbuild team is to not read from the
TargetFramework property before the project sets it
(in a property group). That effectively means that the TargetFramework
property shouldn't be used in props files at all.

Therefore these helper properties can't be used anymore for property
conditions and I'm replacing their usage with TargetPlatformIdentifier
comparisons for both properties and items.
In nearly all cases, the Targets* helper properties can be replaced with
TargetPlatformIdentifier checks on items and in the few cases where
TargetsUnix or TargetsLinux marks multiple tfms as compatible, the exact
tfms must be used instead for the TargetPlatformIdentifier comparison.

Whenever a project needs to condition properties on the platform, I'm
first setting the TargetPlatformIdentifier the same way the SDK sets it
so that the SDK later doesn't need to set it again to avoid the
additional expensive msbuild function call.

* Use TargetFramework singular to avoid outer builds

Use TargetFramework instead of TargetFrameworks property whenever a
projects only targets a single target framework. This avoid unnecessary
outer builds and evaluations and makes the build faster.
2022-02-12 13:07:16 +01:00
Stephen Toub 3ae87395f6 Initial roll out of !! (#64720)
* Bump version of C# compiler

This should be reverted when arcade brings in a new enough compiler.

* Fix a few new warnings from updating compiler

* Enable IDE0190 to employ parameter null checking

* Initial roll out of !!

* Fix more compiler warnings from upgrade, plus some test fixes / reverts

* Fix a few more tests

* Disable profiling test
2022-02-08 16:06:59 -05:00
Viktor Hofer daf77fc9a5 Add NetCoreAppCurrent rid agnostic tfm to libs (#64518)
* Add NetCoreAppCurrent rid agnostic tfm to libs

This change adds a NetCoreAppCurrent rid-less configuration which throws
a PNSE to the following libraries:
- System.Console
- System.IO.Compression.ZipFile
- System.IO.Compression
- System.IO.FileSystem.DriveInfo
- System.IO.MemoryMappedFiles
- System.Net.Http
- System.Net.Mail
- System.Net.NameResolution
- System.Net.Primitives
- System.Net.Requests
- System.Net.WebSockets

System.Private.Runtime.InteropServices.JavaScript is excluded from that
list as it doesn't have a contract and hence can't generate a PNSE
assembly. Also it's currently a private assembly.

These are the only libraries that were missing a RID agnostic tfm.

Adding rid-less configurations, even if they just throw PNSEs helps with:
- Platform enablement, i.e. a new "base" platforms like "Browser" usually
  require libraries that are RID specific to support them. By offering a
  RID agnostic PNSE tfm, projects can gradually support new platforms.
- Making it possible to have ProjectReferences between libraries, i.e.
  imagine an microsoft.build.notargets / microsoft.build.traversal
  project with a `$(NetCoreAppCurrent)-$(TargetOS)` tfm which P2Ps all
  source projects. NuGet can't know that a $(NetCoreAppCurrent)-Linux
  tfm can reference a project with a $(NetCoreAppCurrent)-Unix tfm and
  will throw during restore, more precisely during the compatibility
  check. Ideally NuGet or the SDK would support targeting platforms from
  the runtime.json RID graph, including its compatiblity matrix but
  that isn't the case today.

Even though the added tfms add to the build, I have other changes
in the pipeline which depend on this one which will make the build
noticeably faster.

* Use default impl for DriveInfo & ZipFile
2022-02-01 07:49:42 +01:00
Ivan Zlatanov 2cbde409e0 Fixing a possible null reference error in WebSocket deflate. (#62428)
Fixes #62422
2021-12-13 13:41:42 +01:00
Adam Sitnik 72e0da83a7 fix the build (#62575) 2021-12-09 09:50:51 -05:00
Julien Couvreur ab0de531c8 Escape lower-cased type names (#62507) 2021-12-09 00:05:25 -08:00
Jeremy Barton 899bf97046 Merge System.Security.Cryptography.Algorithms to System.Security.Cryptography 2021-11-17 12:00:31 -08:00
Elinor Fung 3806e15595 Use GeneratedDllImport for blittable p/invokes in System.IO.Compression, System.IO.Compression.Brotli, System.Net.Http, System.Net.NameResolution (#61638) 2021-11-16 14:01:42 -07:00
Viktor Hofer 36b6247cc7 Update solution files for correct ordering of elements (#58655)
With the newest udpate of slngen, the order of elements (configuration, folders, etc.) is in sync with how Visual Studio arranges them.
Also the order is now deterministic.

Based on that, updating all solution files to have the correct ordering of elements. This change also unblocks adding CI protection for
making sure that solution files are up-to-date in regards to their dependencies as slngen is now generating the files deterministically.
2021-09-04 00:16:15 +02:00
Natalia Kondratyeva 69de57bcf2 Throw on invalid payload length in WebSockets (#57598)
Port of https://github.com/dotnet/runtime/commit/9eb56805a13851c756d70a4cff4bd71fa89736f4

**Description:**
Avoid integer overflow to prevent infinite loop in reading from WebSocket. (also complies better with WebSocket RFC)
MSRC 65273 - Prevents DoS attack by sending frames with invalid payload length.

**Risk:** Low

**Impacted assemblies:** System.Net.WebSockets.dll
2021-08-18 10:01:59 +02:00
Stephen Toub 19b86fbaea Refactor ManagedWebSocket to avoid forcing Task allocations for ReceiveAsync (#56282)
* Refactor ManagedWebSocket to avoid forcing Task allocations for ReceiveAsync

The ManagedWebSocket implementation today supports CloseAsyncs being issued concurrently with ReceiveAsyncs, even though CloseAsync needs to issue receives (this allowance was carried over from the .NET Framework implementation).  Currently the implementation does that by storing the last ReceiveAsync task and awaiting it in CloseAsync if there is one, but that means multiple parties may try to await the same task multiple times (the original caller of ReceiveAsync and CloseAsync), which means we can't just use a ValueTask.  So today asynchronously completing ReceiveAsyncs always use AsTask to create a Task from the returned ValueTask.  This isn't actually an additional task allocation today, as the async ValueTask builder will create a Task for the asynchronously completing operation, and then AsTask will just return that (and when it completes synchronously, there's extra code to substitute a singleton).  But once we switch to using the new pooling builder, that's no longer the case.

This PR uses an async lock as part of the ReceiveAsync implementation, with the existing async method awaiting entering that lock.  CloseAsync is then rewritten to be in terms of calling ReceiveAsync in a loop.  This also lets us remove the existing Monitor used for synchronously coordinating state between these operations, as the async lock serves that purpose as well.  Rather than using a SemaphoreSlim, since we expect zero contention in the common case, we use a simple AsyncMutex that's optimized for the zero contention case, using a single interlocked to acquire and a single interlocked to release the lock.

* Fix misleading comment
2021-08-10 22:14:13 -04:00
Viktor Hofer a6b9a63f35 Update libraries solution and NuGet.config files (#56430)
* Update slngen and invocation

* Update NuGet.config files

* Update solution files with slngen
2021-07-28 18:44:17 +02:00
Stephen Toub 59a5610e8b Tighten up some ArrayPool.Return usage (#56229)
Avoid potential problems if Return were to throw an exception after having already put the array back into the pool.
2021-07-27 07:40:36 -04:00
Alexander Nikolaev 55198524db Annotate WebSockets.RegisterPrefixes with [Obsolete] (#55640)
Fixes #50530
2021-07-16 11:37:04 +02:00
Stephen Toub fa779e8cb2 Raise the max size poolable by ArrayPool (#55621)
We previously set an arbitrary cut-off of 2MB max array size. That was before we would trim arrays in response to memory pressure.  This now raises the limit as high as we can while maintaining the current power-of-two-based scheme.
2021-07-14 11:33:50 -04:00
Ulrich Weigand 3b8b527ef6 Big-endian fix: ApplyMask in System.Net.WebSockets.ManagedWebSocket (#55422)
* Fix mask shifting logic for big-endian systems
2021-07-09 20:00:20 -04:00
Pavel Savara 1e1951825b [wasm] Enable more networking tests (#53027)
- enable System.Net.Http.Functional.Tests on browser
- System.Net.Http.Functional.Tests to run in chrome instead of V8 via WasmTestOnBrowser
- ActiveIssue https://github.com/dotnet/runtime/issues/34690 for WebSocket on Windows Mono
- fix Quic detection in test
- disable webSocket tests on Mono/Windows
- disable tests with MaxConnectionsPerServer not supported on Browser
- disable tests with Socket not supported on Browser
- disable tests with AutomaticDecompression not supported on Browser
- disable tests with UseProxy not supported on Browser
- disable tests with PreAuthenticate not supported on Browser
- disable tests with Credentials is not supported on Browser
- disable tests with Loopback server
- run outerloop on browser, rather than V8 only
- [ActiveIssue] #37669 for missing crypto MD5
- conditional tests with PlatformDetection.IsBrowserDomSupportedOrNotBrowser to allow System.Net.Http.Functional.Tests pass on V8
- disabled tests with https://github.com/dotnet/runtime/issues/53018
- disabled tests with https://github.com/dotnet/runtime/issues/53591
- disabled tests with https://github.com/dotnet/runtime/issues/53592
2021-06-02 20:17:12 +02:00
Mitchell HwangandMitchell Hwang c6b5994fbc [libraries] Move library tests Feature Switches defaults to Functional tests (#53253)
* [libraries] Remove UseSystemResourceKeys true default

* [libraries] Remove UseSystemResourceKeys for iOS

* [libraries] Resolve WebSockets System resource keys activeissue

* [tests] Move default feature switches from libraries to functional tests

* [tests] Move Browser wasm default switches into FuntionalTests scope

* Add Browser OS condition

* Move DefaultFeatureSwitches initialization to FunctionalTests project

* Consolidate trimming framework library features and condition for libraries with EnableAggressiveTrimming

* [testing][EAT] Revert trimming framework library features to browser defaults for enable aggressive trimming

* [tests] Add Xamarin Android, Xamarin Mac/iOS, and Wasm feature defaults to Functional tests

* Fixup tabs to spaces

* Add common feature switches, links, and cleanup

* Cleanup Xamarin Android link

Co-authored-by: Mitchell Hwang <[email protected]>
2021-05-28 20:07:13 -04:00
Natalia Kondratyeva 87e65109cd Put failing WebSockets tests under ActiveIssue for Android (#52647)
As per https://github.com/dotnet/runtime/pull/52052#issuecomment-838655841, putting the failing tests under ActiveIssue.

Tracking issue: https://github.com/dotnet/runtime/issues/52645
2021-05-12 20:24:41 +02:00
Ivan Zlatanov 7ecb1eb17c Fixed a bug in websocket receive, when a compressed frame with no payload is received. (#52621)
Fixed a bug where compressed frame of size 0, would have been prematurely marked as processed.
Compressed frames should always go through inflation in order to make sure
there is no leftover from previous receives.
Created a test that verifies the correct handling of empty compressed frame.

Fixes #52551
2021-05-12 17:36:34 +02:00
Ivan Zlatanov d515841235 Fix for failing WebSocket deflate test on ARM (#52052)
Reducing the number of times Random.Next is called to improve runtime performance of test on ARM. 
Fixes #52031
2021-05-11 17:53:22 +02:00
Kareem ZedanandJan Kotas b08a97afb8 Task/use get last p invoke error (#52212)
* replacing GetLastWin32Error with GetLastPInvokeError in remaining assemblies

* replace GetLastWin32Error with GetLastPInvokeError in assemblies outside system.private.corelib

* Apply suggestions from code review

Co-authored-by: Jan Kotas <[email protected]>
2021-05-09 12:42:21 -07:00
Ivan Zlatanov 576be0dde8 Reduce the memory footprint of ManagedWebSocket (#52022)
Removed unused CancellationTokenSource. Using RandomNumberGenerator.Fill instead of custom instance of RandomNumberGenerator.
2021-05-05 00:10:20 +02:00
Dan Moseley 721384062e increase timeout for websocket compression tests (#52086)
* increase timeout for websocket compression tests
* disable for 14 and 15 on ARM
2021-04-30 10:12:25 +02:00
Ivan Zlatanov 2c3eb64bf4 WebSocket Compression (#49304)
Adds support for RFC 7692 "compression extensions for websocket".

Closes #31088
2021-04-28 19:35:52 +02:00
Alexander Köplinger bc9f00c226 Cleanup PlatformSpecific/SkipOnMono attributes that skip a platform (#50907)
We have a bunch of test assemblies that don't make sense on some platforms, e.g. Browser.
Right now we're skipping them via `[SkipOnMono("reason", TestPlatforms.Browser)]` but there's nothing that inherently ties this to Mono other than the current implementation.

The more generic `SkipOnPlatform` attribute can be used instead.
We can also use it in places where we do `[PlatformSpecific(~TestPlatforms....)]` to avoid the double inversion.
2021-04-09 13:20:18 +02:00
Buyaa Namnan 0ac80c3354 Remove unneeded UnsupportedOSPlatform('browser') attribute (#48795) 2021-02-25 21:48:15 -08:00
Natalia Kondratyeva f86a99949d Remove WebSocketProtocol assembly (#47578)
Removed WebSocketProtocol code and mentions of the assembly.
Moved ManagedWebSocket.cs from Common to System.Net.WebSockets.

Fixes #1493
2021-01-29 15:50:21 +01:00
Buyaa abc525d0c2 Handle unsupported browser warnings (#43363)
* Handle browser warnings

* Apply feedback, revert updates handled with different PRs

* Add misssing diagnotic id

* Address multitargeted warnings

* Apply feedback

* Small type/comment updates

* Apply more feedback

* Use project settings instead adding Directory.Build.props

* Annotate APIs injecting unsupported type through DI

* Fix window support related warnings found with generic type parameter

* Fix another browser warning found with generic type parameter bug fix

* All public APIs of ConsoleLoggerExtensions are unsupported, so marking entire type as unsupported on browser

* Try handle mono warnings

* Revert mono related changes, it was mistake

* Try handle browser warninga in mono

* Apply feedback and fix new warnings caused from corelib changes

* Review update

* Apply feedback

* Move platform specific section from HttpTelemetry

* Revering unwanted changes

* Remove redundant attributes

* Exclude cross platform build with browser target

* small updates

* Annotate entire type DiagnosticCounter unsupported

* Apply feedback, improve suppression comments

* Remove Unsupported browser from TypeDescriptor.CreateInstance, TypeDescriptionProvider.CreateInstance and related updates
2020-11-25 21:20:52 +00:00
Viktor Hofer ed295782bf Add workflow to update solution files with SlnGen and update them initially (#44703)
* Add slngen infra

* Update all solution files
2020-11-17 18:23:30 +01:00
Krzysztof Wicher 3ac170acc8 Ensure <Nullable>enable<Nullable> on System.IO.Packaging and S.Resources.Extensions (#41731)
Fix src ref diffs
2020-09-09 09:15:30 -07:00
Maxim Lipnin 6ab00b4821 [wasm] Re-enable some tests in the System.Net.WebSockets.Tests namespace (#40004)
There is no repro for https://github.com/dotnet/runtime/issues/38807 at the moment so the related tests have been enabled.
Two tests have been disabled due to PNSE (see https://github.com/dotnet/runtime/pull/39346).

Fixes: https://github.com/dotnet/runtime/issues/38807 

The test run result: `Tests run: 177, Errors: 0, Failures: 0, Skipped: 0.`
2020-07-29 11:10:35 +02:00
Viktor Hofer 809a06f451 Remove depprojs in favor of PackageReferences (#35606)
- Remove depprojs which currently binplace external references into the RefPath folders in favor of PackageReference and PackageDownload items.
- Build all configurations by default when building an individual project (either on the CLI or inside VS) same as with the official SDK. This enables .NETFramework Test Explorer support.
- Centrally define libraries that compose the shared framework instead of in each Directory.Build.props file to be able to build the targeting pack first and consume it in the OOB libraries.
- Use ProjectReferences to reference OOB projects. Compile against the reference assembly but use the implementation assembly app-local during runtime.
- Remove OOBs from the testhost and remove the testhost folder for .NETFramework as it isn't required anymore.
- Only binplace for $(NetCoreAppCurrent) to compose a) the targeting pack, b) the runtime pack, c) the testhost, d) a full closure for the shims.
- Use Targeting Packs for OOB projects (with their implicit assembly references) but still explicitly define granular references for .NETCoreApp configurations (DisableImplicitAssemblyReferences switch). Use the implicit targeting pack references in some Microsoft.Extensions.* cases.
- Remove placeholder configurations as they aren't needed anymore with explicit P2Ps vs Targeting Pack references.
- Remove implicit assembly references (ie for .NETFramework, mscorlib)
- Remove AssemblySearchPath hacks that were introduced with b7c4cb7 as the targeting pack is now used by default.
- Reduce unnecessary .NETFramework configurations that were added to run tests in favor of the already existing ref&src configurations.
- Stop hardcoding the paths for wasm assemblies and use the returned TargetPath of the ProjectReferences.
- Addressed formatting (ItemGroups, References at the bottom of the project file, ordering of references, use LibrariesProjectRoot instead of a relative path, unnecessary AssemblyName and RootNamespace properties which are identical to the project name, ordering of tfms)
- Revert "fix clean (#33758)"
2020-07-23 17:20:26 +02:00
Stephen Toub 6072e4d3a7 Update license headers (#38793) 2020-07-08 09:23:11 -04:00