I just published my last article for 2020 (what a year!). It is about a feature I will probably have to implement early next year on one of the project I am working on.
It is a good practice to ensure that a user gets authenticated before accessing critical feature of your applications.
I have always maintained a table with users and their passwords in a database but with users getting too many passwords to remember, you can now allow them to use the very same password they use to login their corporate computer if you are using an Active Directory account.
It is amazingly easy for a .Net application running on a computer that can access the AD (useless on a laptop not connected to anything!) to validate the credentials of a user.
You can also check the groups to which this user belongs if you want to build your security based on these groups (which I am not a big fan because it is not very flexible).
You can read the full article from https://www.emoreau.com/Entries/Articles/2020/12/Authenticate-and-Authorize-users-against-the-AD-from-a-Net-application.aspx.
I just published a new article. Last week, I was executing a PowerShell script from a .Net application. This is something I already wrote about back in June 2018.
I still use something like this in my apps. But this time, I want to be able to run a script that is persisted on disk and, even more important, to be able to get the exit code of my script into my .Net application.
Of course PowerShell has the Exit statement but the code is not easily read by a .Net application.
You can read the full article from https://www.emoreau.com/Entries/Articles/2020/11/Getting-an-exit-Code-returned-by-a-PowerShell-script-from-Net-app.aspx.
For quite some time now (I should say many years), I had a very simple task on my TODO list (mine is particularly long!).
This little task was simply: In Visual Studio, how to search for a word which is not on a commented line?
That would have been nice if the VS IDE would offer that option built-in, but it is sadly not! Another useful option would be to colorize the search results exactly like the code window does.
This morning, I was working in a new project for a new client and find they are not deleting lines of code very often, they are most of the time commenting out the code (even if the code hosted in TFS). I was searching for a word and the Find in files feature (CTRL-SHIFT-F) returned literally many hundreds of rows, most of them being commented out. It was nearly impossible to find out the line of codes (about 20) in this non-ending results.
I opened a browser and quickly found an old solution on stack overflow that is working great. The trick is to use a regular expression in the “Find what” textbox and to check the “Use Regular Expressions” under “Find options”. The very same trick also works for the regular search feature (CTRL-F).
The other nice thing about this trick is that using the same idea (with slight difference in syntax), it works in VB.Net, C#, and even in SSMS.
The regular expression to use are (depending on language and/or IDE):
VB.Net^(?![ \t]*').*YourSearchTermC#^(?![ \t]*//).* YourSearchTermSQL^(?![ \t]*--).*YourSearchTerm
I know, there are more ways to comment out code (like /* … */) for which this trick won’t work. But at least for today since I don’t have that kind in the code I am looking at, I will stop there. If you find a better solution, let me know!
Lately I had serious issues. One of my solutions was refusing to compile after I upgraded one of the libraries I am using to its latest version. The compiler was complaining about conflicting references. It was not easy to find since my solution contains 28 projects and the error message returned by the compiler was not explicit on which of the many components was throwing the issue nor for which project.
I needed to find a solution!
This is what you can read from https://www.emoreau.com/Entries/Articles/2020/10/Finding-conflicting-references-in-your-solution.aspx.
I have a new need to fulfill. I need to merge a bunch of PDF files into a single one.
Of course I could have purchased the tool I recommend to all my clients (Foxit PhantomPDF but there is no fun for me in there)!
I decided to spend a part of my Labor Day holiday to create my own tool instead and decided to share a good part of it with you!
This is the article I have for you this month that you can read from https://www.emoreau.com/Entries/Articles/2020/09/Merging-PDFs-documents-from-a-Net-application.aspx.
I just published a new article on a prerelease control that you can use in your .Net desktop applications.
As you have surely heard, Internet Explorer will stopped being supported in August 2021. That means that you should really stop using it as it will not be patched anymore and wide open to problems.
Back in April 2007, I wrote an article about integrating the WebBrowser control in your application. This control is using Internet Explorer as its engine. This means that a replacement needs to be found.
Luckily, Microsoft just released a preview control which is based on the latest Edge-Chromium and we can use this control in a .Net application. This control is called the WebView2 (because there was a former WebView control that could not be used from .Net).
Why would one need such a control in a desktop application? I hope that nobody is thinking about creating a new web browser today! Maybe you have some webpage that you would like to display? Or maybe a PDF? This control is extremely useful even in a desktop application.
You can read the full article from https://www.emoreau.com/Entries/Articles/2020/08/-Using-the-WebView2-control-in-a-Net-application.aspx.
I just published my latest article.
Lately, I was trying to use the Edit-And-Continue feature of Visual Studio 2019 and remembered that this feature has not been working for me on 2 different computers but never had the chance to dig to find the root cause. I was able to edit my code, but the modifications were not recompiled on the fly and considered until I stopped the debugging session and start the debugging all over again. Not really the spirit of that feature and counter-productive! Now that I have some time, I went the extra mile and found the culprit: PostSharp.
In this article, I will not bash on PostSharp. I still think that it is an unbelievably valuable tool for some projects but maybe not all of them as the Edit-And-Continue feature is too important. I will show you how I replaced the cursor aspect (easily implemented using an attribute through Aspect Oriented Programming) with code.
You can read this one from https://www.emoreau.com/Entries/Articles/2020/07/WaitCursorHourGlass-cursor-for-Net-Windows-Forms-project.aspx.
In the last few weeks, I needed a feature that would compare the text of two side-by-side RichTextBox controls. I wanted the differences to be highlighted. I also wanted the RichTextBox controls to scroll in sync to ease the comparison.
I was not really surprised to find snippets of code here and there doing all that but nothing combining the 3 requirements all together.
The most complex task of these 3 is that text comparison. I found a free library dedicated for that task. This library called “Diff Match Patch” is made available by Google on their github page.
Figure 1: The demo application in action
You can read the full article from https://www.emoreau.com/Entries/Articles/2020/06/Comparing-Text-to-highlight-differences-in-Net.aspx.
I was updating a library lately to their latest bits (PostSharp Cache if you are curious) and this new version started to return compilation warnings for code that was compiling for years. But when you really look at it, it totally makes sense. In short, I was using cache on a method returning an integer (a function) but that was also returning one of the arguments ByRef (ref in C#).
Time to find a workaround because I do not want to go back to a previous version, and I want my code to compile.
You can read the full article from https://www.emoreau.com/Entries/Articles/2020/05/Using-ValueTuple-in-Net.aspx.
Nice finding over the weekend.
I did not try it (as I use a 3rd party component) but one that might be worth testing in the feature: https://discoverdot.net/projects/ribbon-winforms