From 9aa6ccb224bf81c96da06e89f00759dfe454e4bf Mon Sep 17 00:00:00 2001 From: duffyduck Date: Fri, 3 Apr 2026 11:56:34 +0200 Subject: [PATCH] Fix Outlook COM connection: use Activator and clear error message - Try GetActiveObject first, then Activator.CreateInstance as fallback - Use Type.GetTypeFromProgID for version-independent COM activation - Clear error message explaining possible causes including New Outlook - NuGet Interop v15 is fine - it's the assembly version, works with all Outlook versions (2013-2024) via COM interface compatibility Co-Authored-By: Claude Opus 4.6 (1M context) --- .../Services/OutlookContactsService.cs | 31 ++++++++++++++----- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/src/StarfaceOutlookSync/Services/OutlookContactsService.cs b/src/StarfaceOutlookSync/Services/OutlookContactsService.cs index 2ddab49f..db34ecc9 100644 --- a/src/StarfaceOutlookSync/Services/OutlookContactsService.cs +++ b/src/StarfaceOutlookSync/Services/OutlookContactsService.cs @@ -26,20 +26,35 @@ namespace StarfaceOutlookSync.Services { if (_outlookApp != null) return _outlookApp; + // Versuch 1: Laufende Outlook-Instanz finden try { - // Versuche laufende Outlook-Instanz zu finden _outlookApp = (Outlook.Application)GetActiveComObject("Outlook.Application"); _weStartedOutlook = false; + return _outlookApp; } - catch - { - // Outlook starten falls nicht laufend - _outlookApp = new Outlook.Application(); - _weStartedOutlook = true; - } + catch { } - return _outlookApp; + // Versuch 2: Outlook per COM starten + try + { + var outlookType = Type.GetTypeFromProgID("Outlook.Application"); + if (outlookType != null) + { + _outlookApp = (Outlook.Application)Activator.CreateInstance(outlookType); + _weStartedOutlook = true; + return _outlookApp; + } + } + catch { } + + throw new InvalidOperationException( + "Outlook Classic konnte nicht gefunden werden.\n\n" + + "Moegliche Ursachen:\n" + + "- Outlook Classic ist nicht installiert\n" + + "- Outlook Classic ist nicht gestartet\n" + + "- Das neue Outlook wird verwendet (wird noch nicht unterstuetzt)\n\n" + + "Bitte Outlook Classic starten und erneut versuchen."); } public List GetContactFolderPaths()