Skip to content

Move NetCore project to use .NET SDK #380

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

Merged
merged 19 commits into from
Jan 28, 2023

Conversation

dougbu
Copy link
Contributor

@dougbu dougbu commented Jan 22, 2023

Move NetCore project to use .NET SDK

  • Formatting.NetCore now targets netstandard1.3
    • was Profile259 aka portable-net45+wp80+win8+wpa81, approximately netstandard1.0
    • but Newtonsoft.Json.Bson supports netstandard1.3 and up
  • use Newtonsoft.Json.Bson in NetCore projects
  • can now multi-target NetCore.Test as well
  • nits:
    • align src/ Formatting projects as much as possible
    • align test/ Formatting projects as much as possible
    • clean up the Microsoft.TestCommon project slightly
  • note: NetCore project names make no sense but I'm leaving them alone for this PR

React to using Newtonsoft.Json.Bson everywhere

  • remove deprecated BsonWriter mentions entirely
  • remove legacy BSON writer test workaround

Remove unnecessary ConcurrentDictionary class

  • was not available in Profile259
  • leave tests to confirm correct operation w/ "real" class

Remove UriQueryUtility because WebUtility is available everywhere

  • leave test to confirm WebUtility continues to behave about the same
    • handle WebUtility being a public class
  • change other tests to handle WebUtility.UrlEncode(...) encoding to uppercase
    • unlike UriQueryUtility.UrlEncode(...)

Add simple classes to NetCore project

  • use ICloneable copy to get more classes compiling
    • helps NetCore in similar way to existing MediaTypeHeaderValueExtensions
  • use InvalidEnumArgumentException copy to simplify code and testing
  • both not available in netstandard1.3 (or available packages) but easily duplicated

Remove unnecessary NetCore-specific GlobalSuppressions.cs file

Use NameValueCollection everywhere

  • available (but not serializable) in netstandard1.3

Add MaxDepth support in NetCore assembly

  • remove an unnecessary suppression about MaxDepth in BaseJsonMediaTypeFormatter

Add UseDataContractJsonSerializer support in NetCore assembly

Copy TranscodingStream and related files from dotnet/runtime

  • my runtime clone was at 88868b7a781f4e5b9037b8721f30440207a7aa42

Adjust TranscodingStream and related code to compile and run here

  • add conditions to avoid references to version-specific API
  • remove references to internal dotnet/runtime code
    • rewrite some code more generically if performance impact likely minor
  • use Microsoft.TestCommon instead of directly relying on Xunit in tests
  • use C# 9.0

Use TranscodingStream in JSON and XML formatters

  • remove ReadOnlyStreamWithEncodingPreamble and its tests
  • now support a much broader set of encodings in JSON and XML formatters
    • not just UTF8, UTF16BE, and UTF16LE
    • JSON formatter already supported every encoding when UseDataContractJsonSerializer was false
      • no longer have this downside when property is true
      • however, quotas remain unsupported in netstandard1.3 version of this formatter when property is true
    • XML formatter requirement for an XML declaration in non-UTF8 content was general and is no longer an issue

Add MediaTypeMappings support in NetCore assembly

Add IRequiredMemberSelector support in NetCore assembly

Remove unnecessary NETFX_CORE workarounds

  • use DefaultContractResolver, GuidAttribute, TypeDescriptor, XmlElement, XmlNode classes
  • use IRequiredMemberSelector interface
  • use RequestMessage.CreateResponse() extension method
    • all available in netstandard1.3
  • JsonContractResolver use is something of a late Newtonsoft.Json version reaction
    • was held back by missing IRequiredMemberSelector

Work around missing features in netstandard1.3

  • get classes now included in NetCore assembly compiling
  • SerializationAttribute is not available
    • therefore Exception is not serializable
    • therefore DefaultContractResolver.IgnoreSerializableAttribute is not available
  • Stream.(Begin|End)(Read|Write) and Stream.Close() are not available
  • nit: clean up MultipartFormDataStreamProvider whitespace

Ensure a couple more assemblies are available

  • don't seem to be copied into test folder in CI builds

@dougbu
Copy link
Contributor Author

dougbu commented Jan 22, 2023

This PR is pretty big and complicated. I recommend going through the commits individually and concentrating on areas you're at least slightly familiar with.

