Settings Results in 4 milliseconds

OpenSSL Error generate Certificates "Error checkin ...
Category: Linux

Question OpenSSL error Error checking extension section default405703A1CE7F0000error11 ...


Views: 0 Likes: 29
Asp.Net Core 3.1 Entity Framework Core DateTime fi ...
Category: .Net 7

 Question How do you resolve the datetime that results to 1/1/0001 ...


Views: 233 Likes: 74
MySQL Backup and Restore Commands for DBA
Category: SQL

<span style="font-weight bold; font-size large; textline underli ...


Views: 354 Likes: 102
Entity framework "InvalidCastException: Unable to ...
Category: .Net 7

Question I have spend so much time on this error but I don't see where the issu ...


Views: 171 Likes: 69
 C# 9 Deep Dive: Target Typing and Covariant Returns
C# 9 Deep Dive Target Typing and Covariant Retur ...

We’ve been quite busy, my friends. In this C# 9 deep dive series, we’ve looked at init-only features, records, pattern matching, and then top-level programs. To complete this series (before showing off everything in a single app), we’ll discuss the last two items featured in the Build 2020 announcement target typing and covariant returns. These are not related, but I’ve decided to bundle these in a single blog post.This is the fifth post in a six-post series on C# 9 features in-depthPost 1 - Init-only featuresPost 2 - RecordsPost 3 - Pattern matchingPost 4 - Top-level programsPost 5 (this post) - Target typing and covariant returnsPost 6 - Putting it all together with a scavenger huntThis post covers the following topics.Improved target typingTarget-typed new expressionsTarget typing with conditional operatorsCovariant returnsWrapping upImproved target typingC# 9 includes improved support for target typing. What is target typing, you say? It’s what C# uses, normally in expressions, for getting a type from its context. A common example would be the use of the var keyword. The type can be inferred from its context, without you needing to explicitly declare it.The improved target typing in C# 9 comes in two flavors new expressions and target-typing ?? and ?.Target-typed new expressionsWith target-typed new expressions, you can leave out the type you instantiate. At first glance, this appears to only work with direct instantiation and not coupled with var or constructs like ternary statements.Let’s take a condensed Person class from previous postspublic class Person { private string _firstName; private string _lastName; public Person(string firstName, string lastName) { _firstName = firstName; _lastName = lastName; } } To instantiate a new Person, you can omit the type on the right-hand side of the equality statement.class Program { static void Main(string[] args) { Person person = new ("Tony", "Stark"); } } A big advantage to target-typed new expressions is when you are initializing new collections. If I wanted to create a list of multiple Person objects, I wouldn’t need to worry about including the type every time I create a new object.With the same Person class in place, you can change the Main function to do thisclass Program { static void Main(string[] args) { var personList = new List<Person> { new ("Tony", "Stark"), new ("Howard", "Stark"), new ("Clint", "Barton"), new ("Captain", "America") // ... }; } } Target typing with conditional operatorsSpeaking of ternary statements, we can now infer types by using the conditional operators. This works well with ??, the null-coalescing operator. The ?? operator returns the value of what’s on the left if it is not null. Otherwise, the right-hand side is evaluated and returned.So, imagine we have some objects that shared the same base class, like thispublic class Person { private string _firstName; private string _lastName; public Person(string firstName, string lastName) { _firstName = firstName; _lastName = lastName; } } public class Student Person { private string _favoriteSubject; public Student(string firstName, string lastName, string favoriteSubject) base(firstName, lastName) { _favoriteSubject = favoriteSubject; } } public class Superhero Person { private string _maxSpeed; public Superhero(string firstName, string lastName, string maxSpeed) base(firstName, lastName) { _maxSpeed = maxSpeed; } } While the code below does not get past the compiler in C# 8, it will in C# 9 because there’s a target (base) type that is convert-ablestatic void Main(string[] args) { Student student = new Student ("Dave", "Brock", "Programming"); Superhero hero = new Superhero ("Tony", "Stark", "10000"); Person anotherPerson = student ?? hero; } Covariant returnsIt has been a long time, coming—almost two decades of begging and pleading, actually. With C# 9, it looks like return type covariance is finally coming to the language. You can now say bye-bye to implementing some interface workarounds. OK, so just saying return type covariance makes me sound super smart, but what is it?With return type covariance, you can override a base class method (that has a less-specific type) with one that returns a more specific type.Before C# 9, you would have to return the same type in a situation like thispublic virtual Person GetPerson() { // this is the parent (or base) class return new Person(); } public override Person GetPerson() { // you can return the child class, but still return a Person return new Student(); } Now, you can return the more specific type in C# 9.public virtual Person GetPerson() { // this is the parent (or base) class return new Person(); } public override Student GetPerson() { // better! return new Student(); } Wrapping upIn this post, we discussed how C# 9 makes improvements with target types and covariant returns. We discussed target-typing new expressions and their benefits (especially when initializing collections). We also discussed target typing with conditional operators. Finally, we discussed the long-awaited return type covariance feature in C# 9.


