Pull to refresh
103.77

.NET *

A hub about .NET

Show first
Rating limit
Level of difficulty

Scanning the code of Orchard CMS for Bugs

Reading time12 min
Views988

Picture 6

This article reviews the results of a second check of the Orchard project with the PVS-Studio static analyzer. Orchard is an open-source content manager system delivered as part of the ASP.NET Open Source Gallery under the non-profit Outercurve Foundation. Today's check is especially interesting because both the project and the analyzer have come a long way since the first check, and this time we'll be looking at new diagnostic messages and some nice bugs.
Read more →
Total votes 34: ↑33 and ↓1+32
Comments0

Announcing Support for Native Editing of Jupyter Notebooks in VS Code

Reading time3 min
Views1.7K
With October release of the Python extension, we’re excited to announce the support of native editing of Jupyter notebooks inside Visual Studio Code! You can now directly edit .ipynb files and get the interactivity of Jupyter notebooks with all of the power of VS Code.

You can manage source control, open multiple files, and leverage productivity features like IntelliSense, Git integration, and multi-file management, offering a brand-new way for data scientists and developers to experiment and work with data efficiently. You can try out this experience today by downloading the latest version of the Python extension and creating/opening a Jupyter Notebook inside VS Code.



Since the initial release of our data science experience in VS Code, one of the top features that users have requested has been a more notebook-like layout to edit their Jupyter notebooks inside VS Code. In the rest of this post we’ll take a look at the new capabilities this offers.
Read more →
Total votes 9: ↑9 and ↓0+9
Comments0

Visual Studio for Mac: Top Features of the New Editor

Reading time4 min
Views1K
Over the past year, the Visual Studio for Mac team updated the editors within the IDE to be faster, more fluent and more productive. We did this by building a macOS-native editor interface on top of the same editor backend as Visual Studio on Windows. In version 8.1 we introduced the new C# editor. This was followed by the new XAML editor in 8.2. And most recently, we updated our web languages to utilize the new editors in version 8.3, completing the process we set out to do a year ago. To celebrate this accomplishment, I wanted to share a bit of detail regarding the design and implementation of the new editors along with my five favorite new features in the Visual Studio for Mac code editors.

At the core of the updated editors within Visual Studio for Mac is the shared language service with Visual Studio on Windows. What this means is that the same backend that powers the Windows version of Visual Studio now powers the macOS version as well. This includes IntelliSense, Roslyn, text logic, and all the language services behind the scenes. The only portion not shared between Windows and macOS is the UI layer, which stays native for each platform. In the case of macOS, that means using macOS frameworks like Cocoa and CoreText to power the UI experience. By using a native UI, while also being able to utilize support for native input methods as well as support for right-to-left languages, font ligatures and other advanced graphical features.

Read more →
Total votes 3: ↑3 and ↓0+3
Comments0

Regular Avalonia

Reading time4 min
Views8K
Sometimes we don’t understand how the regular expression that we have composed works and want to check. There are many applications like regex101.com or vs code. I wanted to add one more to this list.

In this article we will see how you can wrap Regex in cross-platform graphics and create a simple application for testing regular expressions.


Read more →
Total votes 14: ↑13 and ↓1+12
Comments0

What's new in ML.NET and Model Builder

Reading time2 min
Views977
We are excited to announce updates to Model Builder and improvements in ML.NET. You can learn more in the «What’s new in ML.NET?.» session at .NET Conf.

ML.NET is an open-source and cross-platform machine learning framework (Windows, Linux, macOS) for .NET developers.

ML.NET offers Model Builder (a simple UI tool) and CLI to make it super easy to build custom ML Models using AutoML.

Using ML.NET, developers can leverage their existing tools and skillsets to develop and infuse custom AI into their applications by creating custom machine learning models for common scenarios like Sentiment Analysis, Recommendation, Image Classification and more!..

Read more →
Total votes 4: ↑4 and ↓0+4
Comments0

Enumerable: How to yield a business value

Reading time6 min
Views2.1K
This article is a brief explanation about how using a common language keywords might have an influence on the budget of IT-infrastructure of a project or help to achieve some limitations/restrictions of hosting infrastructure and, moreover, will be a good sing of the quality and maturity of the source code.
Read more →
Total votes 12: ↑11 and ↓1+10
Comments0

