Entwickler-Ecke

WinForms - Namenskonflikt in einer Windows Forms Anwendung


xCrice - Di 28.06.16 09:13
Titel: Namenskonflikt in einer Windows Forms Anwendung
Hallo zusammen,

folgendes Problem beschäftigt mich schon seit Tagen:

Ich möchte in meine Windows Form das globale Adressbuch von Outlook auslesen und in einer TextBox (textbox1)wiedergeben.

C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
MSOutlook.Application outlook = (MSOutlook.Application)Marshal.GetActiveObject("Outlool.Application");

MSOutlook.AddressList myAdrBook = outlook.Session.AddressLists["Kontakte"];

foreach (MSOutlook.AddressEntry address in myAdrBook.AddressEntries)
{
    textBox1.Text = textBox1.Text + "\n" + address.Name + " ,  Adresse: " + address.Address;
}

Nun wird aber "Application" bereits in meiner Windows Form verwendet...dadurch habe ich nun eine Namenskonflikt .. :nixweiss:
Leider habe ich keine Ahnung wie ich diesen beheben kann.

Danke schon mal im Voraus !

Grüße
xCrice


Th69 - Di 28.06.16 10:12

Hallo und :welcome:

in deinem Code sehe ich keinen Namenskonflikt (da du ja explizit den Namensbereich MSOutlook angegeben hast).

Am besten du zeigst die konkrete Codestelle sowie den Compilerfehler.


xCrice - Di 28.06.16 10:25

Danke :)

Der Fehler:

Zitat:
Error 3 The type 'Microsoft.Office.Interop.Outlook.Application' exists in both 'C:\Program Files (x86)\Microsoft Visual Studio 11.0\Visual Studio Tools for Office\PIA\Office14\Microsoft.Office.Interop.Outlook.dll' and 'C:\WINDOWS\assembly\GAC_MSIL\Microsoft.Office.Interop.Outlook\14.0.0.0__71e9bce111e9429c\Microsoft.Office.Interop.Outlook.dll' U:\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 146 23 WindowsFormsApplication1


Ich habe das gesamte Projekt gerade nochmals neu aufgesetzt. Nun wird mir der Fehler nicht mehr angezeigt :?: Verstehe ich jetzt nicht :lol:

Jetzt hat er nur noch ein Problem mit "Marshal"
(Das auslesen des globalen Adressbuchs von Outlook habe ich mir mithilfe von Google zusammengebaut)