Visual studio – CWinApp http://cwinapp.com/ Sun, 15 May 2022 01:35:46 +0000 en-US hourly 1 https://wordpress.org/?v=5.9.3 https://cwinapp.com/wp-content/uploads/2021/10/icon-3-120x120.png Visual studio – CWinApp http://cwinapp.com/ 32 32 Visual Studio 2022 17.2 goes into general availability and has update issues — Visual Studio Magazine https://cwinapp.com/visual-studio-2022-17-2-goes-into-general-availability-and-has-update-issues-visual-studio-magazine/ Thu, 12 May 2022 16:32:57 +0000 https://cwinapp.com/visual-studio-2022-17-2-goes-into-general-availability-and-has-update-issues-visual-studio-magazine/ News Visual Studio 2022 17.2 goes into general availability, encounters update issues Visual Studio 2022 17.2 reached general availability status this week, but some users outside of the United States soon experienced download update issues. “As of 7:23 a.m. PDT May 11, 2022, we are aware of some issues outside of the US region that […]]]>

News

Visual Studio 2022 17.2 goes into general availability, encounters update issues

Visual Studio 2022 17.2 reached general availability status this week, but some users outside of the United States soon experienced download update issues.

“As of 7:23 a.m. PDT May 11, 2022, we are aware of some issues outside of the US region that are still experiencing delays and failures in updating Visual Studio and other downloads. Teams are currently investigating and we apologize for the inconvenience,” reads a notice above the announcement blog post. It provides links for problem updates as well as a workaround.

If you manage to download the update, you will see a host of improvements to the flagship IDE.

“This release brings continued improvements to the C# and .NET experiences, new Git performance and experiences, updates for C++ developers, and new Azure tools for on-premises development and deployment,” Microsoft said.

As for this last element for cloud development, a focal point for Microsoft, the functionality of connected services has been improved with the possibility of using containers for certain Azure services configured by the developer, allowing local debugging. Connected Services is a collection of Visual Studio tools that help developers connect applications to:

  • Azure Services
  • OpenAPI endpoints
  • gRPC (Remote Procedure Call) endpoints
  • Windows Communication Foundation (WCF) endpoints

The v17.2 update also supports the new Azure Container Apps service for direct deployment or configuration with GitHub Actions. This service helps developers run microservices and containerized applications on a serverless platform, and it can now serve as a deployment target for projects using containers such as a web application or ASP.NET Core API.

The IDE’s “Go to Implementation” functionality has also been enhanced with Source Link, which enables debugging the source code of .NET assemblies from NuGet. Now, when working with referenced assemblies that provide embedded source information, developers can access the original source files that implement the target symbols, as shown in this animated GIF:

Source link in animated action
[Click on image for larger view.] Source link in animated action (source: Microsoft).

Other release highlights as described by Microsoft include:

  • Raw string literal: “In C# 11, we added a new language feature called raw string literals. We now have a refactoring to convert a normal or verbatim string literal to a raw string literal.”
  • Debugging collections: “We recently highlighted this feature in a Visual Studio 17.2 Preview 2, but it bears repeating. If you regularly debug your .NET code and want to inspect large and possibly complex collections, we’ve introduced a new visualizer in the debugging experience for IEnumerable object types.”
  • Razor Editor: “As of version 17.1, we’ve improved the reliability of the new Razor editing experience. In version 17.2, we’ve added in-editor support for:

    • Ability to collapse regions for easy readability and organization
    • The new Razor editor now supports snippet functionality in C# code!
    • We heard you and the ‘wrap div’ shortcut is enabled, use Shift + Alt + W to run”
  • Live Web Preview for ASP.NET Framework: “In the initial release of Visual Studio 2022, we introduced a new feature for those who work with Web Forms applications and the designer. Web Live Preview allows your running application to be the design surface and provides code synchronization between the source and the web surface to help you navigate directly to the code file of the element you’re editing.”
  • C++: “Support for C++20 modules is coming to CMake in Visual Studio! You can try out our experimental support now by making sure you supply the latest /std:c++20 or /std:c++ switches to the compiler and using the MSBuild (Visual Studio) generator for CMake rather than Ninja.” The online hints and improved device and RTOS register views for embedded developers, introduced in v17.1, also boost C++ development.
  • Git tools: “We continue to work on improving the Git experience in Visual Studio. Inline staging support was introduced in Visual Studio 17.2 Preview and now you can also enable it in 17.2 GA by going to to the preview features pane and toggling the ‘Enable line staging support checkbox.’
  • Business support: “Version 17.2 is the second Long-Term Servicing Channel (LTSC) for Visual Studio 2022. Servicing Channels provide larger organizations with increased flexibility in when they choose to adopt new features that are released with updates. Minor release updates for Enterprise, Professional, and Build tools. 17.2 LTSC will be supported for 18 months, until January 9, 2024.”

About the Author


David Ramel is an editor and writer for Converge360.



]]>
Visual Studio Installer checking for “endless” updates • The Register https://cwinapp.com/visual-studio-installer-checking-for-endless-updates-the-register/ Wed, 11 May 2022 15:00:00 +0000 https://cwinapp.com/visual-studio-installer-checking-for-endless-updates-the-register/ Microsoft Visual Studio seems to be having a bad Wednesday with users of the development suite forced to jump into Microsoft’s feedback forum to complain about prolonged issues with the software installer. The problem manifests itself when the installer tries to extract files from where Microsoft has hidden them. Rather than the usual progress bar […]]]>

Microsoft Visual Studio seems to be having a bad Wednesday with users of the development suite forced to jump into Microsoft’s feedback forum to complain about prolonged issues with the software installer.

The problem manifests itself when the installer tries to extract files from where Microsoft has hidden them. Rather than the usual progress bar of optimism, users have found themselves staring at “Getting things ready…” or “Checking for updates…” while the backend seems to be twiddling its thumbs.

The issues were first reported on Twitter around 07:30 UTC, and the annoyance is palpable. Eight hours and counting, but normal service still hasn’t resumed.

A few users have managed to get things started, only to be presented with an “An installer file was not downloaded” error.

