Subscribe: Rick Strahl's Web Log
Added By: Feedage Forager Feedage Grade B rated
Language: English
application  applications  bit  describe  markdown monster  markdown  monster  net core  net  rendering  visual studio  web  wpf 
Rate this Feed
Rate this feedRate this feedRate this feedRate this feedRate this feed
Rate this feed 1 starRate this feed 2 starRate this feed 3 starRate this feed 4 starRate this feed 5 star

Comments (0)

Feed Details and Statistics Feed Statistics
Preview: Rick Strahl's Web Log

Rick Strahl's Web Log

Life, Surf, Code and everything in between


Video Rendering Issues for WPF Windows

Tue, 14 Feb 2017 00:57:23 GMT

Over the last half a year I've had a couple of Github Issues coming into Markdown Monster for some odd startup rendering failures. Markdown Monster would come up with a completely black screen, but underneath it all the application would actually still be live. Now I was never able to reproduce this myself which made this really tricky to track down. Thankfully Tom Robinson posted an issue a few days ago and followed up with a bunch of information that allowed me to track this down eventually using a workaround I'll describe here. Tom posted a screen shot (since I can't dupe it) that demonstrates the black hole of a screen: The Window comes up totally opaquely black, but it's actually ‘live’ in that menus pop up and the window can be moved around the screen. In fact, it's also possible to drag the Window to another screen and depending on which screen it's moved onto the window then starts rendering. According to Tom (and one other report) dragging the Window from an external monitor onto the native laptop monitor always brings the screen back to life. Starting on the laptop monitor as well seems to render right from the start. All of this points at video problems - some weird combination of video card and monitor interaction that's causing the screen to not refresh properly. Easy to call, but not a good explanation to give to a user. Hrrrmph! Video Card Issues This issue is very rare - I got two bugs reported for this over the last half a year - but it's related to specific video hardware and how WPF interacts with it. WPF uses hardware acceleration and DirectX for rendering its UI and if there's an issue with a video driver you can get all sorts of odd issues (and crashes - eek). Both of the cases in question where using nVidia Quadro M200M video cards, so it's likely the issue is related to that particular card/driver combo, although several people have mentioned in the comments that they've seen this behavior with other applications on a few other video cards as well. For both users other applications were also affected. Specifically both users reported problems with the Chrome browser when running in full screen mode with the same behavior described above. There may be other places with WPF based applications where this manifests as well. Note that this probably doesn't affect every WPF application. Markdown Monster uses the MahApps.Metro UI framework which does all sorts of custom window drawing to provide the Metro styling for the application's windows. MahApps is a fairly graphics intensive process that replaces the stock WPF window rendering with custom drawn windows on startup and likely the reason that the video driver issues are kicking in. Standard WPF Windows are less likely to exhibit these problems. Workaround: Disable Hardware Acceleration After a bunch of back and forth on the issue on Github, the eventual solution to fixing the problem for affected machines is to turn off hardware accelerated rendering for the WPF application. I was pointed to this solution by a 3 year old post from Keith Fink of the DSUI team at Microsoft. Towards the end of the article, Keith points out that rendering crashes and failures can often be resolved by forcing the system or application to turn off hardware assisted rendering if it looks like there's a hardware or driver problem. There is a registry key that can be set to a DWORD of 1 to disable hardware rendering at: HKEY_CURRENT_USER\SOFTWARE\Microsoft\Avalon.Graphics\DisableHWAcceleration DWORD But this is a hammer solution, for a problem that might not affect but a few applications. WPF ProcessRenderMode Luckily there's a much better solution for .NET applications via the static System.Windows.InteropRenderOptions.ProcessRenderMode property that can be set at application startup. In Markdown Monster I've added a DisableHardwareAcceleration option to the configuration settings which trigger the following code in application's startup in app.xaml.cs: protected override void OnStartup(StartupEventArgs e) { if (mmApp.Configuration.DisableHardwareAccelera[...]

Creating a portable and embedded Chocolatey Package

Sun, 29 Jan 2017 21:05:40 GMT

Chocolatey is an awesome tool to install software. As a publisher you have a lot of choices of how to create packages and in this post I describe the two packages that I use with Markdown Monster, which is a full downloaded installer package and a fully self contained embedded portable package. Here I cover the basics of Chocolatey package creation and some of the steps required to create a portable package from a full installation and some of the challenges you might run into along the way.(image)

Adding Files to Visual Studio Projects

Wed, 25 Jan 2017 19:35:31 GMT

Visual Studio has a boat load of ways to add new files to a project and various extensions and tools provide even more ways to do the same. Even so the experience to add new files to a project in Visual Studio is one of the most tedious tasks. Here's what bugs me and how I try to work around the verbosity of it all.(image)

New CODE Magazine Article: Getting down to Business with ASP.NET Core

Thu, 12 Jan 2017 20:19:27 GMT

The latest issue of CODE magazine features my `Getting down to Business with ASP.NET` Core article as the cover article. The article focuses on building an ASP.NET Core backend for an Angular 2 front application, covering all aspects of separating business and Web app logic, dealing with EF Core data access in related tables, CORS to be able to run across domains and simple authentication in a client centric REST service application. Check it out.(image)

Faking out the .NET Runtime Version

Tue, 10 Jan 2017 07:04:01 GMT

I've been struggling with DPI Scaling issues in WPF in Markdown Monster and .NET 4.6.2 has a few fixes that address the problems I've been working on. However, requiring 4.6.2 is a problem due to lowish adoption rates and skittishness about installing new versions of .NET. In this post I show a little hack that allows me to compile my app to .NET 4.6.2 but don't require user to have that version installed so those that have it can take advantage of the updates.(image)

Back to Basics: String Interpolation in C#

Tue, 27 Dec 2016 08:12:59 GMT

String Interpolation provides string templating for string literals in C#. Rather than using string.Format you can use string interpolation to produce much more readable code that embeds expression values directly into string literals rather than escaping numeric arguments as you do with string.Format(). In this post I look at how string interpolation works, what the compiler does under the covers and some common use cases where it makes life easier.(image)

Downgrading a .NET Applications from 64 bit to 32 bit for the WebBrowser Control

Fri, 23 Dec 2016 09:14:52 GMT

Recently while working on Markdown Monster I ran into some odd crashes and behaviors when interacting with the Web Browser control in this WPF application. It turns out that some of these inconsistent behaviors are apparently caused by running hte application in 64 bit mode. Switching to 32 bit mode has made the application and Web Browser interaction much more responsive and has stopped the nagging unexplainable crashes. In this post I look at 32 and 64 bit applications in .NET and outline some of the issues I ran into and how I fixed the problem by switching to building a 32 bit app.(image)

Visual Studio Debugging and 64 Bit .NET Applications

Mon, 19 Dec 2016 08:26:59 GMT

Recently while debugging a 64 bit application I found out the hard way that Visual Studio by default will use 32 bit debugging even when running what would otherwise be a 64 bit .NET application. There are a number of options that determine the bitness of your application, but the debugger often behaves differently than your standalone application. In this post I describe, why this might be a problem in some situations and how you can get the debugger to run in 64 bit.(image)

WPF Rendering DUCE.Channel Crashes due to Image Loading

Thu, 15 Dec 2016 09:43:47 GMT

I ran into a nasty WPF rendering bug that affected only a few select machines. Rendering problems in WPF can be terribly difificult to debug because there often is no additional information on what failed and the exceptions that occur are not trappable but fall back to application wide error handling. In this post I describe a specific failure caused by a 'bad' image WPF can't deal with and how I tracked it down and fixed it.(image)

Loading .NET Assemblies out of Seperate Folders

Mon, 12 Dec 2016 09:49:25 GMT

In the process of updating the Addin manager in Markdown Monster I ran into a few snags with loading .NET assemblies out of separate folders. Assembly loading out of non base folders in .NET can be problematic and sure enough I ran into a few issues that took a while to find a work around for. In this post I describe some of the issues of folder based assembly loading and a brute force solution to deal with assembly resolution.(image)

.NET Standard 2.0 - Making Sense of .NET Again

Wed, 23 Nov 2016 09:29:40 GMT

It's taken awhile but it seems Microsoft is finally nailing the message for .NET going forward and .NET Standard with its common API specification is a huge part in making sure that the same base library of .NET is available on all .NET platforms. In this post I look at what .NET Standard is, how it works and what some of the surrounding issues and impacts are for the .NET Eco system.(image)

Introducing Markdown Monster - a new Markdown Editor

Fri, 04 Nov 2016 08:14:57 GMT

I'm happy to announce Version 1.0 of Markdown Monster a Markdown Editor and Weblog Publishing tool for Windows. In this post I give a quick tour of Markdown Monster and provide links to all you need to know to check out this great new Markdown editor.(image)

Windows Update Hell

Thu, 03 Nov 2016 19:26:45 GMT

I've been fighting Windows Update Hell for the last month with failed updates wreaking havoc on my machine. Updates fail to install completely and roll back and then continue to retry each day. Attempts to turn off the particular update now fails as well, so I'm stuck in this groundhog day like loop of pain. This is a cry for help, in hopes somebody has additional ideas on what to try.(image)

C# NumberFormat Sections

Thu, 03 Nov 2016 17:27:56 GMT

In all the years I've been using C#, I've completely missed that the NumberFormat features using .ToString() or string expressions support sections for positive, negative and zero values. In this post I describe the feature and how it works.(image)

Excluding the node_modules Folder in Visual Studio WebSite Projects

Sun, 30 Oct 2016 19:42:40 GMT

If you're working on a client side project that includes an NPM folder with a large number of dependencies and you're using a WebSite Project in Visual Studio, you've probably found that this is a terrible combination out of the box. In this post I describe why this is a problem and how you can work around it with a simple hack.(image)

Automating Installation Builds and Chocolatey Packaging

Wed, 26 Oct 2016 06:08:01 GMT

Having a quick and easy way to build a final deployable applicationsin a few minutes has been a huge motivation for me. I can update code and release a new build as soon as a feature is added or a bug is fixed, and my release cycle is much more frequent than it was before. I used to be much more conservative with releases - if something was broken it'd have to wait. But with an easy release mechanism all of that has changed and I can push new releases out much more frequently and I really like the fact that it works this way. In this post I describe my deployment processing for Markdown Monster for creating an installer, publishing it on my Web site and creating and publishing a Chocolatey package.(image)

Error Handling and ExceptionFilter Dependency Injection for ASP.NET Core APIs

Mon, 17 Oct 2016 06:14:05 GMT

Exception handling in API applications is important as errors - both handled and unhandled - need to be passed to clients in some way to let them display error information. ASP.NET's default error handling doesn't provide for object error results by default, but you can use an ExceptionFilter to intercept exceptions and format them yourself. In this post I look at how to create an API exception filter to create error object responses, and hook up custom logging of those errors to disk.(image)

Dealing with Anti-Virus False Positives

Wed, 05 Oct 2016 20:22:27 GMT

I've been struggling with false positive Anti-Virus warnings for Markdown Monster. In this post I describe what problems I was running into and how eventually managed to get a clean distribution of Markdown Monster out the door.(image)

External Network Access to Kestrel and IIS Express in ASP.NET Core

Thu, 29 Sep 2016 01:19:50 GMT

Recently I needed to connect to my Windows based ASP.NET Core API from my Mac and in order for that to work some configuration settings are necesary so that the ASP.NET applications can serve HTTP content to the external network connection that this entails. In this post I show what you have to do to enable remote connections both using the Kestrel and IIS Express Web servers.(image)

ASP.NET Core and CORS Gotchas

Mon, 26 Sep 2016 21:34:08 GMT

CORS is a requirement for cross domain XHR calls, and when you use Angular 2.0 default dev server and talk to an ASP.NET Core application you'll need to use CORS to get XHR to talk across the domain boundaries. Here's how to set up CORS and how to test it.(image)

Bootstrap Modal Dialog showing under Modal Background

Wed, 14 Sep 2016 17:42:32 GMT

On more than a few occasions I've run into issues with Bootstrap's Modal dialog rendering incorrectly with the dialog showing underneath the overlay. There are a number of ways around this problem, but none of them are universal that depend on how your pages are laid out. It's especially problematic for applications that dynamically render components where there's no good control on where the elements are placed outside of the components DOM containership. In this post, I describe a few of the workarounds and their limitations.(image)

External JavaScript dependencies in Typescript and Angular 2

Mon, 12 Sep 2016 08:21:30 GMT

Angular 2.0 and Typescript make it very easy to import external Typescript classes and references using the module loading functionality built into Typescript (and ES6). However, if you need to work with external libraries that aren't built with Typescript you need to do a little extra work in importing and referencing the external libraries. In this post I show two approaches for importing libraries as modules and dereferencing library globals so that the Typescript compiler is happy.(image)

Capturing Zoom Operations in the WPF Web Browser Control

Tue, 06 Sep 2016 01:55:14 GMT

If you need to capture Zoom operations in the Web Browser control - either to avoid letting hte user zoom or to capture the zoom operation and take action on it - you need to dig into the Web Browser's DOM events to capture the scroll wheel and key events. In this post I describe how you can do just that by looking at an application that captures scrolling and rather than zooming adjusts the font size of the content.(image)

Detecting and Setting Zoom Level in the WPF WebBrowser Control

Mon, 22 Aug 2016 07:25:01 GMT

Zoom level detection in the Web Browser control is a pain and in this article I describe one approach I used to both capture the current Zoom level in order to adjust font sizes, and then also explicitly set the Zoom level in the Web Browser control of a WPF application.(image)