I have an Inno Setup script where the desired form was too complicated to build entirely in Inno Setup itself, so I created a helper class library in .NET which contains a WinForms window with the things I need.
I open this WinForms window in Inno Setup by exposing the method with the Unmanaged Exports NuGet from Robert Giesecke.
This works perfectly on my development machine running Windows 10. It also works on a test server running Windows Server 2012 and 2016. When I try to run the setup on a Windows Server 2008R2 machine however, I am presented with the following error:
Sytem.ArgumentException: Font '?' cannot be found.
This is my Inno Setup script:
#define MyAppName "InnoTest"
#define MyAppVersion "1.0"
#define MyAppPublisher "Test"
#define MyAppURL "http://inno.test"
[Setup]
AppName={#MyAppName}
AppVersion={#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={pf}\{#MyAppName}
DefaultGroupName={#MyAppName}
DisableProgramGroupPage=yes
OutputDir=C:\Users\Admin\Desktop\test_inno
OutputBaseFilename=test_inno_setup_x64
Compression=lzma/Max
SolidCompression=true
[Files]
Source: "C:\Users\Admin\Documents\Visual Studio 2017\Projects\InnoTestNet\InnoTestNet\bin\Release\InnoTestNet.dll"; DestDir: "{tmp}"; Flags: dontcopy
[Code]
procedure ShowTestForm(); external 'ShowTestForm@files:InnoTestNet.dll stdcall';
procedure InitializeWizard();
begin
ShowTestForm();
end;
and my C# code:
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using RGiesecke.DllExport;
namespace InnoTestNet
{
public class InnoTestNet
{
[DllExport("ShowTestForm", CallingConvention = CallingConvention.StdCall)]
public static void ShowTestForm()
{
try
{
var testForm = new TestForm();
testForm.ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
}
I have reduced the WinForms window down to the bare minimum (just one label).
Things I have tried:
- Embedding "Arial.otf" in the class library, loading the font at runtime with PrivateFontCollection and setting the font on the WinForm.
- Using another font like Calibri or Tahoma
- Changing the font of the InnoSetup installer itself (DefaultDialogFontName)
- Executing "Application.EnableVisualStyles()"
The Windows Server 2008R2 environment is a fully updated clean install with .NET Framework 4.7.2 intalled.
The class library is targeted for .NET Framework 4.5.2.
I am using the Unicode version of InnoSetup 5.6.1.
edit
I found this interesting SO question: Using SetDefaultDllDirectories breaks Font handling
It appears, when calling the "SetDefaultDllDirectories" function from the Windows API, font resolving might get broken. When further tracking down the release notes of Inno Setup 5.5.9 it appears Inno Setup is indeed calling this problematic function.