Some assumed the problem was with their installation, and so uninstalled and tried to reinstall the software, then found themselves stuck once again, except this time without even an outdated IDE they can use.

It’s not a great look for Microsoft. Earlier this week, the company bragged, “We’re continually improving the Visual Studio update experience so that it’s as easy and effortless as possible,” with the addition of an Update All button. update on the installer.

A single click should have been enough to do the magic: “So you can quickly run the updates, go have a cup of tea, and when you come back, all your installations will have been updated with the latest that Visual Studio has to offer.”

Instead, users are forced to spend quality time wondering why the app disappeared.

Microsoft has yet to comment officially on this, however, the developers have taken matters into their own hands, with some suggesting a change to the hosts file, while others have launched VPNs to help the installer get to where it needs to go.

Obviously, extreme caution should be exercised when playing with Windows internals.

The issue appears to be regional, with users across Europe and the Middle East registering complaints, including developers The Reg talked. Additionally, some developers have reported success on one device but failure on another.

As for Visual Studio’s own service status page, at the time of writing everything was green and users were greeted with a cheery “All is well, no active events yet” while they were sadly thinking about how to recover after an uninstall.

Visual Studio Status

Click to enlarge

“Lies, damn lies, and cloud service status dashboards,” one user joked.

The register contacted Microsoft to find out what happened to Visual Studio’s servers and will update if the company responds. ®

]]>
C# Gains the Most in the Popularity of Programming Languages ​​Index — Visual Studio Magazine https://cwinapp.com/c-gains-the-most-in-the-popularity-of-programming-languages-index-visual-studio-magazine/ Tue, 10 May 2022 16:32:34 +0000 https://cwinapp.com/c-gains-the-most-in-the-popularity-of-programming-languages-index-visual-studio-magazine/ News C# earns the most in the popularity index of programming languages Microsoft’s C# programming language posted the biggest 12-month gain in popularity, according to the May 2022 TIOBE index. After pledging to compete for TIOBE’s “Programming Language of the Year” award last December, C# ultimately failed, coming in second behind Python. But now the […]]]>

News

C# earns the most in the popularity index of programming languages

Microsoft’s C# programming language posted the biggest 12-month gain in popularity, according to the May 2022 TIOBE index.

After pledging to compete for TIOBE’s “Programming Language of the Year” award last December, C# ultimately failed, coming in second behind Python.

But now the surge continues, with the May 2022 report noting that C# has “far” surpassed other languages ​​as of May 2021.

TIOBE index for May 2022
[Click on image for larger view.] TIOBE index for May 2022 (source: TIOBE index).

“His ranking has increased by almost 2% over the past 12 months,” TIOBE said. “C# is one of the most mature programming languages ​​out there, supporting many modern programming paradigms. Until recently, its only downside was that its Linux support was questionable, but that’s changing rapidly over the past couple of years. So there is a good chance that C# could enter the top 3 of the TIOBE index by replacing C.”

Indeed, regarding the “rapidly evolving” Linux claim, Microsoft’s guidance released details last month on how to “install .NET on Linux distributions.” However, full Linux support is still not here, as Microsoft also notes that “Visual Studio 2022 lets you build and debug apps for Linux using C++, Python, and Node.js.” Developers can take a few steps to use MonoDevelop and Visual Studio Code for C# Linux programming.

Despite C#’s main 12-month percentage increase in the May 2022 TIOBE Index, C# remained in its fifth spot, with the only changes in the top 10 being Python overtaking C for the top spot, and SQL overtaking PHP to move from tenth to ninth place.

The TIOBE Index ranking is based on results from search engines that measure the number of qualified engineers worldwide, courses, and third-party vendors to determine the languages ​​in which the most lines of code are written.

About the Author


David Ramel is an editor and writer for Converge360.



]]>
visual studio code https://cwinapp.com/visual-studio-code/ Tue, 10 May 2022 10:32:12 +0000 https://cwinapp.com/visual-studio-code/ Microsoft and the Visual Studio Code (VS Code) team have rolled out version 1.67 of the Electron-based editor which has become the world’s favorite IDE – the latest StackOverflow survey estimated it was used by 71.06 % of respondents, more than double the use -placed Visual Studio. It’s become a monster project and issues are […]]]>

Microsoft and the Visual Studio Code (VS Code) team have rolled out version 1.67 of the Electron-based editor which has become the world’s favorite IDE – the latest StackOverflow survey estimated it was used by 71.06 % of respondents, more than double the use -placed Visual Studio.

It’s become a monster project and issues are popping up every few minutes on GitHub.

Sometimes small changes have the biggest impact, and that can be the case with bracket pair colorization, a feature that was originally an extension but became part of core VS Code in August 2021 – with a claimed 10,000x performance improvement.

Deeply embedded code in brace languages ​​like JavaScript, Java, C, and C# can be difficult to navigate or fix if something goes wrong, and inadvertently removing a brace can cause the editor to report hundreds of errors. The color coding of the pairs is a big help and also works with square brackets to help untangle long lines of code.

In this latest release, it’s enabled by default, which means developers who haven’t discovered it before may wonder how they managed without it.

Color-coded parenthesis pairs help navigate and correct code – now enabled by default

Markdown editing is improved. Authors can link to files by dragging and dropping from Explorer or from a web browser while holding down the Shift key, convenient for documentation. Another new feature in Markdown is the Find All References, which works for headings, links, file references, and URLs.

Related is the new ability to rename link destinations, including headers, file links, and referral links, while automatically updating all links that target them. This makes it much easier to update a large document without breaking links.

Perhaps the most strategic change in this release is a preview feature, the ability to import and export settings profiles. This includes installed extensions as well as UI customizations such as what’s visible in the activity bar – the bar with icons for key functions like explorer, search, and source control.

It doesn’t include all the settings yet, but more comprehensive import and export is planned. Use cases include standardizing a development team’s settings or providing students with a preconfigured configuration.

The concept could be useful for tailoring VS Code to specific types of work. The popularity of the editor and the large number of extensions can lead to a bloated configuration and impact performance. A developer might want to use one set of extensions for TypeScript or JavaScript, and another for Python, for example.