@phenning, I included you because I'm removing some comments you added. Note we already have a netstandard2.0 assembly w/ none of the restrictions of the former Profile259 assembly.

@stephentoub and @GrabYourPitchforks, you're likely most interested in the first two of the three commits mentioning TranscodingStream, especially the middle one.

@dougbu
Copy link
Contributor Author

dougbu commented Jan 22, 2023

To help track which commits have been thoroughly checked, please tick those you are signing off on:

  • Move NetCore project to use .NET SDK
  • React to using Newtonsoft.Json.Bson everywhere
  • Remove unnecessary ConcurrentDictionary class
  • Remove UriQueryUtility because WebUtility is available everywhere
  • Add simple classes to NetCore project
  • Remove unnecessary NetCore-specific GlobalSuppressions.cs file
  • Use NameValueCollection everywhere
  • Add MaxDepth support in NetCore assembly
  • Add UseDataContractJsonSerializer support in NetCore assembly
  • Copy TranscodingStream and related files from dotnet/runtime
  • Adjust TranscodingStream and related code to compile and run here
  • Use TranscodingStream in JSON and XML formatters
  • Add MediaTypeMappings support in NetCore assembly
  • Add IRequiredMemberSelector support in NetCore assembly
  • Remove unnecessary NETFX_CORE workarounds
  • Work around missing features in netstandard1.3
  • Ensure a couple more assemblies are available (fixup for "Adjust TranscodingStream ..." commit)
  • !fixup! Remove added AggressiveInlining requests
  • !fixup! Improve XmlReader comments

@dougbu dougbu force-pushed the dougbu/Newtonsoft.Json.part6 branch from 77a9a81 to 327f780 Compare January 22, 2023 05:51
@dougbu
Copy link
Contributor Author

dougbu commented Jan 24, 2023

/ping reviewers

Copy link
Contributor

@wtgodbe wtgodbe left a comment

Choose a reason for hiding this comment

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

Approving for the subset of commits I checked off, largely based off of the changes seeming reasonable/consistent, and the CI passing

dougbu added 16 commits January 24, 2023 17:05
- Formatting.NetCore now targets `netstandard1.3`
  - was `Profile259` aka `portable-net45+wp80+win8+wpa81`, approximately `netstandard1.0`
  - but Newtonsoft.Json.Bson supports `netstandard1.3` and up
- use Newtonsoft.Json.Bson in NetCore projects
- can now multi-target NetCore.Test as well

nits:
- align src/ Formatting projects as much as possible
- align test/ Formatting projects as much as possible
- clean up the Microsoft.TestCommon project slightly

Notes:
- NetCore project names make no sense but I'm leaving them alone for this PR
- Formatting.NetCore does not build at this point due to `netstandard1.3` / `Profile259` differences
- remove deprecated `BsonWriter` mentions entirely
- remove legacy BSON writer test workaround
- was not available in `Profile259`
- leave tests to confirm correct operation w/ "real" class
- leave test to confirm `WebUtility` continues to behave about the same
  - handle `WebUtility` being a `public` class
- change other tests to handle `WebUtility.UrlEncode(...)` encoding to uppercase
  - unlike `UriQueryUtility.UrlEncode(...)`
- use `ICloneable` copy to get more classes compiling
  - helps NetCore in similar way to existing `MediaTypeHeaderValueExtensions`
- use `InvalidEnumArgumentException` copy to simplify code and testing
- both not available in `netstandard1.3` (or available packages) but easily duplicated
- available (but not serializable) in `netstandard1.3`
- remove an unnecessary suppression about `MaxDepth` in `BaseJsonMediaTypeFormatter`
- `XsdDataContractExporter` remains unavailable
  - update XML DCS tests to handle this (previously not in NetCore assembly)
- try various workarounds
  - `ReadOnlyStreamWithEncodingPreamble` causes tests to hit dotnet/runtime#80160
  - restriction to UTF8 when writing is a significant issue
- my runtime clone was at 88868b7a781f4e5b9037b8721f30440207a7aa42
- add conditions to avoid references to version-specific API
- remove references to internal dotnet/runtime code
  - rewrite some code more generically if performance impact likely minor