Drupal 8 Page Not Found (Custom Module Page Life C ...
Category: Technology

Drupal 8 Page N ...


Views: 296 Likes: 80
InvalidOperationException: An error was generated ...
Category: Entity Framework

Question How do you solve for this error? "InvalidOperationException An error was generated fo ...


Views: 0 Likes: 30
How to use a Text File as a Template to Send Email ...
Category: .Net 7

AnswerOne way to accomplish this is by creating a text file and defining your template ...


Views: 385 Likes: 104
Introduction to Entity Framework Core
Introduction to Entity Framework Core

In this post I am going to look into Entity Framework Core, present the new features, the similarities and differences from EF6. ? hope that the people who will read this post are familiar with what EF is. In a nutshell EF is the official data access technology platform from Microsoft. It is a  mature platform since it is almost 9 years old. It is a new way of accessing and storing data, a set of .NET APIs for accessing data from any data store. Going into more details Entity Framework fits into a category of data access technologies called Object Relational Mappers or ORMs. ORMs reduce the friction between how data is structured in a relational database and how you define your classes. Without an ORM, we typically have to write a lot of code to transform database results into instances of the classes. An ORM allows us to express our queries using our classes, and then the ORM builds and executes the relevant SQL for us, as well as materializing objects from the data that came back from the database. ?y using an ORM we can really eliminate redundant data interaction tasks and we can really enhance developer productivity. Instead of writing the relevant SQL to target whatever relational database you’re working with, Entity Framework uses the LINQ syntax that’s part of the .NET framework. LINQ to Entities allows developers to use strongly-typed query language regardless of which database they’re targeting. When we use EF Core in your application, firstly you need to create your domain classes. These are pure .Net classes or objects and have nothing to do with EF Core.Then you use Entity Framework Core APIs to define a data model based on those domain classes. You also use Entity Framework APIs to write and execute LINQ to Entities Queries against those classes. When you need to save data back to the database you use SaveChanges methods. EF Core keeps track of the state of objects that it’s aware of, it’ll determine the SQL it needs to save data back to the database. Entity Framework will transform your LINQ to Entities Queries into SQL, execute that SQL, and then create objects from query results. As you many know, Entity Framework development was moved to CodePlex and became open source.  Entity Framework 6 has since then been moved to GitHub. The URL is github.com/aspnet/EntityFramework. You can download and experiment with the latest version, you can clone the repository, add your own fixes/features, and then submit those as pull requests to become part of Entity Framework Core. All pull requests that are submitted from the community are examined from the ADO.Net team before becoming part of EF Core. Another thing I wanted to mention is that different people call EF with different names. Let me be clear on that so that there is no confusion. EF Core was released in late June of 2016 and it was called Entity Framework 7, but in January 2016, its name was changed to Entity Framework Core. At the same time ASP.NET 5 was changed to ASP.NET Core. EF Core is not simply an update from EF6, it’s a different kind of Entity Framework, it is a complete rewrite. For developers who have invested time and effort on EF6 and have projects on EF6 should not worry as it will be actively supported. Entity Framework Core can run  on .NET Core. NET Core  can run on the CoreCLR and CoreCLR can run natively, not only in Windows, but also on Mac and Linux. EF Core can also run inside the full .NET Framework that is any version that is 4.5.1 or newer. Entity Framework Core is a brand new set of APIs and it doesn’t have all of the features that you might be used to with Entity Framework so it’s important to understand that before starting a  new project with Entity Framework Core. If you want to target cross platform or UWP apps then you have no other way but to use Entity Framework Core. For .NET apps that you want to run on Windows, you can still use Entity Framework 6. If you are building an ASP.NET Core applications that will run on Windows you can still use Entity Framework 6, so bear that in mind as well. There are Entity Framework features that will never be part of the Entity Framework Core, for example in EF Core there is no support for a designer-based model, there’s no EDMX and it isn’t supported by the Entity Framework Designer. Having said that in EF Core you can can still define a data model with classes and a DbContext. The DbContext API is still there and so is DbSets. You can also create and migrate to the database as your model changes, and you can still query with LINQ to Entities. Entity Framework continues to track changes to entities in memory. There are some new features in  EF Core that there were no available in earlier versions. In EF Core we have the ability to do batch inserts, updates, and deletes. We can specify unique foreign keys in entities and LINQ queries have become smarter and more efficient. In EF Core there is an In Memory provider that makes it really easy to build automated tests using Entity Framework without hitting the database. EF Core makes it really easy to use with inversion of control patterns and dependency injection. EF Core has the ability to populate backing fields not just properties. EF Core supports mapping to IEnumerables. Hope you have a better understanding of EF Core now. Hope it helps!!!  


System.IO.FileNotFoundException: Could not load fi ...
Category: .Net 7

Question How do you solve the error in IIS that saysCategory Microsoft.AspNetCore. ...


Views: 0 Likes: 43
Solved!! Visual Studio 2019 Shows a big Cursor and ...
Category: Technology

Problem When coding in Visual Studio, all of the sudden you see a big cursor and when you start ...


Views: 800 Likes: 98
Asp.Net MVC Development Notes
Category: .Net 7

<a href="https//www.freecodecamp.org/news/an-awesome-guide-on-how-to-build-restful-apis-w ...


Views: 752 Likes: 79
Let’s Give You More Control(s) – These Weeks in Firefox: Issue 132
Let’s Give You More Control(s) – These Weeks in Fi ...

Highlights Dao has enabled the URL bar result menu in Nightly! This gives you more control over the results that appear. You can remove hamster dance from your history, but not from your heart. The improved video controls for Picture-in-Picture have been enabled in Nightly We have introduced the playhead scrubber, timestamp, seek forward and backward buttons, and the fullscreen button. Please file bugs here if you find any! Thanks to Christian Sonne, it’s now easier to copy output from console.table into a spreadsheet The DevTools team has tweaked the console output to be more legible when the console is narrow Thanks to Gregory Pappas, who has given the browser.search WebExtension API a few enhancements to help Firefox be more compatible with Chrome WebExtensions that use that API! Friends of the Firefox team Resolved bugs (excluding employees) Volunteers that fixed more than one bug Gregory Pappas [gregp] Itiel New contributors (?? = first patch) Brian Pham fixed checkbox labels for the migration wizard ?? G Jeevika changed title-case strings to sentence-case on buttons portiawuu converted browser/actors/NetError* JSM modules to ESMs Project Updates Add-ons / Web Extensions WebExtensions Framework  As follow-ups related to the extensions button and panel Cleaning up code and css that is now unused on all channels (Bug 1801540, Bug 1799009) and fixed the extension icon size selected when the extensions action buttons are being pinned to the toolbar (Bug 1811128) and the positioning of the extension install doorhanger (Bug 1813275) as part of enhancements related to Origin Controls, starting from Firefox 111 the user will be able to allow manifest_version 3 extensions to get access to a website origin loaded in a tab for a single visit (Bug 1805523) Emilio fixed a small visual regressions related to the private browsing checkbox included in the post-install dialog (fixed in Firefox 111 and Firefox 110 by Bug 1812445, initially regressed in Firefox 108  by Bug 1790616) WebExtension APIs As part of the work for exposing WebExtensions API WebIDL bindings to the WebExtensions Background Service Worker Introduced WebIDL bindings for the “browser.dns”, “browser.proxy”, “browser.browserSettings” and “browser.browserSettings.colorManagement” API namespaces (Bug 1723838, Bug 1748313, Bug 1748293) Added a new section of the in-tree docs to provide a short description of the special setup related to the WebExtensions API WebIDL bindings, and in particular answers to common questions that DOM peers have asked as part of reviewing the WebIDL files generated from the WebExtensions API’s JSONSchema data (Bug 1813164) https//firefox-source-docs.mozilla.org/toolkit/components/extensions/webextensions/webidl_bindings.html#review-process-on-changes-to-webidl-definitions Developer Tools DevTools Kernp25 fixed an error that was happening on tab unloading (bug) Zacnomore improved the layout of the pseudoclass toggles in the inspector (bug) Thanks to Ian from the SpiderMonkey team who helped us fix a case where breaking on exception would pause at the wrong line in the debugger when faulty code was called inside a for..of loop (bug) Hubert added a title for debugger search results from dynamic sources (eval, new Function(), …) (bug) Hubert also added a performance test so we can track perceived performance of debugger search (bug) We added autocomplete in rule view for color level 4 formats (color, lab, lch, oklab, oklch) when layout.css.more_color_4.enabled is true (bug, bug) Alex fixed an issue with the Browser toolbox’s debugger being broken when a frame was selected in the iframe dropdown (bug) Alex migrated most of our server actors to proper ES classes (bug, bug) Julian fixed a bug that was preventing to inspect elements on some system pages (bug) WebDriver BiDi Sasha updated our vendored version of puppeteer (bug) which allows us to run Puppeteer BIDI protocol unit tests in CI (bug) Henrik finalized (de-)serialization support for WebElement and ShadowRoot (bug, bug) GeckoDriver was running with Fission disabled in some scenarios (e.g. in Selenium). Henrik fixed the issue (bug) and we released a new version of GeckoDriver, 0.32.1 (bug) ESMification status Small increases this week, but various patches are in progress. ESMified status browser 46.7% toolkit 38.3% Total 47.1% (up from 46.5%) #esmification on Matrix Migration Document (with a walkthrough!) Lint, Docs and Workflow mconley has landed a linting rule to ensure ini files for tests are in alphabetical order. This is just a warning for now. I’ve filed this metabug to start conversions. Here’s a good first bug for anybody who wants to contribute! standard8 turned on eslint-plugin-eslint-plugin to lint our self-built rules. standard8 landed basic ESLint support for loadSubScript. As posted on dev-platform and firefox-dev, this means you’ll need to include less import-globals-from comments if the full url is in the argument to loadSubScript. Migration Improvements (CalState LA Project) Completed Brian Pham fixed a glitch where the click area of a resource type in the new migration wizard was too large Underway Alvin and Bryan are making great progress with favicon import support for Chrome (and Chrome-based browsers) and Safari! We’re in the “writing automated tests” part of the project. Angel has started to dig into not showing resource type checkboxes in the migration dialogs when those resources are actually empty (for example, if the bookmarks database exists but has nothing inside of it). Ani has helped us figure out a way of probing Ubuntu for installed browsers even when we don’t have direct access to the browser profile folder (when Firefox is installed as a Snap package). Brian is adding an error message for the new migration wizard when no browsers to import from are found Evan has started to explore how to import Safari’s history from its SQLite database Nolan is working on a second variant of the selection page in the new migration dialog that we will compare with the default selection page in some user studies. Portia is adding the branding assets of the other browsers that we import from so that we can display their icons in the selection dropdown of the new migration wizard Steven is removing cookie migration support from other browsers. This is because it hasn’t historically worked very well, and runs the risk of bypassing our tracking cookie protection mechanisms. Zach has figured out how to retrieve the credit card data that Chrome-based browsers store locally, and is working on building out a MigratorResource to import them into Firefox’s credit card database when the user asks us to. Picture-in-Picture Thanks to Cieara for fixing duration issues with Hulu Cieara also landed a change that corrects the PiP toggle outline on focus Niklas updated our YouTube wrapper to not show playback controls for live streams kpatenio worked on a fix for ensuring that PiP captions update when the originating window is occluded Follow-up bug for minimized windows on MacOS Search and Navigation Daisuke fixed an issue to show page titles in the urlbar when the whole url is typed @ 1791657 James setup default engines for Friulian and Sardinian @ 1807791 Dale added telemetry and a minimum character match for QuickActions @ 1812152 Mandy fixed the weather results wrapping incorrectly @ 1811556 Mark fixed search engine names being updated correctly when switching languages @ 1781768 Oliver fixed the placeholder being shown correctly in private browsing @ 1792816 Storybook / Reusable components Itiel fixed an RTL issue with moz-toggle (Bug 1813590) Tim landed patches to replace “learn more” links in aboutaddons with moz-support-link (Bug 1804695) Tim removed the redundant support link implementation from aboutaddons (Bug 1809458) Hanna enabled support for writing .mdx and .md based stories in our Storybook (Bug 1805573) We’ve set up a very quiet (so far) matrix room for reusable components


 Dev Discussions - Phillip Carter
Dev Discussions - Phillip Carter

This is the full interview from my discussion with Phillip Carter in my weekly (free!) newsletter, The .NET Stacks. Consider subscribing today!Last week, we talked to Isaac Abraham about F# from a C# developer’s perspective. This week, I’m excited to get more F# perspectives from Phillip Carter. Phillip is a busy guy at Microsoft but a big part of his role as a Program Manager is overseeing F# and its tooling.In this interview, we talk to Phillip about Microsoft F# support, F# tooling (and how it might compare to C#), good advice for learning F#, and more.Can you talk about what you’ve done at Microsoft, and how you landed on F#?I spent some time bouncing around on various projects related to shipping .NET Core 1.0 for my first year-ish at Microsoft. A lot of it was me doing very little in the early days, since there was little for an entry-level PM to do. But I did find that that the Docs team needed help and so I ended up writing a good portion of the .NET docs that exist on docs.microsoft.com today. Some of the information architecture I contributed to is still present there today.I got the F# gig because I had an interest in F# and the current PM was leaving for a different team. Rather than let it sit without a PM for an indeterminate amount of time, everyone agreed that I should take the position. Always better to have someone who’s interested in the space assume some responsibility than have nobody do it, right? I’ve been working on F# at Microsoft ever since.Do you feel F# gets the recognition and attention at Microsoft it deserves?This is always a fun question.Many F# programmers would emphatically proclaim, “No!” and it’s of course a meme that Microsoft Doesn’t Care About F# or whatever. But the reality is that like all other functional programming languages, F# is a niche in terms of adoption, and it is likely to stay a niche if you compare it to the likes of C#, Java, C++, Python, and JavaScript.As a fan of programming languages in general, I feel like tech companies (like Microsoft) emphasize platforms far more than any given language. I find it kind of funny, because I’ve already seen multiple platforms come and go in our industry—but all the languages I’ve been involved with have only become more permanent and grown during that same timespan. This is kind of sidestepping the question, but it really is how I feel about the topic.­­­­­­Being a niche language doesn’t mean something isn’t valuable. To the contrary, there are many large, paying customers who use F# today, and that is only expected to grow as more organizations incorporate and grow software systems and hiring people who like functional programming.  For example, F# powered Azure’s first billion-dollar startup (Jet.com) back in 2016. Could they have used C#? Sure. But they didn’t. Did F# cause them to use Azure? Maybe. They evaluated Azure and Google Cloud and decided on Azure for a variety of reasons, technological compatibility perhaps being one of them. But these questions don’t really matter.From Microsoft’s perspective, we want customers to use the tech they prefer, not the tech we prefer, and be successful with it. If that’s F#, then we want to make sure that they can use our developer tools and platforms and have a good time doing it. If they can’t, then we want to do work to fix it. If you look at official statements on things like our languages, we’re fairly unopinionated and encourage people to try the language and environment that interests them the most and works the best for their scenario.All this context matters when answering this question. Yes, I think Microsoft gives F# roughly the attention and love it deserves, certainly from an engineering standpoint. I don’t think any other major company would do something like pay an employee to fly out to a customer’s office, collect problems they are having with tooling for a niche programming language, and then have a team refocus their priorities to fix a good set of those issues all in time for a major release (in case it wasn’t clear, I am speaking from experience). From the customer standpoint, this is the kind of support that they would expect.From a “marketing” standpoint, I think more attention should be paid to programming languages in general, and that F# should be emphasized more proportionally. But the reality is that there are a lot more platforms than there are languages, so I don’t see much of a change in our industry. I do think that things have improved a lot for F# on this front in the past few years, and I’ve found that for non-engineering tasks I’ve had to work less to get F# included in something over time.This year alone, we’ve had four blog posts about F# updates for F# 5, with a few more coming along. And of course F# also has dedicated pages on our own .NET website, dedicated tutorials for newcomers, and a vast library of documentation that’s a part of the .NET docs site. But if people are waiting for Microsoft’s CEO to get on stage, proclaim that OOP is dead and we all need to do FP with F#, they shouldn’t be holding their breath.This also speaks to a broader point about F# and some Microsoft tech. One of the reasons why we pushed everything into the open and worked to ensure that cross-platform worked well was because we wanted to shift the perception of our languages and tech stacks.People shouldn’t feel like they need Microsoft to officially tell them to use something. They should feel empowered to investigate something like F# in the context of their own work, determine its feasibility for themselves, and present it to their peers.I think it’s Microsoft’s responsibility to ensure that potential adopters are armed with the correct information and have a strong understanding that F# and .NET are supported products. And it’s also Microsoft’s responsibility to communicate updates and ensure that F# gets to “ride the wave” of various marketing events for .NET. But I really, truly want people to feel like they don’t need Microsoft for them to be successful with using and evangelizing F#. I think it’s critical that the power dynamic when concerning F# and .NET usage in any context balances out more between Microsoft and our user base. This isn’t something that can come for free, and does require active participation of people like me in communities rather than taking some lame ivory tower approach.From the build system to the tooling, is F# a first-class citizen in Visual Studio and other tools like C# is? If I’m a C# dev coming over, would I be surprised about things I am used to?This is a good question, and the answer to this is it depends on what you do in Visual Studio. All developers are different, but I have noticed a stark contrast among the C# crowd those who use visual designer tooling and those who do not.For those who use visual designer tooling heavily, F# may not be to your liking. C# and VB are the only two Visual Studio languages that have extensive visual designer tooling support, and if you rely on or prefer these tools, then you’ll find F# to be lacking. F# has an abundance of IDE tooling for editing code and managing your codebase, but it does not plug into things like the EF6 designer, Code Map, WinForms designer, and so on.For anyone who uses Visual Studio to primarily edit code, then F# may take some getting used to, but most of the things you’re used to using are present. In that sense, it is first class. Project integration, semantic colors, IntelliSense, tooltips (more advanced than those in C#), some refactorings and analyzers, and so on.C# has objectively more IDE features than F#, and the number of refactorings available in F# tooling absolutely pales in comparison to C# tooling. Some of these come down to how each language works, though, so it’s not quite so simple as “F# could just have XYZ features that C# has.” But overall, I think people tend to feel mostly satisfied by the kinds of tooling available to them.It’s often claimed that F# needs less refactoring tools because the language tends to guide programmers into one way to do things, and the combination of the F# type system and language design lends itself towards the idiom, “if it compiles, it works right.” This is mostly true, though I do feel like there are entire classes of refactoring tools that F# developers would love to use, and they’d be unique to F# and functional programming.What’s the biggest hurdle you see for people trying to learn F#, especially from OO languages like C# or Java?I think that OO programming in mainstream OO languages tends to over-emphasize ceremony and lead to overcomplicated programs. A lot of people normalize this and then struggle to work with something that is significantly simpler and has less moving parts.When you expect something to be complicated and it’s simple, this simplicity almost feels like it’s mocking you, like the language and environment is somehow smarter than you. That’s certainly what I felt when I learned F# and Haskell for the first time.Beyond this, I think that the biggest remaining hurdles simply are the lack of curly braces and immutability. It’s important to recall that for many people, programming languages are strongly associated with curly braces and they can struggle to accept that a general-purpose programming language can work well without them.C, C++, Java, C#, and JavaScript are the most widely used languages and they all come from the same family of programming languages. Diverging greatly from that syntax is a big deal and shouldn’t be underestimated. This syntax hurdle is less of a concern for Python programmers, and I’ve found that folks with Python experience are usually warmer to the idea of F# being whitespace sensitive. Go figure!The immutability hurdle is a big one for everyone, though. Most people are trained to do “place-oriented programming”—put a value in a variable, put that variable in a list of variables, change the value in the variable, change the list of variables, and so on. Shifting the way you think about program flow in terms of immutability is a challenge that some people never overcome, or they prefer not to overcome because they hate the idea of it. It really does fundamentally alter how you write a program, and if you have a decade or more of training with one way to write programs, immutability can be a big challenge.As a C# developer, in your opinion what’s the best way to learn F#?I think the best way is to start with a console app and work through a problem that requires the use of F# types—namely records and unions—and processing data that is modeled by them.A parser for a Domain-Specific Language (DSL) is a good choice, but a text-based game could also work well. From there, graduating to a web API or web app is a good idea. The SAFE stack combines F# on the backend with F# on the frontend via Fable—a wonderful F# to JavaScript compiler—to let you build an app in F# in multiple contexts. WebSharper also allows you to accomplish this in a more opinionated way (it’s a supported product, too). Finally, Bolero is a newer tech that lets you build WebAssembly apps using some of the more infrastructural Blazor components. Some rough edges, but since WebAssembly has the hype train going for it, it’s not a bad idea to check it out.Although this wasn’t your question, I think a wonderful way to learn F# is to do some basic data analysis work with F# in Jupyter Notebooks or just an F# script with F# Interactive. This is especially true for Python folks who work in more analytical spaces, but I think it can apply to any C# programmer looking to develop a better understanding of how to do data science—the caveat being that most C# programmers don’t use Jupyter, so there would really be two new things to learn.What are you most excited about with F# 5?Firstly, I’m most excited about shipping F# 5. It’s got a lot of features that people have been wanting for a long time, and we’ve been chipping away at it for nearly a year now. Getting this release out the door is something I’m eagerly awaiting.If I had to pick one feature I like the most, it’s the ability to reference packages in F# scripts. I do a lot of F# scripting, and I use the mechanism in Jupyter Notebooks all the time, too. It just kind of feels like magic that I can simply state a package I want to use, and just use it. No caveats, no strings attached. In Python, you need to acquire packages in an unintuitive way due to weirdness with how notebooks and your shell process and your machine’s python installation work. It’s complexity that simply doesn’t exist in the F# world and I absolutely love it.What’s on the roadmap past F# 5? Any cool features in the next few releases?Currently we don’t have much of a roadmap set up for what comes next. There are still a few in-progress features, two of them being rather large a task { } computation expression in FSharp.Core that rewrites into an optimized state machine, and a revamp of the F# constraint system to allow specifying static constraints in type extensions.The first one is a big deal for anything doing high-performance work on .NET. The second one is a big deal for lots of general F# programming scenarios, especially if you’re in the numerical space and you want to define a specialized arithmetic for types that you’re importing from somewhere else. The second one will also likely fix several annoying bugs related to the F# constraint system and generally make library authors who use that system heavily much happier.Beyond this, we’ll have to see what comes up during planning. We’re currently also revamping the F# testing system in our repository to make it easier for contributors to add tests and generally modernize the system that tens of thousands of tests use to execute today. We’re also likely to start some investigative work to rebase Visual Studio F# tooling on LSP and working with the F# community to use a single component in both VS and VSCode. They already have a great LSP implementation, but a big merging of codebases and features needs to happen there. It’ll be really exciting, but we’re not quite sure what the work “looks like” yet.What’s something about working on the F# team that you wish the community knew, but probably doesn’t?I think a lot of folks underestimate just how much work goes into adding a new language feature. Let’s consider something like nameof, which was requested a long time ago. Firstly, there needed to be a design for the obvious behaviors. But then there are non-obvious ones, like nameof when used as a pattern, or what the result of taking the name of an operator should be (there are two kinds of names for an operator in F#).Language features need a high degree of orthogonality—they should work well with every other feature. And if they don’t, there needs to be a very good reason.Firstly, that means a very large test matrix that takes a long time to write, but you also run into quirks that you wouldn’t initially anticipate. For example, F# has functions like typeof and typedefof that accept a type as a parameterized type argument, not an input to a function. Should nameof behave like that when taking the name of a type parameter? That means there are now two syntax forms, not just one. Is that the right call? We thought so, but it took a few months to arrive at that decision.Another quirk in how it differs from C# is that you can’t take a fully-qualified name to an instance member as if it were static.  Why not? Because nameof would be the only feature in all of F# that allows that kind of qualification. Special cases like this might seem fine in isolation, but if you have every language feature deciding to do things its own way rather than consider how similar behaviors work in the language, then you end up with a giant bag of parlor tricks with no ability to anticipate how you can or cannot use something.Then there are tooling considerations does it color correctly in all ways you’d use it? If I have a type and a symbol with the same name and I use nameof on it, what does the editor highlight? What name is taken? What is renamed when I invoke the rename refactoring? Does the feature correctly deactivate if I explicitly set my LangVersion to be lower than F# 5? And so on.These things can be frustrating for people because they may try a preview, see that a feature works great for them now, and wonder why we haven’t just shipped it yet. Additionally, if it’s a feature that was requested a long time ago, there seems to be some assumption that because a feature was requested a long time ago, it should be “further along” in terms of design and implementation. I’m not sure where these kinds of things come from, but the reason why things take long is because they are extremely difficult and require a lot of focused time to hammer out all the edge cases and orthogonality considerations.Can you talk a little about the SAFE Stack and how it can be used in ASP.NET Core applications?The SAFE stack is a great combination of F# technologies—minus the A for Azure or AWS, I guess—to do full-stack F# programming. It wasn’t the first to achieve this—I believe WebSharper was offering similar benefits many years ago—but by being a composition of various open source tools, it’s unique.The S and A letters mostly come into play with ASP.NET Core. The S stands for Saturn, which is an opinionated web framework that uses ASP.NET Core under the hood. It calls into a more low-level library called Giraffe, and if you want to use Giraffe instead (GAFE), you can. The A is more of a stand in for any cloud that can run ASP.NET Core, or I guess it could just mean A Web Server or something. It’s where ASP.NET Core runs under the hood here. The F and E are for Fable and Elmish, which are technologies for building web UIs with F#.I won’t get into the details of how to use SAFE, but I will say that what I love about it is that all the technologies involved are entirely independent of one another and square F# technologies. Yes, they use .NET components to varying degrees and rely on broader ecosystems to supply some core functionality. But they are technologies are made by and for F# developers first.This is a level of independence for the language that I think is crucial for the long-term success of F#. People can feel empowered to build great tech intended mainly for F# programmers, combine that tech with other tech, and have a nice big party in the cloud somewhere. What SAFE represents to me is more important than any of the individual pieces of tech it uses.We’re seeing a lot of F# inspiration lately in C#, especially with what’s new in C# 9 (with immutability, records, for example). Where do you think the dividing line is between C# with FP and using F#? Is there guidance to help me make that decision?I think the dividing line comes down to two things what your defaults are and what you emphasize.C# is getting a degree of immutability with records. But normal C# programming in any context is mutable by default. You can do immutable programming in C# today, and C# records will help with that. But it’s still a bit of a chore because the rest of the language is just begging you to mutate some variables.They’re called variables for a reason! This isn’t a value judgement, though. It’s just what the defaults are. C# is mutable by default, with an increasing set of tools to do some immutability. F# is immutable by default, and it has some tools for doing mutable programming.I think the second point is more nuanced, but also more important. Both C# and F# implement the .NET object system. Both can do inheritance, use accessibility modifiers on classes, and do fancy things with interfaces (including interfaces with default implementations). But how many F# programmers use this side of the language as a part of their normal programming? Not that many. OOP is possible in F#, but it’s just not emphasized. F# is squarely about functional programming first, with an object programming system at your disposal when you need it.On the other hand, C# is evolving into a more unopinionated language that lets you do just about anything in any way you like. The reality is that some things work better than others (recall that C# is not immutable by default), but this lack of emphasis on one paradigm over the other can lead to vastly different codebases despite being written in the same language.Is that okay? I can’t tell. But I think it makes identifying the answer to the question, “how should I do this?” more challenging. If you wanted to do functional programming, you could use C# and be fine. But by using a language that is fairly unopinionated about how you use it, you may find that it’s harder to “get it” when thinking functionally than if you were to use F#. Some of the principles of typed functional programming may feel more difficult or awkward because C# wasn’t built with them in at first. Not necessarily a blocker, but it still matters.What I would say is that if you want to do functional programming, you will only help yourself by learning F# when learning FP. It’s made for doing functional programming on .NET first and foremost, and as a general guideline it’s a good idea to use tools that were made for a specific purpose if you are aligned with that purpose. You may find that you don’t like it, or that you thought some things were cool but you’re ultimately happier with taking what you learned and writing C# code in a more functional style from now on. That’s great, and you shouldn’t feel any shame in deciding that F# isn’t for you. But it’ll certainly making writing functional C# easier, since you’ll already have a good idea of how to generally approach things.Something I ask everyone what is your one piece of programming advice?The biggest piece of advice I would give people is to look up the different programming paradigms, functional being one of them, and try out a language some of them.Most programmers are used to an ALGOL-derived language, and although they are great languages, they all tend to encourage the same kind of thought process for how you write programs. Programming can be a tool for thought, and languages from different backgrounds encourage different ways of thinking about solving problems with programming languages. I believe that this can make people better programmers even if they never use F# or other languages outside of the mainstream ones.Additionally, all languages do borrow from other ones to a degree, and understanding different languages can help you master new things coming into mainstream languages.You can reach Phillip Carter on Twitter.


chmod: cannot access '777': No such file or direct ...
Category: Linux

QuestionHow do you resolve Linux Error chmod cannot access '777' No such file or dire ...


Views: 982 Likes: 103
Validating nested DataAnnotation IOptions recursively with MiniValidation
Validating nested DataAnnotation IOptions recursiv ...

In this short post I show how you can use the MiniValidation library from Damian Edwards to support recursive validation of IOptions object in .NET 6+. Validating IOptions in .NET 6 Last year I wrote a post explaining how to add validation to your strongly typed IOptions objects using built-in functionality and DataAnnotation attributes. .NET 6 added support for this, as well as for validating on app startup, out-of-the-box. I suggest reading that post for details, but in summary it looks something like this builder.Services.AddOptions<MySettings>() .BindConfiguration("MySettings") // ?? Bind the MySettings section in config .ValidateDataAnnotations() // ?? Enable DataAnnotation validation .ValidateOnStart(); // ?? Validate when the app starts Inevitably, someone asked how you can do something similar with FluentValidation, so I wrote a post about that here. And of course, for completeness, someone else pointed out that ValidateDataAnnotations() doesn't validate nested properties, so if you have something that looks like this public class MySettings { [Required] public string DisplayName { get; set; } [Required] public NestedSettings Nested { get; set; } public class NestedSettings { [Required] public string Value { get; set; } [Range(1, 100)] public int Count { get; set; } } } and you bind it as shown in the previous snippet, then the MySettings.Nested property won't be validated. This often takes people by surprise, and is tracked in this issue, but fundamentally this stems from the way the Validator in the DataAnnotation namespace works - it doesn't recursively validate by default. Until there's a solution in the box, there are plenty of workarounds to this, as described in the issue, but in this post I'm going to show a simple alternative use the MiniValidation NuGet package. MiniValidation MiniValidation is a small library created by Damian Edwards on the ASP.NET Core team. As per the README, MiniValidation is A minimalistic validation library built atop the existing features in .NET's System.ComponentModel.DataAnnotations namespace. Adds support for single-line validation calls and recursion with cycle detection. It contains code that I have often found myself writing in the past, to simplify using the built-in DataAnnotation methods. It doesn't do anything especially fancy, but it does it in a nice little package without any effort! In this case, we're going to rely on it for the recursion it provides. In it's simplest form, you can validate a DataAnnotations object mySettings with a single call // ?? Do the validation errors is IDictionary<string, string[]> MiniValidator.TryValidate(mySettings, out var errors); // Print the errors foreach((string member, string[] memberErrors) in errors) { var memberError = string.Join(", ", memberErrors); Console.WriteLine($"{member} had the following errors {memberError}"); } It's a small thing, but the terseness and extra features (like recursion) make it an easy package to recommend playing with. To demonstrate, in this post I'll show how you can hook it into the OptionsBuilder to solve the problem with nested classes. Validating IOptions with MiniValidation As I described in my previous post that used FluentValidation, the interface we need to implement is IValidateOptions<T>. In the FluentValidation we also had to hook up various extra validators, but in this case it's simpler as we're just reusing the existing DataAnnotation attributes. To start with, you'll need to install the MiniValidation library. From the command line, run dotnet add package MinimalApis.Extensions This adds the package to your .csproj file, something like this <Project Sdk="Microsoft.NET.Sdk.Web"> <PropertyGroup> <TargetFramework>net6.0</TargetFramework> <Nullable>enable</Nullable> <ImplicitUsings>enable</ImplicitUsings> </PropertyGroup> <ItemGroup> <!-- ?? Add this --> <PackageReference Include="MiniValidation" Version="0.7.4" /> </ItemGroup> </Project> Now we can create an IValidateOptions<T> implementation that uses the MiniValidation helpers. The implementation below is based on the original DataAnnotationValidateOptions type used in the ValidateDataAnnotations() call, so you can consider it a complete implementation. This implementation handles named options too. If you're not familiar with named options, you can read my post about them here. public class MiniValidationValidateOptions<TOptions> IValidateOptions<TOptions> where TOptions class { public MiniValidationValidateOptions(string? name) { Name = name; } public string? Name { get; } public ValidateOptionsResult Validate(string? name, TOptions options) { // Null name is used to configure ALL named options, so always applys. if (Name != null && Name != name) { // Ignored if not validating this instance. return ValidateOptionsResult.Skip; } // Ensure options are provided to validate against ArgumentNullException.ThrowIfNull(options); // ?? MiniValidation validation ?? if (MiniValidator.TryValidate(options, out var validationErrors)) { return ValidateOptionsResult.Success; } string typeName = options.GetType().Name; var errors = new List<string>(); foreach (var (member, memberErrors) in validationErrors) { errors.Add($"DataAnnotation validation failed for '{typeName}' member '{member}' with errors '{string.Join("', '", memberErrors)}'."); } return ValidateOptionsResult.Fail(errors); } } To make it easy to add this type to your options we'll create an extension method on OptionsBuilder too public static class MiniValidationExtensions { public static OptionsBuilder<TOptions> ValidateMiniValidation<TOptions>( this OptionsBuilder<TOptions> optionsBuilder) where TOptions class { // ?? register the validator against the options optionsBuilder.Services.AddSingleton<IValidateOptions<TOptions>>( new MiniValidationValidateOptions<TOptions>(optionsBuilder.Name)); return optionsBuilder; } } And that's it, we're done! Trying it out To use our new extension, we simply replace the call to ValidateDataAnnotations() with ValidateMiniValidation(). No other changes are needed in our project using System.ComponentModel.DataAnnotations; using Microsoft.Extensions.Options; using MiniValidation; var builder = WebApplication.CreateBuilder(args); builder.Services.AddOptions<MySettings>() .BindConfiguration("MySettings") .ValidateMiniValidation() // ?? Replace with mini validation .ValidateOnStart(); var app = builder.Build(); app.MapGet("/", (IOptions<MySettings> options) => options.Value); app.Run(); If we have the following config in our appsettings.json file (where the Nested property values are invalid) { "MySettings" { "DisplayName" "Display", "Nested" { "Count" 0 } } } then when we run our application, we'll get an error when you call app.Run() OptionsValidationException DataAnnotation validation failed for 'MySettings' member 'Nested.Value' with errors 'The Value field is required.'.; DataAnnotation validation failed for 'MySettings' member 'Nested.Count' with errors 'The field Count must be between 1 and 100.'. Microsoft.Extensions.Options.OptionsFactory<TOptions>.Create(string name) Microsoft.Extensions.Options.OptionsMonitor<TOptions>+<>c__DisplayClass10_0.<Get>b__0() ... Success! This is just one of the ways you can handle recursive validation in your IOptions object, but it feels like an easy one to me! Summary In this post I described the problem that by default, DataAnnotation validation doesn't recursively inspect all properties in an object for DataAnnotation attributes. There are several solutions to this problem, but in this post I used the MiniValidation library from Damian Edwards. This simple library provides a convenience wrapper around DataAnnotation validation, as well as providing features like recursive validation. Finally I showed how you can replace the built-in DataAnnotation validation with a MiniValidation-based validator.


Login to Continue, We will bring you back to this content 0



For peering opportunity Autonomouse System Number: AS401345 Custom Software Development at ErnesTech Email Address[email protected]