It is already possible to have language specific settings, but combining with profiles would make this more powerful. Caution should be exercised, however, as importing profiles overwrites existing settings.

Java coders benefit in this release from lazy variable resolution, a debugging feature that defers retrieving values ​​for what the team describes as “an expensive variable” until it is explicitly viewed.

Python support has also been updated. The official Python extension was getting too big, so the team is splitting into separate extensions to improve performance.

A new extension now supports the Black Python code formatter which its authors describe as “uncompromising” because “you agree to cede control over the details of manual formatting”.

Improvements have also been made to Jupyter notebook support. The extension can now be used as a web extension with the browser version of VS Code, but with limited functionality, and many other features are planned for this, so it will work in environments such as Microsoft’s vscode.dev.

]]>
Deep Dive into Blazor – Visual Studio Magazine https://cwinapp.com/deep-dive-into-blazor-visual-studio-magazine/ Mon, 09 May 2022 17:42:40 +0000 https://cwinapp.com/deep-dive-into-blazor-visual-studio-magazine/ Questions and answers Q&A: Deep dive into Blazor The “hottest” project in the Microsoft-centric web development space is Blazor, which offers both a server-side component and a client-side component based on the revolutionary WebAssembly technology, combining to provide a C# instead of JavaScript. The free and open source framework has evolved from its web orientation […]]]>

Questions and answers

Q&A: Deep dive into Blazor

The “hottest” project in the Microsoft-centric web development space is Blazor, which offers both a server-side component and a client-side component based on the revolutionary WebAssembly technology, combining to provide a C# instead of JavaScript.

The free and open source framework has evolved from its web orientation to target other domains including mobile and even desktop.

Officially, Microsoft says:

Blazor apps are composed of reusable web UI components implemented using C#, HTML, and CSS. Client and server code is written in C#, allowing you to share code and libraries.

Blazor is a feature of ASP.NET, the popular web development framework that extends the .NET development platform with tools and libraries for building web applications.

With its growing popularity in the Microsoft dev camp, it’s no surprise that it’s getting an in-depth feature preview at the upcoming Visual Studio Live! conference scheduled for June 13-17, 2022 in Austin, Texas.

Directing the deep dive is Rockford Lhotka, a well-known open source and distributed systems architect, author, and speaker. We caught up with “Rocky” for a short Q&A to learn more about his presentation which will teach attendees:

  • How Blazor, WebAssembly, and .NET combine to enable this app platform
  • How to Build Server-Side Blazor and Blazor WebAssembly Apps
  • How to use Blazor UI framework features such as UI components, data binding, routing, and authorization

Visual Studio Magazine: From its roots as Steve Sanderson’s pet project, Blazor has become hugely popular. Besides allowing C# coders to participate in the web development action instead of relying primarily on traditional JavaScript, what else does Blazor offer to explain this popularity?
Lhotka: Blazor provides a number of powerful features in addition to allowing C# developers to use their language of choice for web development.

“Blazor provides a number of powerful features in addition to allowing C# developers to use the language of their choice for web development.”

Rockford Lhotka, Chief Software Architect, Marimer LLC

Blazor supports running your code on the server or on the client through WebAssembly, and you can choose which users or devices get which experience. For example, you can direct users with older, less powerful devices to use server-side Blazor, and users with modern devices to use Blazor WebAssembly.

Blazor also includes a powerful UI component model, based on learnings from previous UI frameworks such as MVC, Web Forms, Windows Forms, WPF, and Xamarin. The Blazor UI Component model makes it easy to create highly maintainable and reusable UI components surrounding a single UI widget or entire sections of app functionality. Coupled with the simple yet extremely powerful data-binding capabilities supported by Blazor, the result is a UI template designed for building enterprise-level applications down to a simple web page.

ASP.NET Core MVC is also less dependent on JavaScript than other alternative frameworks. Does Blazor offer advantages over ASP.NET Core MVC, or are they specific tools for different types of work?
ASP.NET Core MVC is a server-side web framework, with roots dating back to the days before what we now think of as the modern web. For some application scenarios, a server-based model that pushes HTML, CSS, and JavaScript to the browser is still very valid. This is especially true for scenarios where data display is important and user interactivity is of secondary importance.

For applications where user interactivity is very important, most people prefer UI frameworks like Angular, React, or Blazor. All of these tools provide the ability to create rich user experiences, though none are as good at displaying raw data as something like MVC.

The advantage of Blazor in this case is that you can mix ASP.NET MVC or Razor Pages functionality with your Blazor functionality in the same app and using the same IDE and programming language.

Since its initial focus on SPA apps, Blazor WebAssembly has been aimed at all sorts of other targets, from mobile to even desktop. Is there a limit to this? Why not Blazor for everything?
WebAssembly itself is likely to be a transformative technology for many types of applications, as it runs in all modern browsers and in a growing number of server-side and IoT scenarios, including places like Kubernetes. The ability to write code in the language of your choice, such as C#, Go, Rust, or many others – and compile that code to WebAssembly so it can run in many environments – is extremely convincing.

Blazor WebAssembly itself is a UI framework focused on leveraging HTML and CSS, along with your C# code (instead of TypeScript or JavaScript) to build browser-based apps. As with other SPA technologies, Blazor benefits greatly from the expansion of browser-based hybrid scenarios for hosting on mobile and desktop apps, as well as directly in a browser experience.

What all of these have in common is that the browser sandbox remains in place. That’s good, because it means Blazor WebAssembly apps can be run in your browser or as a mobile or desktop app with the same security and trust you have with apps written in other tools that target the browser, such as Angular or React.

On the other hand, it is often more cost effective to build very high fidelity mobile applications using more native technologies than browser-based technologies. If you’re building a consumer-facing mobile or desktop app that’s a primary touchpoint for your brand, obviously it’s critical that your users get the best possible experience, which is what drives most organizations to build iOS and Android apps. native, or perhaps to use a cross-platform tool like Xamarin/MAUI or Flutter.

Do organizations typically combine Blazor Server and Blazor WebAssembly functionality in their development, or did you find one or the other more important?
From my observations, many organizations use server-side Blazor with the understanding that if they need the scalability provided by Blazor WebAssembly, they can adopt this model in the future. Slightly fewer organizations build Blazor WebAssembly apps out of the box, and a minority build their apps to dynamically switch between the two models at runtime.

