Category Archives: .NET

Microsoft .NET issues and solutions

access_token unavailable?

This call returns null for you (so your app cannot use Microsoft Graph APIs)? await HttpContext.GetTokenAsync(“access_token”); … and you’ve tried already most of the things found on StackOverflow? options.ResponseType = OpenIdConnectResponseType.IdTokenToken; options.SaveTokens = true; Maybe you’ve just missed to check … Continue reading

Posted in ASP .NET | Tagged , , | Leave a comment

SHA*Managed + FIPS = hate šŸ’”

If you write .NET software that cryptographically validates signatures, e.g. you verify a customer’s license at runtime, be aware of issues when the check runs on US government-certifiedĀ FIPS-enabled computers. Chances are that you run Sha256Managed algorithm for computing a hash … Continue reading

Posted in .NET | Tagged , , , , | Leave a comment

Indexing for IndexOf

Today, a short one. But it gave me some not-so-short trouble recently. Do you happen to use or inherit Collection or any of its subclasses (e.g. ObservableCollection)? Make sure you don’t call its IndexOf method too much. As indicated on … Continue reading

Posted in .NET | Tagged , , , | Leave a comment

Hacking the WPF DataGrid: properly hiding rows for unwanted items

If you even need to hide some DataGridRow elements displayed in a WPF DataGrid please remember these few things – it took me some time to realize and solve them all: If you plan to just set DataGridRow.Visibility to Collapsed … Continue reading

Posted in WPF | Tagged , , , , , | Leave a comment

Generically handling multi-threading exceptions in WPF

You have a WPF app and you just want to show a message whenever an exception is raised an not handled anywhere else in code. The first try is surely this: This works fine, as long as the exception isn’t … Continue reading

Posted in .NET, C#, WPF | Tagged , , , | Leave a comment

Moq: how to VerifySet with an object that respects a condition

Sometimes you want to test that a service method sets up the correct object on another (singleton) service.Ā For example, that an authentication service sets up a user object with the correct username to the app’s user context. With Moq you … Continue reading

Posted in C# | Tagged , , , | Leave a comment

ToolTipService.ShowDuration within a specific WPF view

ToolTipService.ShowDuration attached property isn’t inherited from parent to child elements within the WPF visual tree, and therefore values for this property – to produce runtime effects – must be set on all the elements that have ToolTips for which we’d … Continue reading

Posted in WPF | Tagged , , , | Comments Off on ToolTipService.ShowDuration within a specific WPF view

Mocking “this”

Let’s assume we have a simple service that is also using an inner service, providing a few operations as follows: publicĀ interfaceĀ IService { Ā Ā Ā Ā stringĀ A(); Ā Ā Ā Ā stringĀ B(); Ā Ā Ā Ā stringĀ C(); } publicĀ classĀ ServiceĀ :Ā IService { Ā Ā Ā Ā privateĀ readonlyĀ IInnerServiceĀ innerService; Ā Ā Ā Ā publicĀ Service(IInnerServiceĀ innerService) Ā Ā Ā Ā { Ā Ā Ā Ā Ā Ā Ā Ā this.innerServiceĀ =Ā innerService; Ā Ā Ā Ā } Ā Ā Ā Ā publicĀ stringĀ A() Ā Ā Ā Ā { Ā Ā Ā Ā Ā Ā Ā Ā returnĀ “A”; Ā Ā Ā Ā } Ā Ā Ā Ā publicĀ stringĀ B() Ā Ā Ā Ā { Ā Ā Ā Ā Ā Ā Ā Ā returnĀ b(); … Continue reading

Posted in .NET, C# | Tagged , , , | Leave a comment

Invariant string interpolation

I’m sure you like C# string interpolation support ($”{…}”): var start = DateTime.Now; var end = start.AddDays(7); string weekIntervalText = $”{start}-{end}”; But you also know that this uses the current thread’s culture to format the string, so you think “Oh, … Continue reading

Posted in C# | Tagged , , , , | Leave a comment

Attached properties and the WPF DataGrid

WPF attached properties. They look like such a difficult topic. But you only need to see a single example in action to understand their true potential: as long as your objects inherit from DependencyObject you can add as many extra … Continue reading

Posted in WPF | Tagged , , , , | Leave a comment