|
This is NOT a programming question. Just something you might want to be aware of.
So I migrated my project and fixed that various things in Startup that broke. Stupid things, like apparent env.IsDevelopment() doesn't exist anymore, and IHostingEnvironment has to be changed to IWebHostEnvironment or something like that, and app.UseMvc(); is wrong now and you have to use:
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
instead, and I don't have Razor pages anyways.
And I do wish that the whole NuGet package manager / Visual Studio would figure out that when I change the target framework, yes, please go and get the appropriate packages for the new framework, and now I need to specifically install the System.Data.SqlClient framework? And we're no longer using Microsoft.AspNetCore.App but instead need Microsoft.EntityFrameworkCore and Microsoft.EntityFrameworkCore.SqlServer?
Sigh. Fine, relatively easy fixes, and all that was an aside, relatively easy to fix, but annoying.
So, once I got it to compile, fired it up and tried a very simple API call that returns an access token.
Now, in .NET Core 2.2, the response at the client contains the key "access_token"
In .NET Core 3.1, the response at the client contains the key "token"
As in:
JSON.parse(xhr.response).access_token;
has to be changed to:
JSON.parse(xhr.response).token;
WTF?
On the C# side, the return from the API call is the same:
ActionResult<IAccessToken>(resp.token)
where IAccessToken is quite literally just:
public interface IAccessToken
{
string Token { get; set; }
}
Now here's where it gets interesting. resp is actually a tuple: (IAccessToken token, HttpStatusCode status)
and I'm returning the token part of the tuple resp.token (checking the status is not necessary because if the status isn't "OK", then the token is null so the full line is actually:
ret = resp.token.Token == null ? Unauthorized() : new ActionResult<IAccessToken>(resp.token); but that's irrelevant to this discussion.
The point being, .NET Core 2.2 serializes the container IAccessToken differently than .NET Core 3.1.
Good grief. I would not have expected that kind of a breaking change. Why the heck is 2.2 prepending "access_" to the key? And what else breaks in the serialization of objects with 3.1?
And (shame on me) why didn't I notice that weird "access_token" issue to being with? I even wrote up the example response in the documentation with that!
There's a lesson here somewhere. Don't trust .NET Core. Don't trust open source projects. And notice stupid things, because if I had, I could have at least forced it to return what I expected.
And here's another fun one. This code:
client = context.Client.SingleOrDefault(acct => acct.Token == token && (!acct.IsDeleted || allowDeletedAccounts));
Given:
[NotMapped]
public bool IsDeleted { get { return (Deleted ?? 0) != 0; } }
(yes, we have a Deleted flag as a nullable integer in our tables) - this code works fine in .NET Core 2.2.
But noooo, EF can't figure out what to do with it in .NET Core 3.1. So instead:
client = context.Client.SingleOrDefault(acct => acct.Token == token && (((acct.Deleted ?? 0) == 0) || allowDeletedAccounts));
And that breaking change isn't discovered until runtime! (Like the serialization issue when the client tries to parse out the token.)
So how many places in the code base break at runtime and you won't know until you've executed all the possible code path queries?
Now, while I had tried .NET Core 3.1 because there were posts about multi-part content being broken in .NET 2.2 and it was fixed in .NET Core 3.0, it turns out that that wasn't the reason my file uploads weren't working.
But that's a whole other story. Involving pretty much 8 hours of try this, google that, and getting so pissed off (which is rare for me) that I really wanted to just go on a rampage. Because, at the end of the day, it's quite simple, but nobody actually tells you the important things you need to make sure you do correctly. That will become an article, so that somewhere in the cloud there will be a concise example explaining why and not just glossing over the critical, key, pertinent, essential, vital niggly little things you need to do to post FormData up to a .NET Core application. Grrr.
|
|
|
|
|
Marc Clifton wrote: Don't trust .NET Core. Don't trust open source projects.
Don't trust
FTFY
Real programmers use butterflies
|
|
|
|
|
Sounds like they did it on purpose because they couldn't support the old api going from 2.x to 3.x. Force you to update your code if you update your libs.
The one I remember (between "libs") was in one case you can use a single char for a string split separator, while the other version will (still) insist on an array. You think it's neat and change your code, then find your lib is no longer compatible with your other libs. I also ran into problems thinking all libs should serialize / compress the same ... not. They may actually read and write but the file sizes will be off.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
Most of the serialization issues are from them switching from Newtonsoft to System.Text.Json. Beware if you have your own custom converters or attributes to change the serialized property names!
|
|
|
|
|
I can't see how any version of Entity Framework would be able to translate a query using your computed property to a SQL query. It's quite likely that EF Core 2.x was loading the entire table into memory and evaluating the condition as a LINQ-to-objects query instead. One of the breaking changes in 3.x is that it won't do that any more.
Old behavior
Before 3.0, when EF Core couldn't convert an expression that was part of a query to either SQL or a parameter, it automatically evaluated the expression on the client. By default, client evaluation of potentially expensive expressions only triggered a warning.
New behavior
Starting with 3.0, EF Core only allows expressions in the top-level projection (the last Select() call in the query) to be evaluated on the client. When expressions in any other part of the query can't be converted to either SQL or a parameter, an exception is thrown.
There are a couple of ways around this. You could make the property a computed column[^]:
modelBuilder.Entity<Client>()
.Property(acct => acct.IsDeleted)
.HasComputedColumnSql("CAST(IsNull(Deleted, 0) As bit)"); Or use you use a value converter[^] on the property:
modelBuilder.Entity<Client>()
.Property(acct => acct.IsDeleted)
.HasColumnName("Deleted")
.HasConversion(new BoolToZeroOneConverter<int>()); in which case, you'd want to remove the Deleted property, and possibly make IsDeleted writable.
Either option should allow your original query to be evaluated in the database, instead of in memory.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Okay, so I have a set of "packed ranges" which are start and end position pairs stored as adjacent ints in an int array.
For example
var ranges=new int[] { 'A','Z','a','z','_','_' };
would indicate the ranges A-Z, a-z, and the single character _ (range _-_)
Here's the thing. I need them in order. I don't care if they overlap.
So all i do is I sort the array as a flat array of ints.
This *shouldn't* screw with any of my ranges I think?
Can anyone think of a case that will break this? remember i don't care if ranges overlap.
I just need to make sure that after i sort, the same ranges are in the array.
I broke it. LOL answered my own question
Real programmers use butterflies
|
|
|
|
|
Where do I put in a bug report?
The "Hide" and Copy code" links continue to work, even though they've been struck out.
I wanna be a eunuchs developer! Pass me a bread knife!
|
|
|
|
|
I noticed that too. You say bug, I say feature. I wonder if it copies the code struck out?
Real programmers use butterflies
|
|
|
|
|
What I have noticed is that the code runs much faster if I set the font in my IDE to DokChampa Regular, but you've really got to avoid handwriting fonts. Some people swear by Comic Sans, but a remarkable percentage of people swear at it.
If you want to look like a real hero, at work, compile the code in something like Algerian, so it runs really slowly, then recompile it in DokChampa just before a customer demo, and pretend to have fixed loads of other people's bugs.
I wanna be a eunuchs developer! Pass me a bread knife!
|
|
|
|
|
It's not really a bug, since "strikethrough" is a text feature rather than a functional one to my mind. But ... Bugs and Suggestions[^] is where you report such things.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Hand in your Monty Python air-displacement card immediately!
I wanna be a eunuchs developer! Pass me a bread knife!
|
|
|
|
|
Is this the five minute argument or the full half hour?
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Ni!
I wanna be a eunuchs developer! Pass me a bread knife!
|
|
|
|
|
Hail Caesar. If it's not done by sunrise, I'll cut your balls off.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
And that's what the Romans did for me
I wanna be a eunuchs developer! Pass me a bread knife!
|
|
|
|
|
Splitter!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
You're a very naughty boy!
I wanna be a eunuchs developer! Pass me a bread knife!
|
|
|
|
|
You try and tell the young people today that... and they won't believe ya!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
*BONG!*
That's not Monty Python; it was At Last, the 1948 Show. AIRI, it was written by Tim Brooke-Taylor.
I wanna be a eunuchs developer! Pass me a bread knife!
|
|
|
|
|
Mark_Wallace wrote: AIRI, it was written by Tim Brooke-Taylor.
And John Cleese & Graham Chapman (along with Marty Feldman) - which is why it also got dragged into the MP Canon: Four Yorkshiremen sketch - Wikipedia[^]
The MP version is probably better known.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
You didn't explain how you broke it. Was it something to do with overlapping ranges?
Eg: ['A', 'E', 'C', 'G'] would become 'A'–'C' and 'E'–'G' after sorting, whereas you probably wanted 'A'–'G' instead.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
it never got that far. was a bug in parsing ranges
Real programmers use butterflies
|
|
|
|
|
So I met a road side accident like a week ago and since then been ignoring the obvious signs of injury and trying to continue with my daily life. Now that I couldn't get myself to walk properly, I had no other choice but to visit the doctor. Apart from various muscle ruptures, turns out I have broken toe fingers.
I've been strictly suggested to rest since I've already made my injuries worse by ignoring them. But that's the thing, I had an upcoming squash tournament to play by the end of this month which I won't be able to play now and that's making me real sad.
Why, Why, Why
|
|
|
|
|
Because life's a bitch.
But ... even if you had gone to the quack straight away, you still wouldn't be fixed by the end of next month, let alone this!
Accidents always happen at the least convenient time, that's Einstein's third law of relatives.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
OriginalGriff wrote: Because life's a bitch.
Can't agree more
OriginalGriff wrote: that's Einstein's third law of relatives.
I read it Einstein's third law of relativity and questioned my high school Physics knowledge for a good 5 minutes
|
|
|
|
|