What about performance? How does Blazor compare to alternative frameworks like React and others?
When talking about Blazor performance, it is necessary to separate server-side Blazor from Blazor WebAssembly.

Server-side Blazor is extremely capable, with performance largely based on ensuring your web server is sufficient for the workload. The software architecture behind server-side Blazor is extremely similar to the proven designs used by VT or 3270 terminals of yore, but with modern internet speeds and server hardware.

Blazor WebAssembly, or any WebAssembly-based UI, can be slower than JavaScript UI frameworks like React. This is because WebAssembly does not yet allow native code to interact directly with the HTML DOM. Interaction with UI elements must therefore go through a JavaScript shim. Pure computational code tends to be faster in WebAssembly than in JavaScript, but UI interactions are slower.

You have to temper this with the understanding that when used correctly, all of these SPA UI frameworks, including Blazor WebAssembly, can create top-notch user experiences that are very satisfying to use.


What innovations do you see coming for Blazor and its client-side technology, WebAssembly?


I can’t wait for WebAssembly to embrace multi-threading and have the ability for native wasm code to interact directly with the HTML DOM. I’m also extremely excited about how WebAssembly is spreading beyond the browser, with the potential to become a common assembly language for client, servers, IoT devices and more.

Blazor is poised to support multithreading, and with its tight integration with the MAUI framework, Blazor is likely to become a major technology for building apps that run in browsers, on mobile devices, and on desktops. desktop, all based on the same C#, HTML and CSS code base.

About the Author


David Ramel is an editor and writer for Converge360.



]]>
Dapr for Building Distributed .NET Applications – Visual Studio Magazine https://cwinapp.com/dapr-for-building-distributed-net-applications-visual-studio-magazine/ Tue, 03 May 2022 18:14:40 +0000 https://cwinapp.com/dapr-for-building-distributed-net-applications-visual-studio-magazine/ Questions and answers Q&A: Dapr for Building Distributed .NET Applications Modern distributed applications require more than just application logic. Features such as service state management, communication using publish/subscribe messaging, and event-driven binding to cloud resources may be required. Dapr introduces a runtime to offer such building blocks and is less invasive in your application, allowing […]]]>

Questions and answers

Q&A: Dapr for Building Distributed .NET Applications

Modern distributed applications require more than just application logic. Features such as service state management, communication using publish/subscribe messaging, and event-driven binding to cloud resources may be required. Dapr introduces a runtime to offer such building blocks and is less invasive in your application, allowing you to choose what you need.

Dapr has become so essential in the .NET space for distributed applications that it is the subject of an upcoming advanced level workshop which will be led by Alex Thissen to Visual Studio Live! conference scheduled for June 13-17 in Austin, Texas.

dapr
[Click on image for larger view.] dapr (source: Microsoft).

Thissen, an architect, lead developer, and mentor at companies large and small, will lead the workshop titled Dapr for Building Distributed .NET Applications on June 17.

The workshop will examine the approach taken by the Dapr runtime with a sidecar architecture, separating application logic from Dapr runtime components while showing participants how to develop distributed applications in .NET using the features of Dapr and how to link to messaging infrastructure, cloud resources and use the actor programming model and client proxies. Coders will also learn how to combine Dapr into ASP.NET Core applications using routing, controllers, and middleware.

Before the workshop, we caught up with Thissen to find out more in a short Q&A session.

Visual Studio Magazine: Microsoft says Dapr addresses a big challenge inherent in modern distributed applications: complexity. How?
Thissen: Distributed applications in a modern architecture and cloud environment are inherently complex. Dapr provides an application-level abstraction and removes a considerable amount of that complexity.

“Developers can focus on the logic instead of having to learn and work with the low-level details of the cloud services used.”

Alex Thissen, Architect, Lead Developer and Mentor

The challenges of communicating and discovering services, pub/sub messaging patterns, storage and multithreading, and high levels of concurrency are facilitated by the building blocks of Dapr. Languages ​​help combine application logic with the use of building blocks in native constructs. Developers can focus on the logic instead of having to learn and work with the low-level details of the cloud services used.

What are some examples of these building blocks?
The building blocks cover storage, secrets management, service-to-service communication, pub/sub models, actor programming model, configuration, observability, and bindings to cloud services. There is a long list of specific blocks for each of them. These include many services from Microsoft Azure, Google Cloud Provider and Amazon Web Services. Application logic is independent of the specific block used, so block switching is relatively easy.

Can you briefly describe what a sidecar architecture is?
A sidecar architecture takes advantage of a container orchestrator’s ability to host container instances with additional accompanying containers tightly connected to each other. These additional containers are sidecars and help the main container provide additional functionality. Dapr uses sidecars to provide secure mutual TLS communication to other services, service discovery, distributed tracing, and binding to different cloud services.

What is the biggest problem that developers typically find when learning to use Dapr?
Dapr uses Kubernetes as its production hosting environment. Dapr itself is fairly accessible, but learning Kubernetes is daunting and challenging. Developers will need to be familiar with container technology in general and Kubernetes as a container orchestrator in particular.

Dapr is described as an open source project sponsored by Microsoft. What benefits does this sponsorship bring to .NET-centric developers?
.NET is a first-class citizen for Dapr to implement applications using the application runtime. The same goes for other languages ​​such as Go and C++. The benefits for .NET developers are the long-standing support implied by Microsoft’s involvement. Also, .NET will often be one of the first to get support for new features in Dapr.

About the Author


David Ramel is an editor and writer for Converge360.



]]> Naive Bayesian Classification Using C# — Visual Studio Magazine https://cwinapp.com/naive-bayesian-classification-using-c-visual-studio-magazine/ Mon, 02 May 2022 20:09:48 +0000 https://cwinapp.com/naive-bayesian-classification-using-c-visual-studio-magazine/ The Data Science Lab Naive Bayes Classification using C# Dr. James McCaffrey of Microsoft Research presents a complete step-by-step example with all the code to predict a person’s optimism score from their occupation, eye color, and country. By James McCaffrey 02/05/2022 The goal of a naive Bayesian classification problem is to predict a […]]]>

