BadImageFormatException for a 64-bit ASP MVC web application

Updated on Thursday, September 30, 2021

System.BadImageFormatException for a 64-bit web application in IIS Express

I converted an ASP.NET MVC web application to 64-bit in order to use dlib and it immediately died with a System.BadImageFormatException (Could not load file or assembly 'xxx' or one of its dependencies. An attempt was made to load a program with an incorrect format.)

Assuming I must have a stray wrong-bittedness something lying around I spent way to long with the assembly binding log viewer (Fuslogvw.exe) trying to figure out what I had messed up. But eventually I realized that Visual Studio was launching a 32-bit version of IIS Express to debug a 64-bit web application.

To fix this select Options from the Tools menu, expand Projects and Solutions, choose Web Projects and then check Use the 64-bit version of IIS Express forĀ  web sites and projects. Problem solved.

(Probably shouldn't have this component in the web application - the plan longer term is to move it to an asynchronous process somewhere instead.)

(Related: Monitor page index status with Google Sheets, Apps Script and the Google Search Console API; Using the Azure Monitor REST API from Google Apps Script; ESRI Shapefile Reader in .NET)

(You might also like: How does Hulu manage to suck so badly and the missing app for cord cutting; Save Mount Davidson; Semi-flooded duck (DUKW) headlight)

(All Code Posts)

Crushing PNGs in .NET

Updated on Thursday, May 13, 2021

Crushing PNGs in .NET

I'm working on page speed and Google PageSpeed Insights is telling me that my PNGs are just way too large. Sadly .NET does not provide any way to optimize PNG images so there is no easy fix - just unmanaged libraries and command line tools.

I have an allergy to manual processes so I've lashed up some code to automatically find and optimize PNGs in my App_Data folder using PNGCRUSH. I can call CrushAllImages() to fix up everything or CrushImage() when I need to fix up a specific PNG. Code below:

(Related: Long term solar powered time lapse camera using Arduino; Capture DropCam (Nest Cam) frames to Google Drive; Style Transfer for Time Lapse Photography)

(You might also like: Painted Lady Butterflies Eclosing; What is the San Francisco Rent Board Fee?; Baby Yellow Spiders)

(All Code Posts)

Minify and inline CSS for ASP.NET MVC

Updated on Wednesday, April 28, 2021

ASP.NET has a CssMinify class (and a JavaScript variant as well) designed for use in the bundling pipeline. But what if you want to have your CSS minified and inline? Here is an action that is working for me (rendered into a style tag on my _Layout.cshtml using @Html.Action("InlineCss", "Home")).

Note that I'm using this to inline CSS for this blog. The pages are cached so I'm not worried about how well this action performs. My blog is also basically all landing pages so I'm also not worried about caching a non-inline version for later use, I just drop all the CSS on every page.

(Related: Monitor page index status with Google Sheets, Apps Script and the Google Search Console API; Automate Google PageSpeed Insights and Core Web Vitals Logging with Apps Script; Reading and Writing Office 365 Excel from a Console app using the Microsoft.Graph C# Client API)

(You might also like: Timelapse, Week of Jan 17 2022; Prior Artist; Another Butterfly at the California Academy of Sciences)

(All Code Posts)