← Back
IAmTimCorey November 30, 2026 35m

Breaking Changes in .NET 11

Read full transcript 32 segments
  1. The upgrade to .11 is really easy. But as with every upgrade, you need to watch out for the breaking changes. While the .NET team is really good about not disrupting existing code, they do fix bugs. sometimes people start to rely on those bugs working the way they did. So let's look at five bugs the .NET team has fixed that might change how your code works today. Now if you don't know me, my name is Tim Corey and it's my goal to help you be the best developer you can be. Instead of faking it or pretending that prompting an AI makes you good developer, I will teach you how to be a confident, prepared developer. Ready to survive and thrive in today's marketplace. This channel has over a thousand videos dedicated to just that. But if you're looking for even more, go to devforge.com. There you'll find even more free and paid resources to help you wherever you're at on your development journey. So let's dive right in here to a console project that I have. And right now it's .NET 11. We're going to change this. I don't know if you know that you can do this, but we're going to create two versions here. A .NET 10.0 and .NET 11. You have to change from target framework to target framework.

  2. Make it plural. Um but that now allows me when I go to build, I can change, let's save this. I can change um how, let's reload project. There we go. I can change the framework that I am running under. That way I can choose to say, hey, how did this work in .NET 10 and then how is it work in .NET 11. This allows me to do a good demo for you of both versions. Now a little bit more setup work. I want to um let's add an app settings. So app settings .json and we're going to add one more and that's going to be um let's call this shared settings .json. Okay? And we'll use these in upcoming demo. Uh, the other thing we're going to do again, just to get prepared for this, we're going to right-click on Dependencies, Manage NuGet Packages, and we're going to browse for the Microsoft.Extensions.Hosting.

  3. And this is going to Wait for it. That's not the right one. Um, so Microsoft.Extensions.Hosting and we're going to choose the um I think we just have a problem because they have two different versions um set up. So here's what we're going to do. I'm going to take the actual package um and let's go over to our project here and insert it manually. Um, so we're going to say item group. And we're going to say in here I don't know if you noticed, you can do this manually. That's fine. Uh, package reference. We're going to say include. We're going to include the Microsoft.Extensions dot hosting. And the version here is important. So we're going to start off with .NET 10 and so we're going to say version is 10.0.14. That's a pretty good version for this package uh for .NET 10. But we have to remember to change this as well we changed the .NET 11. We want the .NET 11 package of this hosting because the fact that that has some of the changes, the fixes in it for .NET 11. Now you wouldn't normally have to do this because normally you'd be in let's say a uh you know a API or something like that. When you upgrade, one of the things it's going to ask you to do is you should upgrade your packages as well. Um, we're going to do it manually.

  4. Okay. So I think that's enough to get us started. What I'm going to do is get rid of the console write line. I am going to bring in um one record. Let's put it down here at the bottom. Remember it since we're in program.cs that any type of records or classes or methods you have to put at the bottom because this is all one method and these are technically local records that we're creating. So public record, supplier uh price record. And we're going to say string SKU and double unit price and double shipping cost and string effective date. And yes, I know it's a string. It's not a uh a date. And that's important because we're going to we're going to test out how conversions for dates work now. And what I'm going to do is I'm going to bring in um I'm going to actually copy some code rather than making you watch me type it.

  5. This is going to bring in what's called a supplier feed and this is just some data. So some data off of that record and we're going to take a JSON serializer. We're going to deserialize it into the the record that we have here and make sure that the price now contains our filled out record from this data. Okay. So let's start with um the issue the first issue which is conversion from double to decimal. Remember all these are fixes to how .NET work. They it didn't work right before, but now it does. It just might not feel right, okay? So let's start with uh decimal. We're going to say stored unit price. This is the price we expect. 1.23 um that's the decimal price we're expecting. Now we're going to do is say decimal unit price equals convert to decimal price . unit price. Why? Because price .

  6. unit price is a double. So we're going to convert that to decimal. Now what do you expect this to be? Remember up here it's 1.23 so we expect it to be 1.23. Essentially what we're going to do is basically a a unit test of our own, right? We're not going to actually make a unit test do the work. We're going just be testing the the expected value versus the actual value. Okay. So now let's do a console writeline and say string interpolation unit price is unit price. And then we're going to do and is we're going to say um let's do the matching the console writeline and say uh stored price. And say um stored price. Actually, let's do string interpolation first. And say in here we're going to do uh stored unit price. Okay? So that just compares the two. And we'll put a console writeline empty one at end.

  7. Let's just run this. So I had build errors. Um ah of course. I had to put an equal sign there in order to put that value in there. I got too busy talking. Okay. So stored price and unit price stored price and unit price are the same. Okay? So the price that was in the storage was 1.23. The price that we see in the actual value the unit price is 1.23. Everything looks good. Now let's change this to .NET 11. Now I don't need to change that NuGet package yet. I'm not using it yet. So leave it as is. Let's run this. And we see that there is now a differentiation. The stored price the price that we're expecting is 1.23. Instead we get 1.2299999 etc. Right? Why? Well, the reason why is become because conversions are now precise.

  8. See when we store this price then what we're when we store it a double even though it says 1.23 as a double really what's happening is it's it's not quite 1.23 because of how binary works. I have a whole video on that if you want to look at my video on double versus decimal. Um it's not actually stored as 1.23. It's stored as the binary equivalent with some rounding in there. And so we have some extra bits at the end. And so when we store that, it's not quite 1.23. When we convert it here to a decimal, well decimals are much more precise. So therefore it's it's taking that precision and saying, hey, um instead of taking what you see as the value 1.23, I'm going to take the actual value of the double. The actual value of the double is not 1.23. It's 1.22999 etc.

  9. So therefore the unit price will not be 1.23 in decimal because that would be not as precise as it needs to be. And that was the the first kind of uh conversion issue. Now is this going to affect your code? I hope not because I hope that you're not converting doubles to decimals and expecting the same exact value. But if you are, this could have quote unquote worked in the past because it's a bug. But the reality is now that they've fixed the bug, your code might not work because your code may have depended on that bug. Now let's go on to issue number two. So let's just, you know, put above here. Uh let's put it right here. By the way, you can have this code. Just want to put put some code comments in here. You can have this code. There's a link down in the description to download it. So issue one and this is going to be conversions are now precise.

  10. Okay? So that's, you know, the the fix was it made the conversions precise because they weren't before, but that might cause some some issues in your code. Okay. So next up, I'm just going to put it here, issue two rounding is now precise. Okay, let's see what that mean by that. So double shipping equals math.round price.shipping cost. Remember that's a double uh to two places and midpoint rounding uh away from zero. Okay, so this is going to round the shipping costs, which are remember the shipping cost up here is 2.675. It's going to round it to the the uh precise value. Okay, which means we're going to get something a little funky. So let's do console.writeline and say string interpolation and say shipping and we're just going to put shipping.

  11. Now I'm going to expound on this a little bit more in just a minute, but let's put our console.writeline at the end and run this again. This is going to be first.net 10. So .net 10 tells us 2.68, which is what we expect. Why? Because it was 2.675. Well, we're rounding to two places. Therefore, the five rounds up to the next whole value, so 68 instead of 675. That's kind of what we expect, right? Well, let's break that because we're going to run this again and it rounds to 2.67. You might say that's broken. That's not how rounding works because that number 2.675 well five rounds up to eight. You know, five rounds up, four rounds down, right? So we know this. Therefore, it should be 2.68, but it's not in .net 11. You might say it's broken. Here's why it's not broken.

  12. Let's actually put the real value. [snorts] So because it was and I'm going to put price. shipping. Oops. Uh price. dot shipping cost to string. And uh, round we're going to print out what it actually is for our price. Again, remember that when we print out doubles, what it does is it prints out what we're expecting, right? It prints out the the shortened version, but that's really involving a little bit of rounding. So let's see what the actual precision of shipping cost, not the rounded version. This is shipping right here is a rounded version. We're going to take the actual shipping cost, not rounded, and print out the actual value. So if we do that, we can see that in it was 2.674. Wait, I thought it was five. Yeah, it's actually 4.999998223 etc. This is the actual value being stored in memory for our double. So when you round this number, what do you get?

  13. You get 2.67 because four rounds down. So this is the precise value for our rounded double, 2.67. I know working with doubles is tricky because doubles appear to be easier than they are because of how binary is used. Again, whole video on double versus decimal. But what this is going to mean is it going to mean that you are going to see rounding that might not work the way you expected to. Rarely, it's not all the time. It's not every time you see a number it's going to round incorrectly, but because of how binary works, you're going to see sometimes where you get the rounding what feels like wrong. And it's not wrong, it's just how double works. And if you say, well, but I wanted to work that way because I wanted to be 2.675, that's where you're talking about using a decimal instead of a double, which is more expensive, but it is more precise.

  14. So just note that that's why that's happening. Issue number two, rounding is now precise. It just might not feel that way. So, this is one of those things where it feels one way, but it's not actually that way. So, that's why we need to make sure that we're careful when we run these things, that we are looking at it as what is actually happening and understanding what's going on behind the scenes, not just assuming we know that 2.675 is definitely 2.675. It's not really. Okay. Number three. So, I just got to put it here. Issue three. Only allowed styles or exception for date time. Okay. Or actually, let's put date. Okay. So, what we're going to do is we have this effective date here, right? And the effective Let's just unpin this. The effective date for our value is 26 12 1 which would be December 1st 2026.

  15. So what would How we actually convert this? So, if date only We're just going to do date, not date and time. There's no time. So, date only try parse exact. We're going to say price dot effective date. Okay? And we're going to say the format is four years, two months, two for day. And then we're going to say the culture info is going to be invariant culture. And then the uh date time styles operation it does in a if statement, but um that's okay.

  16. The date time styles .assume universal. Now that's where we're going to get burned here. So let's just take that off and do a a control dot here. Um, but this is where we're going to get burned because date time styles, we're saying assume universal for time. Well, the problem is is that we're date only, okay? But we used to be able to do this. We're going to say out date only effective date. Okay, very long if statement. Um, but down here we're going to put our curly braces and then what we'll do is we'll say um console right line. We're going to say string interpolation effective and we're going to say uh effective date and we'll say four years, two months, two days in that format.

  17. Okay, but if not, then we're going to say else. We'll say console right line effective date is invalid. Um, let's call it effective date is invalid. Okay, and we'll put our console right line at the end. Okay, so we're trying to parse the effective date, which is again 12 or 2026 12 01 which fits this format, which fits this format. Everything looks good except as I kind of pointed out here, date time style assume universal. Um that's not really going to work with .NET um it as far as a conversion process. So let's let's see what happens in .NET 10 first. We get a build error. Um, that's because I didn't spell invariant right. That's not the problem. Um, let's this again in .NET 10 and effective date is invalid.

  18. Okay. So so because this assume universal, it couldn't figure it out because it just it doesn't work with date only, it goes it's not it's not valid. Therefore, try parse exact returns a false and we get an effective date is invalid, which seems right, except for the fact that no, it's not because that's that's a correct date. So it says the effective date is invalid, but it's not invalid. It's right date. And this may have been something that you banged your head against the wall saying, why is this not working? Well, let's change this to .NET 11 and we'll run this again. And we get exception this time that says, hey, the only allowed value for the styles are allow whitespace, allow trailing white, allow leading white, and allow inner white. Okay? So it's saying, hey, the styles you got you didn't pick one that's right. Okay? So let's come back here and do control J and allow the inner white.

  19. Okay? Now it's a valid style. Now the effective date is correct. And if you went back to .NET 10, it would still be correct because we have chosen let's make sure that yeah, I did. Um, we've chosen a valid datetime style, but when you choose an invalid datetime style, that used to be that it would just say, hey, that date wasn't valid, but that's not correct. The correct thing is the date is valid, but the style you chose is not possible. So therefore, it's your code that's the problem. It's not the date that's the problem. So you may have been seeing invalid dates when they were valid because you chose the wrong thing here for style. So they cleaned that up and said, no, no, no, let's not, let's not blame the date for your problem. So we're going to throw an exception instead. Now I am going to comment out this code because um if we want to keep running this demo, um actually let's just comment out all these out. That way we're only run the the latest uh one.

  20. Okay, this is where we're going to let's get we're back in .NET 10. Um we're going to uh get to the point where we need to change that NuGet package. So normally in Web API or Blazer or MVC or Razor Pages, you have a host application builder already, but in console we don't. So so you can't do things like dependency injection or logging or um things of that nature, but we can if we just bring it in. So host application builder and notice the top here we're going to get the using Microsoft extensions that hosting that's that um NuGet package you brought in. So this package right here uh that we're currently on 10.0.14 of, that's the one we're going to be changing. Uh but that's what we're using to do the host application builder. This works with console applications. So if you want to get dependency injection console apps, this is how you do it.

  21. So builder equals host.create application builder and passing your args from the command line. That's all you have to do to have your your application builder um set up. But what we're going to do is we're going to add a new configuration file. Now this may not be something you do all the time, but I wanted to point it out. So if you didn't right now we have in this application builder, we have all the the different environments for app settings and app settings.development.json or app settings.production.json and user secrets and environmental variables or environment variables and the command line args. We have all that stuff already built in. So you already have those and those work in .NET 10, .NET 11 the same exact way. However, if you were to say I configuration shared settings equals new configuration builder and you're going to say .addjson file and say shared settings .json and then you're going to say .built.

  22. Okay? So what we're doing is we're adding a new shared json . file which we have here. By the way, we should also select both of these and go to properties and make sure that the the copy output is if newer. Okay, that's going to make sure that we're copying both of those. But we're now bringing that shared json set or shared settings . json in and overriding app settings and other things. Okay. So finally you have to say builder .configuration .add configuration shared settings. So that just adds the shared settings to our existing configuration. Now what I'm going to do is I'm going to go into my app settings and I'm just going to copy and paste from my notes because it's probably a little quicker. So in app settings I'm going to add an SMTP stack where I say host is smtp.devforce.com and the port is 25. You know, something you might have in your settings.

  23. And let's go over to shared settings and I'm going to paste the exact same thing except I'm going to wipe out the values. I'm going to put a empty value for host. Now what happens to that value when we try to read it? Again, let me copy from my notes because it's easier than me typing out asking for all this information, but we're going to say, hey, the host, so build . configure builder . configuration, which is right here, uh, SMTP host and the port is the port, okay? So it's going to pull from our settings file. Now, we have in our app settings the host and the port, but in our, uh, let's pin this for now, uh, in our shared settings we don't have a host, we have it empty, but it is empty. So there's a value there, it's just an empty string. What does the value for host show? Well, we're in .NET 10, let's just verify that. Yep, .NET 10. So I'll run this and we see the value is smtp . devforces . com.

  24. Why? Well, this is a bug because if you would put this in, if you put an empty string in, uh, user secrets, but then put the the value in appsettings . json, user secrets would override app settings and then put an empty string. But when you do this method of adding on a new JSON file using this this chained configuration, when you do a chained configuration it didn't work the same way. Instead, it read the the shared settings and went, oh, that's that's an empty string, therefore it's not a value, instead of saying is it null? So the new change, and let's go over to our NuGet package, changes to 11 . 0, this is important, and then we're going to change our framework to 11, let's just save this and clean our solution just to be sure we cleaned out anything that shouldn't be there. We hit run.

  25. Now we get a value of empty string. So in .NET 11 we get an empty string, we're in .NET 10 we would the value from appsettings.json. So, why is this? Well, they changed how they read this value right here. It used to be that uh you know string dot um is null or whitespace and ignore it, whereas now it's just is it null, meaning does it not exist? Because if it doesn't exist, then we're going to bring in that smtp.devforce.com. But if it exists, even if it's an empty string, that empty string represents a value. The value is empty string. Therefore, the value will be empty string. So, that's the fix they put in place, which yeah, that's going to throw you for a loop if that's not what you were expecting.

  26. So, just note that this is a this is something that's been fixed. Um it is a valid fix. It works now the same way that app settings does versus user secrets or appsettings.developer.json. Those all work this way. It's just chained configurations didn't. Okay, so this is issue four shared settings um or let's say call it change settings. Okay. So, shared uh or change settings now work like standard settings. Okay. So, let's comment that out. We'll leave the the builder in place because we're going to do one last one and that's down here. We're going to say issue five and this is the uh background jobs report.

  27. Okay. So, what we're going to do is we're going to create a a background job. And again, to do this uh quickly, what I'm going to do is I'm going to, you know, build it very quickly, uh nightly import. And I will actually just paste in my code. It's very simple. The code's a background service, and we're going to execute async. And we're going to do a two-second delay, and then we're going to throw an exception. That exception is the worker failed. Okay. So what this represents is a failing background service. What happens when a background service fails? So this has changed from .NET 10 to .NET 11. Now let's first go back into our project and go back to version uh 10.14 so you can see how this worked. And then we'll also change this to the .NET 10. We'll save all of that. I'll do a a clean on this to make sure I have no files sitting around that are going to bork it up. And then back here in our notes, again, I'm going to copy and paste some code just to make life a little easier for us. And that is we're adding to the services, which is our dependency injection. We're adding our nightly import background job.

  28. We're building the host. And then in a try catch, we're doing run async and saying, hey, the host successfully ran, which it shouldn't. Um and then the host failed um if it failed, if it throws an exception. And then we're going to have the import host finished. Now I do want to point out that in the console, you'll see an exception either way [snorts] because in the background, you'll see the exception, but it won't bubble up to the front. So let's see what happens in .NET 10. So again, we have .NET 10. Let's run this application. It's waiting for two seconds, and we have that exception. You know, exception there, failure there. Um but then we have down here, read that line. Host completed successfully. So as you can see above, no, it didn't. We have an exception. There's a problem, but when it returned back to the parent, the one that kicked it off was, hey, I worked. I did my thing.

  29. Which isn't right. It didn't. It returned back a zero meaning I was successful in running the background job even though the background job had an exception. And if you didn't catch these exceptions in your background jobs and if you weren't looking, your background jobs appear as though they are successful because these exceptions never went up any higher than the background job itself. They failed in the background job and the background job returned back saying, hey, I'm done, which I'm going to call success, which isn't right. So, let's change this by again going to our project and changing our our package back to 11.0 and we'll change our framework to 11. We'll save all that and again, no code changes, just changing to .NET 11. Well, plus the package. And now, two seconds later, we'll get that exception, but notice down here, host failed, worker failed. So, now we get a message saying, hey, there was a problem in the background job. So, that that exception is going to bubble up all the way to the caller and say, hey, I had a problem, you might want to check that out because I was not successful. I did not complete successfully. There was an issue.

  30. So, again, this is now a fix in how things work in .NET to fix a broken thing to make it not broken. Now, obviously your code is broken now, but it's supposed to be, right? If your job is failing, you should know that your job failed. However, again, you may have depended on that zero status saying things work successfully to say, hey, our job completed or something else and then you just checked your logs for exceptions. Now you're going to have an exception one level higher in your caller saying, hey, there was a problem. So you might have code that suddenly breaks or has an unhandled exception if you did not handle your exception properly in your program.cs or wherever you kicked off this job. So kind of the the the point here is if you're kicking off background jobs, wrap them in a try catch and make sure you handle that exception now because if you didn't handle that exception, it worked just fine in .NET 10. In .NET 11 it will crash your application because it throws that exception at the parent level.

  31. Okay? So those are the five issues. So we have the conversions are now or yeah, conversions now precise. So from double to decimal is now a precise conversion. Rounding [snorts] is now precise or converting on the actual double value, not the the, you know, pretty up value it's showing us on the front end. The date only parsing, if it doesn't have the right style, it's going to throw an exception now instead of saying, hey, it was an invalid date. It's going to be on you, not on the date. Number four, chained configuration settings now act like regular configuration settings in how they override each other when it comes to empty values. And then finally the background jobs will properly fail if they actually failed. So .NET 11 is incredibly stable, incredibly powerful, and it's fixing a lot of bugs that were well, not a lot, five bugs that were in .NET 10 that your application could be depending on those bugs working the way the the bug worked.

  32. And well, that's not good. Now you can actually fix these things and have a better result for your application. You just need to know that these are bugs and they have been fixed now and you need to make sure that now your application is properly working and handling those bugs appropriately, okay? Thanks for watching and as always, I am Tim Corey. >> [music]

No summary available yet.

View original episode ↗