The Data Science Lab

Naive Bayes Classification using C#

Dr. James McCaffrey of Microsoft Research presents a complete step-by-step example with all the code to predict a person’s optimism score from their occupation, eye color, and country.

The goal of a naive Bayesian classification problem is to predict a discrete value called a class label. The idea is best explained with a concrete example. Suppose you have a set of 40 data items where each item consists of a person’s profession (actor, baker, clerk, or dishwasher), eye color (green or hazel), country (Italy, Japan or Korea) and his personality optimism score (0, 1 or 2). You want to predict a person’s optimism score based on their profession, eye color, and country. This is an example of multiclass classification because the variable to be predicted, optimism, has three or more possible values. If the variable to be predicted had only two possible values, the problem would be called binary classification. Unlike some machine learning techniques, Naive Bayes can handle both multiclass and binary classification problems.

Figure 1: Naive Bayes classification using C# in action
[Click on image for larger view.]Figure 1: Naive Bayes Classification using C# in action

A good way to see where this article is going is to take a look at the screenshot of a demo program in Figure 1. The demo sets up 40 data elements – profession, eye color, country, optimism. The first data elements are:

actor  green  korea  1
baker  green  italy  0
diver  hazel  japan  0
diver  green  japan  1
clerk  hazel  japan  2

Note that all data values ​​are categorical (not numeric). This is a key feature of the naive Bayesian classification technique presented in this article. If you have numerical data, such as a person’s age in years, you can group the data into categories such as child, adolescent, adult.

The demo configures an item to predict as (“baker”, “hazelnut”, “italy”). Then the demo loops through the data and calculates and displays the smoothed joint counts (“add 1”). For example, the 5 in the screenshot means there are 4 bakers who have optimism class = 0.

The demo calculates the raw number of unsmoothed classes as (19, 14, 7). This means that there are 19 people with optimism class = 0, 14 people with class = 1, and 7 people with class = 2. Note that 19 + 14 + 7 = 40, the number of elements of data.

The smoothed joint counts and raw class counts are mathematically combined to produce proof terms of (0.0027, 0.0013, 0.0021). These correspond to the class likelihoods (0, 1, 2). Because the greatest evidentiary value is on the index [0]the prediction for the person (“baker”, “hazelnut”, “italy”) is class 0.

Since the proof terms are somewhat difficult to interpret, the demo converts the three proof terms into pseudo-probabilities: (0.4418, 0.2116, 0.3466). The values ​​are not true mathematical probabilities, but because they add up to 1.0, they can be interpreted roughly as probabilities. The greatest probability is at the clue [0].

This article assumes you have intermediate or better programming skills with a C-family language such as Python or Java, but does not assume you know anything about naive Bayes classification. The complete demo code and associated data are shown in this article. Source code and data are also available in the accompanying download. All normal error checking has been removed to keep the main ideas as clear as possible.

Understanding Naive Bayes Classification

The first step in naive Bayesian classification is to calculate the joint numbers associated with the data item to be predicted. For (“baker”, “hazel”, “italy”) and the 40-item demo data, the joint counts are:

baker and class 0 = 4
baker and class 1 = 0
baker and class 2 = 1
hazel and class 0 = 5
hazel and class 1 = 2
hazel and class 2 = 2
italy and class 0 = 1
italy and class 1 = 5
italy and class 2 = 1

Joint accounts are multiplied together when calculating terms of evidence. If a joint count is 0, the entire term is set to zero, so 1 is added to each joint count to avoid this. This is called Laplacian smoothing.

The next step in naive Bayesian classification is to calculate the number of each of the classes to be predicted. For the demo data, the number of classes is (19, 14, 7). There is no need to smooth the number of classes as there will always be at least one of each class.

Next, a proof term (sometimes called Z) is calculated for each possible class value. For class 0, the proof term is:

Z(0) = (5 / 19+3) * (6 / 19+3) * (2 / 19+3) * (19 / 40)
     = 4/22 * 5/22 * 1/22 * 19/40
     = 0.1818 * 0.2273 * 0.0435 * 0.4750
     = 0.0027

The last term, 19/40, is the probability of class 0. In the first three terms, the numerator is a smoothed joined number. The denominator is the raw number of classes with 3 (number of predictor values) added to compensate for smoothing.

For class 1, the proof term is:

Z(1) = (1 / 14+3) * (3 / 14+3) * (6 / 14+3) * (14 / 40)
     = 1/17 * 3/17 * 6/17 * 14/40
     = 0.0588 * 0.1765 * 0.3529 * 0.3500
     = 0.0013

And for class 2, the proof term is:

Z(2) = (2 / 7+3) * (3 / 7+3) * (2 / 7+3) * (7 / 40)
     = 2/10 * 3/10 * 2/10 * 7/40
     = 0.2000 * 0.3000 * 0.2000 * 0.1750
     = 0.0021

The largest proof term is associated with class 0, so it is the predicted class. To make proof terms easier to compare, they are often normalized so that their sum is 1.0. The sum of the proof terms is 0.0027 + 0.0013 + 0.0021 = 0.0061. The normalized (pseudo-probabilities) are:

P(class 0) = 0.0027 / 0.0061 = 0.4418
P(class 1) = 0.0013 / 0.0061 = 0.2116
P(class 2) = 0.0021 / 0.0061 = 0.3466

Since each proof term is the product of values ​​less than 1, it is possible that the calculation will run into problems. Therefore, in practice, the calculation of proof terms uses the mathematical log() of each value which allows additions and subtractions instead of multiplications and divisions.

The demo program

The complete demo program, with some minor modifications to save space, is shown in List 1. To create the program, I launched Visual Studio and created a new C# .NET Core console application named NaiveBayes. I used Visual Studio 2019 (Free Community Edition), but the demo has no major dependencies, so any version of Visual Studio will work fine. You can also use the Visual Studio Code program.

Once the template code loaded, in the editor window, I removed all unnecessary namespace references, leaving only the reference to the top-level System namespace. In the Solution Explorer window, I right-clicked the Program.cs file, renamed it to the more descriptive NaiveBayesProgram.cs, and allowed Visual Studio to automatically rename the class Program in NaiveBayesProgram.