- use Microsoft.TestCommon instead of directly relying on Xunit in tests
- use C# 9.0
- remove `ReadOnlyStreamWithEncodingPreamble` and its tests
  - was insufficient in general and doesn't work correctly in `netstandard1.3`
  - see dotnet/runtime#80160

Now support a much broader set of encodings in JSON and XML formatters
- not just UTF8, UTF16BE, and UTF16LE
- JSON formatter already supported every encoding when `UseDataContractJsonSerializer` was `false`
  - no longer have this downside when property is `true`
  - however, quotas remain unsupported in `netstandard1.3` version of this formatter when property is `true`
- XML formatter requirement for an XML declaration in non-UTF8 content was general and is no longer an issue
- use `DefaultContractResolver`, `GuidAttribute`, `TypeDescriptor`, `XmlElement`, `XmlNode` classes
- use `IRequiredMemberSelector` interface
- use `RequestMessage.CreateResponse()` extension method
  - all available in `netstandard1.3`
- `JsonContractResolver` use is something of a late Newtonsoft.Json version reaction
  - was held back by missing `IRequiredMemberSelector`
- get classes now included in NetCore assembly compiling
- `SerializationAttribute` is not available
  - therefore `Exception` is not serializable
  - therefore `DefaultContractResolver.IgnoreSerializableAttribute` is not available
- `Stream.(Begin|End)(Read|Write)` and `Stream.Close()` are not available

nit: clean up `MultipartFormDataStreamProvider` whitespace
- don't seem to be copied into test folder in CI builds
- new `[MethodImpl(...)]` attributes have downsides
- also don't match `[StackTraceHidden]` semantics
@dougbu dougbu force-pushed the dougbu/Newtonsoft.Json.part6 branch from 327f780 to 8d057eb Compare January 27, 2023 05:03
@dougbu
Copy link
Contributor Author

dougbu commented Jan 27, 2023

Rebased and addressed @stephentoub's comments.

@stephentoub any other thoughts❔ If none, please check the non-NameValueCollection commits off in the earlier checklist that aren't checked yet. They're all TranscodingStream related but I understand if parts aren't of interest to you. We could find someone to double-check the project files for example (if you prefer).

Other reviewers: Please look at the NameValueCollection commit.

@stephentoub
Copy link

please check the non-NameValueCollection commits off in the earlier checklist that aren't checked yet. They're all TranscodingStream related but I understand if parts aren't of interest to you. We could find someone to double-check the project files for example (if you prefer).

I don't have rights to click those checkmarks. I only reviewed the "Adjust TranscodingStream and related code to compile and run here" commit and it looked fine other than my feedback you addressed.

@dougbu
Copy link
Contributor Author

dougbu commented Jan 27, 2023

I don't have rights to click those checkmarks.

That's a bit odd but thanks for letting me know where you'd focused. Much appreciated.

@dougbu
Copy link
Contributor Author

dougbu commented Jan 27, 2023

To other reviewers: I also ticked the checkboxes for "Copy TranscodingStream …" because that was just a literal cp from my dotnet/runtime clone and "!fixup! Remove added AggressiveInlining requests" because that was in response to @stephentoub's comments. This leaves us w/ 3 unreviewed commits.

Copy link
Contributor

@wtgodbe wtgodbe left a comment

Choose a reason for hiding this comment

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

Approving again for the last few commits I just looked at

Copy link
Member

@Tratcher Tratcher left a comment

Choose a reason for hiding this comment

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

These TFM changes are breaking. Will this be a new major version?

I didn't review the tests.

- mention `XmlDictionaryReader` instead
@dougbu
Copy link
Contributor Author

dougbu commented Jan 28, 2023

@Tratcher I addressed your comment on the "Use TranscodingStream …" commit in the latest "!fixup!" commit. Would you say you're signing off on those two commits❔

Still one open question on versioning and public API surface to you @Tratcher

@Tratcher
Copy link
Member

I've reviewed everything but the tests. :shipit:

@dougbu dougbu merged commit 2ed73bc into aspnet:main Jan 28, 2023
@dougbu dougbu deleted the dougbu/Newtonsoft.Json.part6 branch January 28, 2023 21:39
@dougbu dougbu added this to the 3.3.0 (5.3.0) milestone Feb 26, 2023
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.

4 participants