6

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.

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.

brz
  • 1,846
  • 21
  • 21
  • Can you run your form directly without Inno (in test application)? – Miamy Nov 18 '18 at 19:43
  • Yes. I made a console application and referenced the class library from there. Ran without any problem on all systems. – brz Nov 18 '18 at 19:44
  • My guess is Inno Setup is calling a windows API function which breaks the font resolving. But don't know where to look. I also came across this interesting SO question: https://stackoverflow.com/questions/25818073/using-setdefaultdlldirectories-breaks-font-handling – brz Nov 18 '18 at 19:47
  • What if you run that console application from Inno Setup? – Martin Prikryl Nov 18 '18 at 20:00
  • Also this post suggests the error can be caused by Antivirus: https://social.msdn.microsoft.com/Forums/en-US/36ab500f-4d38-418f-97f5-dfece24c281f/quotsystemargumentexception-font-cannot-be-foundquot-during-application-start-up-any?forum=winforms - Can you try disabling it? – Martin Prikryl Nov 18 '18 at 20:01
  • @MartinPrikryl calling the console application from inno setup will probably work fine. Might go this way if I'm unable to find a more elegant solution. There is no antivirus present on the machine. I have found some new clues and edited the question. – brz Nov 18 '18 at 20:03
  • Try to build dll with target x86 (Inno setup is 32-bit application only). As an other option, if exe file runs from setup correctly, consider to use it instead of library. – Miamy Nov 18 '18 at 20:04
  • @Miamy I am already building the class library as x86. Might go the exe route if I'm unable to find a more elegant solution. – brz Nov 18 '18 at 20:09

0 Answers0