List 1:
Complete Naive Bayes demo code

using System;
namespace NaiveBayes
{
  class NaiveBayesProgram
  {
    static void Main(string[] args)
    {
      Console.WriteLine("nBegin naive Bayes classification ");
      string[][] data = GetData();
      Console.WriteLine("nData looks like: ");
      Console.WriteLine("actor  green  korea  1");
      Console.WriteLine("baker  green  italy  0");
      Console.WriteLine("diver  hazel  japan  0");
      Console.WriteLine("diver  green  japan  1");
      Console.WriteLine("clerk  hazel  japan  2");
      Console.WriteLine(" . . . ");

      int nx = 3;  // number predictors (job, eye, country)
      int nc = 3;  // number classes (0, 1, 2)
      int N = 40;  // number data items

      int[][] jointCounts = new int[nx][];
      for (int i = 0; i < nx; ++i)
        jointCounts[i] = new int[nc];

      int[] yCounts = new int[nc];

      string[] X = new string[] { "baker", "hazel", "italy"};
      Console.WriteLine("nItem to classify: ");
      Console.WriteLine("baker  hazel  italy");

      for (int i = 0; i < N; ++i) {   // compute joint counts
        int y = int.Parse(data[i][nx]);  // get the class as int
        ++yCounts[y];
        for (int j = 0; j < nx; ++j) {
          if (data[i][j] == X[j])
            ++jointCounts[j][y];
        }
      }

      for (int i = 0; i < nx; ++i)  // Laplacian smoothing
        for (int j = 0; j < nc; ++j)
          ++jointCounts[i][j];

      Console.WriteLine("nJoint counts (smoothed): ");
      Console.WriteLine("0 1 2 ");
      Console.WriteLine("------");
      ShowMatrix(jointCounts);

      Console.WriteLine("nClass counts (raw): ");
      ShowVector(yCounts);

      // compute evidence terms
      double[] eTerms = new double[nc];
      for (int k = 0; k < nc; ++k)
      {
        double v = 1.0;  // direct approach
        for (int j = 0; j < nx; ++j)
          v *= (jointCounts[j][k] * 1.0) / (yCounts[k] + nx);
        v *= (yCounts[k] * 1.0) / N;
        eTerms[k] = v;

        //double v = 0.0;  // use logs to avoid underflow
        //for (int j = 0; j < nx; ++j)
        //  v += Math.Log(jointCounts[j][k]) - Math.Log(yCounts[k] + nx);
        //v += Math.Log(yCounts[k]) - Math.Log(N);
        //eTerms[k] = Math.Exp(v);
      }

      Console.WriteLine("nEvidence terms for each class: ");
      ShowVector(eTerms);

      double evidence = 0.0;
      for (int k = 0; k < nc; ++k)
        evidence += eTerms[k];

      double[] probs = new double[nc];
      for (int k = 0; k < nc; ++k)
        probs[k] = eTerms[k] / evidence;

      Console.WriteLine("nPseudo-probabilities each class: ");
      ShowVector(probs);

      Console.WriteLine("nEnd naive Bayes demo ");
      Console.ReadLine();
    } // Main

    static void ShowMatrix(int[][] m)
    {
      int r = m.Length; int c = m[0].Length;
      for (int i = 0; i < r; ++i)  {
        for (int j = 0; j < c; ++j)  {
          Console.Write(m[i][j] + " ");
        }
        Console.WriteLine("");
      }
    }

    static void ShowVector(int[] v)
    {
      for (int i = 0; i < v.Length; ++i)
        Console.Write(v[i] + "  ");
      Console.WriteLine("");
    }

    static void ShowVector(double[] v)
    {
      for (int i = 0; i < v.Length; ++i)
        Console.Write(v[i].ToString("F4") + "  ");
      Console.WriteLine("");
    }

    static string[][] GetData()
    {
      string[][] m = new string[40][];  // 40 rows
      m[0] = new string[] { "actor", "green", "korea", "1" };
      m[1] = new string[] { "baker", "green", "italy", "0" };
      m[2] = new string[] { "diver", "hazel", "japan", "0" };
      m[3] = new string[] { "diver", "green", "japan", "1" };
      m[4] = new string[] { "clerk", "hazel", "japan", "2" };
      m[5] = new string[] { "actor", "green", "japan", "1" };
      m[6] = new string[] { "actor", "green", "japan", "0" };
      m[7] = new string[] { "clerk", "green", "italy", "1" };
      m[8] = new string[] { "clerk", "green", "italy", "2" };
      m[9] = new string[] { "diver", "green", "japan", "1" };
      m[10] = new string[] { "diver", "green", "japan", "0" };
      m[11] = new string[] { "diver", "green", "japan", "1" };
      m[12] = new string[] { "diver", "green", "japan", "2" };
      m[13] = new string[] { "clerk", "green", "italy", "1" };
      m[14] = new string[] { "diver", "green", "japan", "1" };
      m[15] = new string[] { "diver", "hazel", "japan", "0" };
      m[16] = new string[] { "clerk", "green", "korea", "1" };
      m[17] = new string[] { "baker", "green", "japan", "0" };
      m[18] = new string[] { "actor", "green", "italy", "1" };
      m[19] = new string[] { "actor", "green", "italy", "1" };
      m[20] = new string[] { "diver", "green", "korea", "0" };
      m[21] = new string[] { "baker", "green", "japan", "2" };
      m[22] = new string[] { "diver", "green", "japan", "0" };
      m[23] = new string[] { "baker", "green", "korea", "0" };
      m[24] = new string[] { "diver", "green", "japan", "0" };
      m[25] = new string[] { "actor", "hazel", "italy", "1" };
      m[26] = new string[] { "diver", "hazel", "japan", "0" };
      m[27] = new string[] { "diver", "green", "japan", "2" };
      m[28] = new string[] { "diver", "green", "japan", "0" };
      m[29] = new string[] { "clerk", "hazel", "japan", "2" };
      m[30] = new string[] { "diver", "green", "korea", "0" };
      m[31] = new string[] { "diver", "hazel", "korea", "0" };
      m[32] = new string[] { "diver", "green", "japan", "0" };
      m[33] = new string[] { "diver", "green", "japan", "2" };
      m[34] = new string[] { "diver", "hazel", "japan", "0" };
      m[35] = new string[] { "actor", "hazel", "japan", "1" };
      m[36] = new string[] { "actor", "green", "japan", "0" };
      m[37] = new string[] { "actor", "green", "japan", "1" };
      m[38] = new string[] { "diver", "green", "japan", "0" };
      m[39] = new string[] { "baker", "green", "japan", "0" };
      return m;
    } // GetData()

  } // Program
} // ns