The best is the enemy of the good

Reading time11 min
Views1.2K

Picture 6

This article is the story how we once decided to improve our internal SelfTester tool that we apply to test the quality of the PVS-Studio analyzer. The improvement was simple and seemed to be useful, but got us into some troubles. Later it turned out that we'd better gave up the idea.
Read more →
Total votes 43: ↑41 and ↓2+39
Comments0

System.IO.Pipelines — a little-known tool for lovers of high performance

Reading time14 min
Views30K
Hello reader. Quite a lot of time has passed since the release of .NET Core 2.1. And such cool innovations as Span and Memory are already widely known, you can read, see and hear a lot about them. However, unfortunately, library called System.IO.Pipeslines did not receive the same attention. Almost everything there is on this topic is the only post that have been translated and copied on many resources. There should be more information about that technology to look on it from different angles.


Read more →
Total votes 8: ↑8 and ↓0+8
Comments0

Checking the .NET Core Libraries Source Code by the PVS-Studio Static Analyzer

Reading time59 min
Views1.7K

Picture 19

.NET Core libraries is one of the most popular C# projects on GitHub. It's hardly a surprise, since it's widely known and used. Owing to this, an attempt to reveal the dark corners of the source code is becoming more captivating. So this is what we'll try to do with the help of the PVS-Studio static analyzer. What do you think – will we eventually find something interesting?
Read more →
Total votes 28: ↑25 and ↓3+22
Comments1

The story of how PVS-Studio found an error in the library used in… PVS-Studio

Reading time3 min
Views1.2K

Picture 1

This is a short story about how PVS-Studio helped us find an error in the source code of the library used in PVS-Studio. And it was not a theoretical error but an actual one — the error appeared in practice when using the library in the analyzer.
Read more →
Total votes 27: ↑24 and ↓3+21
Comments0

WinForms: Errors, Holmes

Reading time17 min
Views1K

Picture 5

We like to search for errors in Microsoft projects. Why? It's simple: their projects are usually easy to check (you can work in Visual Studio environment for which PVS-Studio has a convenient plugin) and they contain few errors. That's why the usual work algorithm is as follows: find and download an open source project from MS; check it; choose interesting errors; make sure there are few of them; write an article without forgetting to praise the developers. Great! Win-win-win: it took a little time, the bosses are glad to see new materials in the blog, and karma is fine. But this time «something went wrong». Let's see what we have found in the source code of Windows Forms and whether we should speak highly of Microsoft this time.
Read more →
Total votes 28: ↑26 and ↓2+24
Comments0

Saving Routing State to the Disk in a Cross-Platform .NET Core GUI App with ReactiveUI and Avalonia

Reading time17 min
Views7K

image


User interfaces of modern enterprise applications are quite complex. You, as a developer, often need to implement in-app navigation, validate user input, show or hide screens based on user preferences. For better UX, your app should be capable of saving state to the disk when the app is suspending and of restoring state when the app is resuming.


ReactiveUI provides facilities allowing you to persist application state by serializing the view model tree when the app is shutting down or suspending. Suspension events vary per platform. ReactiveUI uses the Exit event for WPF, ActivityPaused for Xamarin.Android, DidEnterBackground for Xamarin.iOS, OnLaunched for UWP.


In this tutorial we are going to build a sample application which demonstrates the use of the ReactiveUI Suspension feature with Avalonia — a cross-platform .NET Core XAML-based GUI framework. You are expected to be familiar with the MVVM pattern and with reactive extensions before reading this note. Steps described in the tutorial should work if you are using Windows 10 or Ubuntu 18 and have .NET Core SDK installed. Let's get started! Source code of the app described in this tutorial is available on GitHub.

Read more →
Total votes 16: ↑16 and ↓0+16
Comments0

«Reader» monad through async/await in C#

Reading time8 min
Views6.5K

In my previous article I described how to achieve the "Maybe" monad behavior using async/await operators. This time I am going to show how to implement another popular design pattern "Reader Monad" using the same techniques.


That pattern allows implicit passing some context into some function without using function parameters or shared global objects and it can be considered as yet another way to implement dependency injection. For example:


class Config { public string Template; }

