Closed aspnet-hello closed 6 years ago
From @CoskunSunali on Tuesday, May 23, 2017 2:49:31 PM
@Tratcher, Don't want to hijack the issue but are you aware of a place where one can read why and when to use StringSegments
and what makes it more efficient than a variable of type string
?
The page at https://docs.microsoft.com/en-us/aspnet/core/api/microsoft.extensions.primitives.stringsegment defines it as An optimized representation of a substring.
but that is a very generic definition and does not really mean much - at least to me.
From @davidfowl on Tuesday, May 23, 2017 2:52:37 PM
@Tratcher, Don't want to hijack the issue but are you aware of a place where one can read why and when to use StringSegments and what makes it more efficient than a variable of type string?
It doesn't allocate a heap object. It's just a struct that wraps a string, an offset and length.
From @MaximRouiller on Wednesday, May 24, 2017 5:23:09 AM
@davidfowl But... where's the list of methods, properties, expected exceptions, use cases, samples in VB.NET? :wink:
/trolling
From @hughzzq on Tuesday, July 4, 2017 11:39:44 PM
This seems to bring a breaking change. I have a project based on .net core 1.0 and I use new MediaTypeHeaderValue("xxx"). But I found it will throw MissingMethodException if I create a .net core 2.0 web application and refer my project(with package). Does any body know how to fix it? Exception information: MissingMethodException: Method not found: 'Void Microsoft.Net.Http.Headers.MediaTypeHeaderValue..ctor(System.String)'
Thanks
From @davidfowl on Tuesday, July 4, 2017 11:56:08 PM
@hughzzq Did you update everything to 2.0? Do you have 3rd party dependencies that depend on 1.0 packages?
From @hughzzq on Wednesday, July 5, 2017 1:53:20 AM
@davidfowl
Did you update everything to 2.0? No, the project with MediaTypeHeaderValue(string) is our standard library. I can't update it to 2.0. But the application is 2.0 with only microsoft.aspnetcore.all package.
Do you have 3rd party dependencies that depend on 1.0 packages? No. I wrote a simple test project created with core 1.0 MVC Application templates and only with one new code 'new Microsoft.Net.Http.Headers.MediaTypeHeaderValue("application/json");'. I can still got this issue.
From @davidfowl on Wednesday, July 5, 2017 7:47:15 AM
No, the project with MediaTypeHeaderValue(string) is our standard library. I can't update it to 2.0. But the application is 2.0 with only microsoft.aspnetcore.all package.
Then you're broken because this is a breaking change. You need to update the older library to compile against 2.0 in order to use it in a 2.0 application. This method was removed.
From @NCC1701M on Thursday, August 17, 2017 4:53:36 AM
@Tratcher Great, now .netstandard1.1 libs which are using MediaTypeHeaderValue can't be integrated in .netcore2.0 apps! Why don't you overload the methods to work with strings as well and internally convert this to StringSegment?
From @beginnerg on Sunday, September 24, 2017 4:59:31 AM
I'm not sure, but I think there is a problem with .NET Core regarding this change. I get a portability problem, if i use the .Net Portability Analyzer
T:Microsoft.Net.Http.Headers.MediaTypeHeaderValue | M:Microsoft.Net.Http.Headers.MediaTypeHeaderValue.#ctor(Microsoft.Extensions.Primitives.StringSegment) .NET Core is not supported.
MediaTypeHeaderValue is used Microsoft.AspNetCore.Mvc.Formatters.OutputFormatter
I'm using this .NET Core class for my own Outputformatter public class MyOutputFormatter : OutputFormatter { public MyOutputFormatter() { SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/xyz")); } ..... }
From @Tratcher on Sunday, September 24, 2017 8:22:18 AM
These types all use netstandard and are working in our Core apps. Have you had any difficulties in an app?
From @beginnerg on Monday, September 25, 2017 1:06:21 AM
I have no problems on windows, but maybe later if i switch to linux. I'm only a little bit confused, why a not supported .Net Core Code is used in a official .Net Core Library.
From @Tratcher on Monday, September 25, 2017 4:52:04 AM
Because the Portability Analyzer is wrong. It's only an assistant, it's not always correct.
From @dracan on Saturday, November 4, 2017 6:54:38 AM
Great, now .netstandard1.1 libs which are using MediaTypeHeaderValue can't be integrated in .netcore2.0 apps! Why don't you overload the methods to work with strings as well and internally convert this to StringSegment?
THIS! Seriously, why break existing .netstandard 1.x libraries?! As @NCC1701M said, why not just add an overload instead? Developers don't necessarily have control over dependencies. We can't re-write all 3rd party libraries for them to support 2.0! Yet another roadblock in my attempt to upgrade to .NET 2.0 😞
We periodically close 'discussion' issues that have not been updated in a long period of time.
We apologize if this causes any inconvenience. We ask that if you are still encountering an issue, please log a new issue with updated information and we will investigate.
From @Tratcher on Tuesday, May 23, 2017 2:34:06 PM
Microsoft.Net.Http.Headers contains a set of HTTP header parsers. To improve their efficiency these APIs have been changed to utilize
StringSegments
rather thanstrings
in their internal operations and public APIs.E.g. MediaTypeHeaderValue MediaType, Type, and SubType have all been changed from
string
toStringSegment
. In the processStringSegment
has added many new helper methods to make it easier to work with. When you do require an actualstring
you can get it by calling.Value
or.ToString()
to get the underlying substring.https://github.com/aspnet/HttpAbstractions/commit/2ce2d8b6c5c4d3111f5bbfe642c478f229bd955f https://github.com/aspnet/Common/commit/6881708c56cd09d580e0f4639ef744697cbb5679 https://github.com/aspnet/Common/commit/7c7031f145413221be316719683edb0bf1b9bf40
Copied from original issue: aspnet/HttpAbstractions#847