The demo program hard-codes the data into a program-defined GetData() function. The data is returned as an array-of-arrays style matrix where each cell contains a string value. In a non-demo scenario, you might want to store data in a text file and write a helper function to read the data into a string of arrays of arrays.[ ][ ] matrix.

All the control logic is in the Main() method. Key data structures are an int array of arrays style[ ][ ] array to hold the joint accounts and an int[ ] vector to hold class counts:

int nx = 3;  // number predictors (job, eye, country)
int nc = 3;  // number classes (0, 1, 2)
int N = 40;  // number data items

int[][] jointCounts = new int[nx][];
for (int i = 0; i < nx; ++i)
  jointCounts[i] = new int[nc];
int[] yCounts = new int[nc];

The raw number of classes and the raw number of joints are calculated as follows:

string[] X = new string[] { "baker", "hazel", "italy"};
for (int i = 0; i < N; ++i) {   // compute joint counts
  int y = int.Parse(data[i][nx]);  // get the class as int
  ++yCounts[y];
  for (int j = 0; j < nx; ++j) {
    if (data[i][j] == X[j])
      ++jointCounts[j][y];
  }
}

The code iterates through the data matrix row by row. The row class label is extracted as an integer from the last row value at index [nx]. The class is used to increment the yCounts vector. Then the code loops through each predictor value and if the predictor value in the data array matches the predictor value in the item to be predicted, the corresponding entry in the jointCount array is incremented. After all the joint count values ​​have been calculated, the demo code loops through the matrix and adds 1 to each count so that there are no 0 values.

]]>
Oracle Cloud Functions Now Supports C# — Visual Studio Magazine https://cwinapp.com/oracle-cloud-functions-now-supports-c-visual-studio-magazine/ Fri, 22 Apr 2022 20:33:42 +0000 https://cwinapp.com/oracle-cloud-functions-now-supports-c-visual-studio-magazine/ News Oracle Cloud Functions now supports C# C# coders can now use the Functions service in Oracle Cloud to create and deploy functions typically used in serverless and event-driven computing. Similar to Azure Functions, Google Cloud Functions, and AWS Lambda, Oracle Cloud Functions is a serverless platform that allows developers to build, run, and scale […]]]>

News

Oracle Cloud Functions now supports C#

C# coders can now use the Functions service in Oracle Cloud to create and deploy functions typically used in serverless and event-driven computing.

Similar to Azure Functions, Google Cloud Functions, and AWS Lambda, Oracle Cloud Functions is a serverless platform that allows developers to build, run, and scale applications without managing any infrastructure.

Now C# coders who, for whatever reason, don’t want to work with one of the “Big 3” vendors, have a new option in Oracle Cloud – sometimes ranked among the top five cloud computing platforms.

Oracle this week announced the new support, saying, “A new Functions Development Kit (FDK) is available for C# (.NET 3.1).”

We assume that Oracle, not being fully immersed in the Microsoft-centric development space, meant .NET Core 3.1 and not the older .NET Framework 3.1 circa 2012. Currently, of course, .NET 7 is in the works for a 2022 launch, after .NET 6 and .NET 5, which came after .NET Core 3.1.

Languages ​​Supported by Oracle Functions
[Click on image for larger view.] Languages ​​Supported by Oracle Functions (source: oracle).

Although Oracle Cloud Functions language support is running a few versions behind for C#/.NET, it is more up to date for other languages ​​as shown in the graphic above.

About the Author


David Ramel is an editor and writer for Converge360.



]]>
‘Alternative to Blazor’ Wisej 3 Ships — Visual Studio Magazine https://cwinapp.com/alternative-to-blazor-wisej-3-ships-visual-studio-magazine/ Thu, 21 Apr 2022 17:17:04 +0000 https://cwinapp.com/alternative-to-blazor-wisej-3-ships-visual-studio-magazine/ News ‘Alternative to Blazor’ Wisej 3 Ships Wisej 3 was shipped, described as an “alternative for Blazor developers” to build enterprise-level ASP.NET web applications with specialized Visual Studio templates. Running on .NET 6 on Windows, Linux and macOS, the third edition of the framework from IceTeaGroup, a global development consulting firm, is available in a […]]]>

News

‘Alternative to Blazor’ Wisej 3 Ships

Wisej 3 was shipped, described as an “alternative for Blazor developers” to build enterprise-level ASP.NET web applications with specialized Visual Studio templates.

Running on .NET 6 on Windows, Linux and macOS, the third edition of the framework from IceTeaGroup, a global development consulting firm, is available in a free community version for small businesses and independent developers, as well as paid licenses and a free trial.

“IceTeaGroup provides a solid, proven alternative for Blazor developers looking to build complex, real-world, enterprise-level web applications,” the company said in an April 20 press release. “Wisej’s pixel-perfect designer helps developers create complex views and integrate features like drag-and-drop, customizable themes, complex layouts, modal workflows, and more.”

The offering includes a suite of over 100 commands, as well as command sets for popular third-party offerings from Syncfusion, DevExpress, Telerik, and others.

Smart controls
[Click on image for larger view.] Smart controls (source: Ice Tea Group).

Although it primarily targets web applications, integrations for mobile development are also provided. These web applications, however, are no ordinary websites, as Wisej is described as a highly specialized framework for real-time web applications. One of the framework’s main selling points is that developers don’t have to dive deep into HTML, CSS or JavaScript and struggle with state management, backend services, callbacks, Ajax panels, synchronization, DOM, security, authentication, concurrency, etc. Microsoft’s Blazor, to which the product is compared, is known for providing a C#-based experience instead of primarily using JavaScript code in web development projects.