public static async Task Main()
{
    Console.WriteLine(await GreetGuys().Apply(new Config {Template = "Hi, {0}!"}));
    //(Hi, John!, Hi, Jose!)

    Console.WriteLine(await GreetGuys().Apply(new Config {Template = "¡Hola, {0}!" }));
    //(¡Hola, John!, ¡Hola, Jose!)
}

//These functions do not have any link to any instance of the Config class.
public static async Reader<(string gJohn, string gJose)> GreetGuys() 
    => (await Greet("John"), await Greet("Jose"));

static async Reader<string> Greet(string name) 
    => string.Format(await ExtractTemplate(), name);

static async Reader<string> ExtractTemplate() 
    => await Reader<string>.Read<Config>(c => c.Template);
Read more →
Total votes 11: ↑11 and ↓0+11
Comments2

.NET – Tools for working with multithreading and asynchrony – Part 2

Reading time13 min
Views7.3K
I have originally posted this article in CodingSight blog.
It's also available in Russian here.


This article comprises the second part of my speech at the multithreading meetup. You can have a look at the first part here and here. In the first part, I focused on the basic set of tools used to start a thread or a Task, the ways to track their state, and some additional neat things such as PLinq. In this part, I will fix on the issues you may encounter in a multi-threaded environment and some of the ways to resolve them.

Contents



Read more →
Total votes 7: ↑6 and ↓1+5
Comments1

“Maybe” monad through async/await in C# (No Tasks!)

Reading time13 min
Views21K


Generalized async return types — it is a new C#7 feature that allows using not only Task as a return type of async methods but also other types (classes or structures) that satisfy some specific requirements.


At the same time, async/await is a way to call a set of "continuation" functions inside some context which is an essence of another design pattern — Monad. So, can we use async/await to write a code which will behave in the same way like if we used monads? It turns out that — yes (with some reservations). For example, the code below is compilable and working:


async Task Main()
{
  foreach (var s in new[] { "1,2", "3,7,1", null, "1" })
  {
      var res = await Sum(s).GetMaybeResult();
      Console.WriteLine(res.IsNothing ? "Nothing" : res.GetValue().ToString());
  }
  // 3, 11, Nothing, Nothing
}

async Maybe<int> Sum(string input)
{
    var args = await Split(input);//No result checking
    var result = 0;
    foreach (var arg in args)
        result += await Parse(arg);//No result checking
    return result;
}

Maybe<string[]> Split(string str)
{
  var parts = str?.Split(',').Where(s=>!string.IsNullOrWhiteSpace(s)).ToArray();
  return parts == null || parts.Length < 2 ? Maybe<string[]>.Nothing() : parts;
}

Maybe<int> Parse(string str)
    => int.TryParse(str, out var result) ? result : Maybe<int>.Nothing();

Further, I will explain how the code works...

Read more →
Total votes 12: ↑10 and ↓2+8
Comments1

Write Better Code Faster with Roslyn Analyzers

Reading time3 min
Views4.5K
Roslyn, the .NET compiler platform, helps you catch bugs even before you run your code. One example is Roslyn’s spellcheck analyzer that is built into Visual Studio. Let’s say you are creating a static method and misspelled the word static as statc. You will be able to see this spelling error before you run your code because Roslyn can produce warnings in your code as you type even before you’ve finished the line. In other words, you don’t have to build your code to find out that you made a mistake.



Roslyn analyzers can also surface an automatic code fix through the Visual Studio light bulb icon that allows you to fix your code immediately.

Read more →
Total votes 9: ↑9 and ↓0+9
Comments2

Fighting complexity in software development

Reading time31 min
Views3.3K

What's this about


After working on different projects, I've noticed that every one of them had some common problems, regardless of domain, architecture, code convention and so on. Those problems weren't challenging, just a tedious routine: making sure you didn't miss anything stupid and obvious. Instead of doing this routine on a daily basis I became obsessed with seeking solution: some development approach or code convention or whatever that will help me to design a project in a way that will prevent those problems from happening, so I can focus on interesting stuff. That's the goal of this article: to describe those problems and show you that mix of tools and approaches that I found to solve them.

Read more →
Total votes 21: ↑20 and ↓1+19
Comments2

Authors' contribution