A 2020 ProjectCode The article written by Microsoft’s Jeremy Likness states “Wisej is a powerful platform that takes the nuances out of client/server interactions while embracing everything the web has to offer, including HTML5-based third-party solutions. is the perfect tool for creating enterprise web applications.”

IceTeaGroup provides template downloads for use in Visual Studio 2022 and 2019 editions. SharpDevelop, a discontinued, free and lightweight alternative to Visual Studio, can also be used.

The main highlight of the v3 version is that it is the first to support both the old .NET Framework (v4.8) and .NET Core (which became .NET 6, .NET 7, etc. .) while running on all three major OSes. So while much of the development effort for Wisej 3 was to split code between .NET Core and .NET Framework and replace all ASP.NET code with ASP.NET Core code, some new features have also been added. Some of these include download callbacks, auto-layout functionality, new interfaces, and new experimental functionality to extend the current data binding model to make it compatible with the command approach found in . NET MAUI (evolution of Xamarin.Forms with added desktop support).

Going forward, the company said it will tackle the development of embedded systems, planning a 2022 release optimized for devices with processor and memory constraints, typically used in the Internet of Things (IoT) , programmable logic controllers (PLC), home automation and similar projects.

After that, a Wisej designer for .NET 6 is available, which the company says will pave the way for Wisej to become platform independent at design time. Currently, the designer does not work for .NET 6 single-target projects because it is tied to the old .NET Framework. These plans are still in their infancy, so nothing is guaranteed.

About the Author


David Ramel is an editor and writer for Converge360.



]]>
Microsoft Asks for Votes on Visual Studio 2022 for Mac Issues — Visual Studio Magazine https://cwinapp.com/microsoft-asks-for-votes-on-visual-studio-2022-for-mac-issues-visual-studio-magazine/ Mon, 18 Apr 2022 15:49:54 +0000 https://cwinapp.com/microsoft-asks-for-votes-on-visual-studio-2022-for-mac-issues-visual-studio-magazine/ News Microsoft asks for votes on Visual Studio 2022 for Mac issues Microsoft’s development team for Visual Studio 2022 for Mac is seeking more developer feedback on key user issues as it refines the IDE, which just shipped in Preview 9. As the team continues its efforts to move the UI from the IDE to […]]]>

News

Microsoft asks for votes on Visual Studio 2022 for Mac issues

Microsoft’s development team for Visual Studio 2022 for Mac is seeking more developer feedback on key user issues as it refines the IDE, which just shipped in Preview 9.

As the team continues its efforts to move the UI from the IDE to fully native code and migrate to .NET 6 (for native support for Apple’s M1 arm64 processor), it has resolved many already reported issues and requested more feedback in the form of votes. on existing questions in addition to filing new questions.

“Another way to help us focus on the issues that matter most is to search for existing issues on the Developer Community site and add your vote to the items that matter to you,” said Jordan Matthiesen, Senior Program Manager, in an April 12 blog post. “When you click on an issue that has already been reported, you can upvote or upvote the items using the up and down arrows next to the vote tally.

“When reviewing reported issues on the latest builds, we always start by reviewing the items with the most votes to get an idea of ​​the level of developer impact. If you vote for an issue, please add a comment with additional steps to reproduce the issue. You can also privately upload your log files to help us troubleshoot.”

Debugging a client-side Blazor app in VS 2022 for Mac
[Click on image for larger view.] Debugging a client-side Blazor app in VS 2022 for Mac (source: Microsoft).

Regarding the issues fixed in Preview 9, he pointed out:

  • Can’t move files in VS 2022 for Mac: “I’m trying to click and drag a file to a folder in Solution Explorer, but the file doesn’t move to the folder when I drop it. It doesn’t doesn’t seem to be a way to move the files around in Visual Studio.”
  • IDE horizontal and vertical splitters become unresponsive: “1) open visual sudio for mac (17, 8230). 2) open a solution. 3) grab the vertical splitter from the solution panel and drag it from back and forth. 4) notice that the drag ends (while dragging) and the panel becomes unresponsive. 5) resize the app window to access the splitters again. 6) repeat with the horizontal splitter of the “lower” panel 7) observe the same effect as note in 4 8) do step 5 again. an unresponsive separator is a separator that the IDE will not allow you to ‘grab’ from equipment on which this has been observed: intel macbook pro, 2019, i9 2.3ghz, 32gb ram, 2to ssd, macOS 12.3.1″
  • Unable to debug unit tests in Visual Studio 2022 Mac Preview: “Running on a Mac Mini M1 (macOS Monterey v12.1) Visual studio 17.07.0 Preview Build 6509

    “I use XUnit for my unit tests. I can run unit tests with no problem, but if I try to debug I get the following in the Output view of the application: Unable to connect to CoreCLR. Error unknown: 0x80131c3c

    “I am able to debug applications as usual.

  • XAML files refuse to save: “After working on a Xamarin Forms project for a while, Visual Studio for Mac sometimes refuses to save changes to a XAML file I opened. I tried to save from the File menu, using CMD+S.

    “The only way around this problem is to copy the contents in memory to the clipboard, close then reopen the file, paste it, then save it. But sometimes even that doesn’t work. I have to close VS completely to get back to work.

    “I’m not sure how exactly to reproduce this issue, but it seems to occur when I move or rename XAML files (along with their C# twins). I do this quite frequently when working on new projects.

    It’s one of the many issues that brings my productivity to a screeching halt.

  • Unable to load Apple certificates: “[severity:I’m unable to use this version]
    Unable to download signing certificates from Apple Connect. Tested with 2 different developer accounts with VS 2022 and VS 2019. I get the error below: There was an error loading your certificates: This request is firbiddn for security reasons: Error authentication. Xcode 7.3 or later is required to continue developing with your Apple ID.

The Preview 9 release notes provide more details on all of the above, as well as other tweaks affecting Azure Functions v3, the Git Changes window, and more.

About the Author


David Ramel is an editor and writer for Converge360.



]]>