for each MyItem in myFolder.Items=HRESULT: 0x80004002 (E_NOINTERFA

G

Guest

Hi....

got a problem...

Outlook 2003 & Exchange Server 2003

I´d like to iterate through folder Items but it fails with RESULT:
0x80004002 (E_NOINTERFACE) after the 249´s Item each time... :(

Don´t know what to do....

[code:]
Private Sub btnSearchAll_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSearchAll.Click
Dim myItems As Microsoft.Office.Interop.Outlook.Items =
myContactFolder.Items
Dim myItem As Outlook.ContactItem
For i As Integer = myContactFolder.Items.Count To 1 Step -1 '
Failure HRESULT: 0x80004002 (E_NOINTERFACE)
myItem = myItems.Item(i)
'lstSearchResults.Items.Add("skipped " & myItem.FileAs.ToString
& " - " & myItem.Categories)
If Microsoft.VisualBasic.Information.TypeName(myItem) =
"ContactItem" Then
If InStr(myItem.Categories, txtSearch.Text,
CompareMethod.Text) Then
lstSearchResults.Items.Add(myItem.FileAs.ToString & " -
" & myItem.Categories)
End If
Else
MsgBox(Microsoft.VisualBasic.Information.TypeName(myItem))
End If
If i = 100 Then Stop
Next i
End Sub

[/code:]

"
Das COM-Objekt des Typs "System.__ComObject" kann nicht in den
Schnittstellentyp "Microsoft.Office.Interop.Outlook.ContactItem" umgewandelt
werden. Dieser Vorgang konnte nicht durchgeführt werden, da der
QueryInterface-Aufruf an die COM-Komponente für die Schnittstelle mit der IID
"{00063021-0000-0000-C000-000000000046}" aufgrund des folgenden Fehlers nicht
durchgeführt werden konnte: Schnittstelle nicht unterstützt (Ausnahme von
HRESULT: 0x80004002 (E_NOINTERFACE)).
"

I also tried the oÓutlook repair feature... but no changes...


Greets from Germany

HelixX23
 
D

Dmitry Streblechenko

You are running out of the 255 RPC channels/process imposed by Exchange in
the online mode.
1. Do cache the value of fMAPIFolder.Item
2. Explicitly release the items as soon as you arae done with them:

set myItems = myContactFolder.Items
For i As Integer = myContactFolder.Items.Count To 1 Step -1 '
set myItem = myItems.Item(i)
...
Marshal.ReleaseCOMObject(myItem)
GC.Collect();
Next i


Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
G

Guest

Hi... thanks for answering :)
I tried this:

Private Sub SearchALL()
Dim myItems As Microsoft.Office.Interop.Outlook.Items =
myContactFolder.Items
pgbSearchAndReplace.Enabled = True
pgbSearchAndReplace.Minimum = 0
pgbSearchAndReplace.Maximum = myItems.Count
pgbSearchAndReplace.Value = 0

MsgBox("Items.Count = " & myItems.Count)

For i As Integer = 1 To myContactFolder.Items.Count
Dim myItem As Outlook.ContactItem = myItems.Item(i)
If Microsoft.VisualBasic.Information.TypeName(myItem) =
"ContactItem" Then
If InStr(myItem.Categories, txtSearch.Text,
CompareMethod.Text) Then
lstSearchResults.Items.Add(myItem.FileAs.ToString & " -
" & myItem.Categories)
End If
Else
MsgBox(Microsoft.VisualBasic.Information.TypeName(myItem))
End If

' Release ComObject
Try

System.Runtime.InteropServices.Marshal.ReleaseComObject(myItem)
Catch ex As Exception
MsgBox("Can't release ComObject" & vbCrLf & ex.Message)
End Try

myItem = Nothing

GC.Collect()
GC.WaitForPendingFinalizers()
Next i
End Sub

but it fails the same at Item 249

it seems that myItem does not release itself...

what am i doing wrong?

Greets HelixX23


Dmitry Streblechenko said:
You are running out of the 255 RPC channels/process imposed by Exchange in
the online mode.
1. Do cache the value of fMAPIFolder.Item
2. Explicitly release the items as soon as you arae done with them:

set myItems = myContactFolder.Items
For i As Integer = myContactFolder.Items.Count To 1 Step -1 '
set myItem = myItems.Item(i)
...
Marshal.ReleaseCOMObject(myItem)
GC.Collect();
Next i


Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

HelixX23 said:
Hi....

got a problem...

Outlook 2003 & Exchange Server 2003

I´d like to iterate through folder Items but it fails with RESULT:
0x80004002 (E_NOINTERFACE) after the 249´s Item each time... :(

Don´t know what to do....

[code:]
Private Sub btnSearchAll_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSearchAll.Click
Dim myItems As Microsoft.Office.Interop.Outlook.Items =
myContactFolder.Items
Dim myItem As Outlook.ContactItem
For i As Integer = myContactFolder.Items.Count To 1 Step -1 '
Failure HRESULT: 0x80004002 (E_NOINTERFACE)
myItem = myItems.Item(i)
'lstSearchResults.Items.Add("skipped " & myItem.FileAs.ToString
& " - " & myItem.Categories)
If Microsoft.VisualBasic.Information.TypeName(myItem) =
"ContactItem" Then
If InStr(myItem.Categories, txtSearch.Text,
CompareMethod.Text) Then
lstSearchResults.Items.Add(myItem.FileAs.ToString & " -
" & myItem.Categories)
End If
Else
MsgBox(Microsoft.VisualBasic.Information.TypeName(myItem))
End If
If i = 100 Then Stop
Next i
End Sub

[/code:]

"
Das COM-Objekt des Typs "System.__ComObject" kann nicht in den
Schnittstellentyp "Microsoft.Office.Interop.Outlook.ContactItem"
umgewandelt
werden. Dieser Vorgang konnte nicht durchgeführt werden, da der
QueryInterface-Aufruf an die COM-Komponente für die Schnittstelle mit der
IID
"{00063021-0000-0000-C000-000000000046}" aufgrund des folgenden Fehlers
nicht
durchgeführt werden konnte: Schnittstelle nicht unterstützt (Ausnahme von
HRESULT: 0x80004002 (E_NOINTERFACE)).
"

I also tried the oÓutlook repair feature... but no changes...


Greets from Germany

HelixX23
 
G

Guest

Maybe GC does not feel to release my objects...

"4. GC will release the COM objects whenever it feels like it, which may be
minutes later. And COM subsystem does not handle "all of that", GC and the
object itself do.
"
"When GC feels it is time to release it (whenever that might be),"

What can i do to force him to release myItem?


HelixX23 said:
Hi... thanks for answering :)
I tried this:

Private Sub SearchALL()
Dim myItems As Microsoft.Office.Interop.Outlook.Items =
myContactFolder.Items
pgbSearchAndReplace.Enabled = True
pgbSearchAndReplace.Minimum = 0
pgbSearchAndReplace.Maximum = myItems.Count
pgbSearchAndReplace.Value = 0

MsgBox("Items.Count = " & myItems.Count)

For i As Integer = 1 To myContactFolder.Items.Count
Dim myItem As Outlook.ContactItem = myItems.Item(i)
If Microsoft.VisualBasic.Information.TypeName(myItem) =
"ContactItem" Then
If InStr(myItem.Categories, txtSearch.Text,
CompareMethod.Text) Then
lstSearchResults.Items.Add(myItem.FileAs.ToString & " -
" & myItem.Categories)
End If
Else
MsgBox(Microsoft.VisualBasic.Information.TypeName(myItem))
End If

' Release ComObject
Try

System.Runtime.InteropServices.Marshal.ReleaseComObject(myItem)
Catch ex As Exception
MsgBox("Can't release ComObject" & vbCrLf & ex.Message)
End Try

myItem = Nothing

GC.Collect()
GC.WaitForPendingFinalizers()
Next i
End Sub

but it fails the same at Item 249

it seems that myItem does not release itself...

what am i doing wrong?

Greets HelixX23


Dmitry Streblechenko said:
You are running out of the 255 RPC channels/process imposed by Exchange in
the online mode.
1. Do cache the value of fMAPIFolder.Item
2. Explicitly release the items as soon as you arae done with them:

set myItems = myContactFolder.Items
For i As Integer = myContactFolder.Items.Count To 1 Step -1 '
set myItem = myItems.Item(i)
...
Marshal.ReleaseCOMObject(myItem)
GC.Collect();
Next i


Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

HelixX23 said:
Hi....

got a problem...

Outlook 2003 & Exchange Server 2003

I´d like to iterate through folder Items but it fails with RESULT:
0x80004002 (E_NOINTERFACE) after the 249´s Item each time... :(

Don´t know what to do....

[code:]
Private Sub btnSearchAll_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSearchAll.Click
Dim myItems As Microsoft.Office.Interop.Outlook.Items =
myContactFolder.Items
Dim myItem As Outlook.ContactItem
For i As Integer = myContactFolder.Items.Count To 1 Step -1 '
Failure HRESULT: 0x80004002 (E_NOINTERFACE)
myItem = myItems.Item(i)
'lstSearchResults.Items.Add("skipped " & myItem.FileAs.ToString
& " - " & myItem.Categories)
If Microsoft.VisualBasic.Information.TypeName(myItem) =
"ContactItem" Then
If InStr(myItem.Categories, txtSearch.Text,
CompareMethod.Text) Then
lstSearchResults.Items.Add(myItem.FileAs.ToString & " -
" & myItem.Categories)
End If
Else
MsgBox(Microsoft.VisualBasic.Information.TypeName(myItem))
End If
If i = 100 Then Stop
Next i
End Sub

[/code:]

"
Das COM-Objekt des Typs "System.__ComObject" kann nicht in den
Schnittstellentyp "Microsoft.Office.Interop.Outlook.ContactItem"
umgewandelt
werden. Dieser Vorgang konnte nicht durchgeführt werden, da der
QueryInterface-Aufruf an die COM-Komponente für die Schnittstelle mit der
IID
"{00063021-0000-0000-C000-000000000046}" aufgrund des folgenden Fehlers
nicht
durchgeführt werden konnte: Schnittstelle nicht unterstützt (Ausnahme von
HRESULT: 0x80004002 (E_NOINTERFACE)).
"

I also tried the oÓutlook repair feature... but no changes...


Greets from Germany

HelixX23
 
K

Ken Slovak - [MVP - Outlook]

Marshal.ReleaseComObject(myItem);

// followed by

GC.Collect();
GC.WaitForPendingFinalizers();
 
G

Guest

In my Environment Marshal is not defined

I´m using Visual Studio 2005 VBA Outlook Addin to get this working..

So i used the System.Runtime.InteropServices.Marshal.ReleaseComObject
referenced function to release my COM Object...

but.. it does not work..

Code:
For i As Integer = 1 To myContactFolder.Items.Count
Debug.Print("generate Object")
Debug.Print("Speicher: " & GC.GetTotalMemory(True))
Dim myItem As Outlook.ContactItem =
myContactFolder.Items.Item(i) ' here drops the failure when "i" reaches "249
as int"
Debug.Print("Speicher: " & GC.GetTotalMemory(True))
If Microsoft.VisualBasic.Information.TypeName(myItem) =
"ContactItem" Then
If InStr(myItem.Categories, txtSearch.Text,
CompareMethod.Text) Then
lstSearchResults.Items.Add(myItem.FileAs.ToString & " -
" & myItem.Categories)
End If
Else

Debug.Print(Microsoft.VisualBasic.Information.TypeName(myItem))
End If

' Try to Release ComObject
Try

System.Runtime.InteropServices.Marshal.ReleaseComObject(myItem)
Catch ex As Exception
Debug.Print("Can't release ComObject" & vbCrLf & ex.Message)
End Try

myItem = Nothing

If i Mod 245 = 0 Then
' --- GC starten
GC.Collect()
GC.WaitForPendingFinalizers()
End If

Next i
 
D

Dmitry Streblechenko

Do not use multiple dot notation (e.g. myContactFolder.Items.Count) as the
compiler creates implicit variables to hold the intermediate results.
Use explicit variables and explicitly release them.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

HelixX23 said:
In my Environment Marshal is not defined

I´m using Visual Studio 2005 VBA Outlook Addin to get this working..

So i used the System.Runtime.InteropServices.Marshal.ReleaseComObject
referenced function to release my COM Object...

but.. it does not work..

Code:
For i As Integer = 1 To myContactFolder.Items.Count
Debug.Print("generate Object")
Debug.Print("Speicher: " & GC.GetTotalMemory(True))
Dim myItem As Outlook.ContactItem =
myContactFolder.Items.Item(i) ' here drops the failure when "i" reaches
"249
as int"
Debug.Print("Speicher: " & GC.GetTotalMemory(True))
If Microsoft.VisualBasic.Information.TypeName(myItem) =
"ContactItem" Then
If InStr(myItem.Categories, txtSearch.Text,
CompareMethod.Text) Then
lstSearchResults.Items.Add(myItem.FileAs.ToString & " -
" & myItem.Categories)
End If
Else

Debug.Print(Microsoft.VisualBasic.Information.TypeName(myItem))
End If

' Try to Release ComObject
Try

System.Runtime.InteropServices.Marshal.ReleaseComObject(myItem)
Catch ex As Exception
Debug.Print("Can't release ComObject" & vbCrLf &
ex.Message)
End Try

myItem = Nothing

If i Mod 245 = 0 Then
' --- GC starten
GC.Collect()
GC.WaitForPendingFinalizers()
End If

Next i


Ken Slovak - said:
Marshal.ReleaseComObject(myItem);

// followed by

GC.Collect();
GC.WaitForPendingFinalizers();
 
G

Guest

Hi...
Thanks for the reply Dmitry.

something is getting better...
the failure changed the line... :)
maybe it is not explicitely declared enough??

Code:
Imports System.Runtime.InteropServices
Imports Microsoft.Office.Core
Imports Outlook = Microsoft.Office.Interop.Outlook
Imports Microsoft.VisualBasic.Information

Public Class SearchAndReplace

Public myContactFolder As Outlook.MAPIFolder '=
Outlook.Application.GetNamespace("MAPI").folders("Öffetnliche
Ordner").folders("Alle Öffentlichen Ordner").folders("EUKON Kontakte")
Private Sub btnPickOLFolder_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnPickOLFolder.Click
Dim myOlApp As Outlook.Application =
CreateObject("Outlook.Application")
Dim myNamespace As Outlook.NameSpace = myOlApp.GetNamespace("MAPI")
myContactFolder = myNamespace.PickFolder
If myContactFolder Is Nothing Then MsgBox("Sie haben keinen Ordner
ausgewählt...?") : Exit Sub
txtOutlookFolder.Text = myContactFolder.FolderPath
End Sub

Private Sub btnSearchAll_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSearchAll.Click
SearchALL()
End Sub

Private Sub SearchALL()
Dim myContactFolderItems As Outlook.Items = myContactFolder.Items
Dim myItem As Object
Dim countItems As Integer = myContactFolderItems.Count
Dim myItemCategories As Object
Dim myItemFileAs As String

pgbSearchAndReplace.Enabled = True
pgbSearchAndReplace.Minimum = 0
pgbSearchAndReplace.Maximum = myContactFolder.Items.Count
pgbSearchAndReplace.Value = 0

MsgBox("Items.Count = " & countItems)

For i As Integer = 1 To countItems
pgbSearchAndReplace.Value = i ' my Progressbar

Debug.Print("Memory: " & GC.GetTotalMemory(True))
Debug.Print("generate Object")

myContactFolderItems = myContactFolder.Items
myItem = myContactFolderItems.Item(i) ' old failure has passed
when "i  as int = 250"
myItemCategories = myItem.Categories ' new failure drops here...
? not explicite enough?
myItemFileAs = myItem.FileAs.ToString

Debug.Print("Memory: " & GC.GetTotalMemory(True))

If TypeName(myItem) = "ContactItem" Then

If InStr(myItemCategories, txtSearch.Text,
CompareMethod.Text) Then
lstSearchResults.Items.Add(myItemFileAs & " - " &
myItemCategories)
End If
Else
MsgBox(TypeName(myItem))
End If

' Try to release ComObjects
ReleaseMyComObject(myItem)
ReleaseMyComObject(myContactFolderItems)
ReleaseMyComObject(myItemCategories)
ReleaseMyComObject(myItemFileAs)

If i Mod 245 = 0 Then
' --- GC starten
Debug.Print("Memory: " & GC.GetTotalMemory(True))
Debug.Print("GC starting")
GC.Collect()
GC.WaitForPendingFinalizers()
Debug.Print("Garbage collected")
Debug.Print("Memory: " & GC.GetTotalMemory(True))
End If

Next i

pgbSearchAndReplace.Value = 0
pgbSearchAndReplace.Enabled = False
End Sub

Public Sub ReleaseMyComObject(ByVal myCOMObject As Object)
Try
If Not myCOMObject Is Nothing Then
Do
If Marshal.ReleaseComObject(myCOMObject) = 0 Then
Debug.Print("Object released")
Exit Do
End If
Loop
End If
Catch ex As Exception
Debug.Print("Can't release ComObject" & vbCrLf & ex.Message)
End Try
myCOMObject = Nothing
End Sub
End Class

What am i doing wrong?

greets HelixX23

Dmitry Streblechenko said:
Do not use multiple dot notation (e.g. myContactFolder.Items.Count) as the
compiler creates implicit variables to hold the intermediate results.
Use explicit variables and explicitly release them.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

HelixX23 said:
In my Environment Marshal is not defined

I´m using Visual Studio 2005 VBA Outlook Addin to get this working..

So i used the System.Runtime.InteropServices.Marshal.ReleaseComObject
referenced function to release my COM Object...

but.. it does not work..

Code:
For i As Integer = 1 To myContactFolder.Items.Count
Debug.Print("generate Object")
Debug.Print("Speicher: " & GC.GetTotalMemory(True))
Dim myItem As Outlook.ContactItem =
myContactFolder.Items.Item(i) ' here drops the failure when "i" reaches
"249
as int"
Debug.Print("Speicher: " & GC.GetTotalMemory(True))
If Microsoft.VisualBasic.Information.TypeName(myItem) =
"ContactItem" Then
If InStr(myItem.Categories, txtSearch.Text,
CompareMethod.Text) Then
lstSearchResults.Items.Add(myItem.FileAs.ToString & " -
" & myItem.Categories)
End If
Else

Debug.Print(Microsoft.VisualBasic.Information.TypeName(myItem))
End If

' Try to Release ComObject
Try

System.Runtime.InteropServices.Marshal.ReleaseComObject(myItem)
Catch ex As Exception
Debug.Print("Can't release ComObject" & vbCrLf &
ex.Message)
End Try

myItem = Nothing

If i Mod 245 = 0 Then
' --- GC starten
GC.Collect()
GC.WaitForPendingFinalizers()
End If

Next i


Ken Slovak - said:
Marshal.ReleaseComObject(myItem);

// followed by

GC.Collect();
GC.WaitForPendingFinalizers();




Maybe GC does not feel to release my objects...

"4. GC will release the COM objects whenever it feels like it, which
may
be
minutes later. And COM subsystem does not handle "all of that", GC and
the
object itself do.
"
"When GC feels it is time to release it (whenever that might be),"

What can i do to force him to release myItem?
 
D

Dmitry Streblechenko

I can only guess tah t since you declare myItem as a generic Object, teh
compiler QI's it for IDispatch every timee and does not release the
reference.
Can you try to declare it as ContactItem (assuming you do not have any DLs
in that folder)?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

HelixX23 said:
Hi...
Thanks for the reply Dmitry.

something is getting better...
the failure changed the line... :)
maybe it is not explicitely declared enough??

Code:
Imports System.Runtime.InteropServices
Imports Microsoft.Office.Core
Imports Outlook = Microsoft.Office.Interop.Outlook
Imports Microsoft.VisualBasic.Information

Public Class SearchAndReplace

Public myContactFolder As Outlook.MAPIFolder '=
Outlook.Application.GetNamespace("MAPI").folders("Öffetnliche
Ordner").folders("Alle Öffentlichen Ordner").folders("EUKON Kontakte")
Private Sub btnPickOLFolder_Click(ByVal sender As System.Object, ByVal
e
As System.EventArgs) Handles btnPickOLFolder.Click
Dim myOlApp As Outlook.Application =
CreateObject("Outlook.Application")
Dim myNamespace As Outlook.NameSpace = myOlApp.GetNamespace("MAPI")
myContactFolder = myNamespace.PickFolder
If myContactFolder Is Nothing Then MsgBox("Sie haben keinen Ordner
ausgewählt...?") : Exit Sub
txtOutlookFolder.Text = myContactFolder.FolderPath
End Sub

Private Sub btnSearchAll_Click(ByVal sender As System.Object, ByVal e
As
System.EventArgs) Handles btnSearchAll.Click
SearchALL()
End Sub

Private Sub SearchALL()
Dim myContactFolderItems As Outlook.Items = myContactFolder.Items
Dim myItem As Object
Dim countItems As Integer = myContactFolderItems.Count
Dim myItemCategories As Object
Dim myItemFileAs As String

pgbSearchAndReplace.Enabled = True
pgbSearchAndReplace.Minimum = 0
pgbSearchAndReplace.Maximum = myContactFolder.Items.Count
pgbSearchAndReplace.Value = 0

MsgBox("Items.Count = " & countItems)

For i As Integer = 1 To countItems
pgbSearchAndReplace.Value = i ' my Progressbar

Debug.Print("Memory: " & GC.GetTotalMemory(True))
Debug.Print("generate Object")

myContactFolderItems = myContactFolder.Items
myItem = myContactFolderItems.Item(i) ' old failure has passed
when "i  as int = 250"
myItemCategories = myItem.Categories ' new failure drops
here...
? not explicite enough?
myItemFileAs = myItem.FileAs.ToString

Debug.Print("Memory: " & GC.GetTotalMemory(True))

If TypeName(myItem) = "ContactItem" Then

If InStr(myItemCategories, txtSearch.Text,
CompareMethod.Text) Then
lstSearchResults.Items.Add(myItemFileAs & " - " &
myItemCategories)
End If
Else
MsgBox(TypeName(myItem))
End If

' Try to release ComObjects
ReleaseMyComObject(myItem)
ReleaseMyComObject(myContactFolderItems)
ReleaseMyComObject(myItemCategories)
ReleaseMyComObject(myItemFileAs)

If i Mod 245 = 0 Then
' --- GC starten
Debug.Print("Memory: " & GC.GetTotalMemory(True))
Debug.Print("GC starting")
GC.Collect()
GC.WaitForPendingFinalizers()
Debug.Print("Garbage collected")
Debug.Print("Memory: " & GC.GetTotalMemory(True))
End If

Next i

pgbSearchAndReplace.Value = 0
pgbSearchAndReplace.Enabled = False
End Sub

Public Sub ReleaseMyComObject(ByVal myCOMObject As Object)
Try
If Not myCOMObject Is Nothing Then
Do
If Marshal.ReleaseComObject(myCOMObject) = 0 Then
Debug.Print("Object released")
Exit Do
End If
Loop
End If
Catch ex As Exception
Debug.Print("Can't release ComObject" & vbCrLf & ex.Message)
End Try
myCOMObject = Nothing
End Sub
End Class

What am i doing wrong?

greets HelixX23

Dmitry Streblechenko said:
Do not use multiple dot notation (e.g. myContactFolder.Items.Count) as
the
compiler creates implicit variables to hold the intermediate results.
Use explicit variables and explicitly release them.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

HelixX23 said:
In my Environment Marshal is not defined

I´m using Visual Studio 2005 VBA Outlook Addin to get this working..

So i used the System.Runtime.InteropServices.Marshal.ReleaseComObject
referenced function to release my COM Object...

but.. it does not work..

Code:
For i As Integer = 1 To myContactFolder.Items.Count
Debug.Print("generate Object")
Debug.Print("Speicher: " & GC.GetTotalMemory(True))
Dim myItem As Outlook.ContactItem =
myContactFolder.Items.Item(i) ' here drops the failure when "i" reaches
"249
as int"
Debug.Print("Speicher: " & GC.GetTotalMemory(True))
If Microsoft.VisualBasic.Information.TypeName(myItem) =
"ContactItem" Then
If InStr(myItem.Categories, txtSearch.Text,
CompareMethod.Text) Then
lstSearchResults.Items.Add(myItem.FileAs.ToString &
" -
" & myItem.Categories)
End If
Else

Debug.Print(Microsoft.VisualBasic.Information.TypeName(myItem))
End If

' Try to Release ComObject
Try

System.Runtime.InteropServices.Marshal.ReleaseComObject(myItem)
Catch ex As Exception
Debug.Print("Can't release ComObject" & vbCrLf &
ex.Message)
End Try

myItem = Nothing

If i Mod 245 = 0 Then
' --- GC starten
GC.Collect()
GC.WaitForPendingFinalizers()
End If

Next i


:

Marshal.ReleaseComObject(myItem);

// followed by

GC.Collect();
GC.WaitForPendingFinalizers();




Maybe GC does not feel to release my objects...

"4. GC will release the COM objects whenever it feels like it, which
may
be
minutes later. And COM subsystem does not handle "all of that", GC
and
the
object itself do.
"
"When GC feels it is time to release it (whenever that might be),"

What can i do to force him to release myItem?
 
G

Guest

I tried to declare myItem as Outlook.ContactItem but this fails also...
something is wrong with the Garbage Collector... its not collecting
anything...
I also tried to start the Garbage Collector before that function and after
the 245´s Item but it fails also.

are there maybe any working examples how to successfully releaseComObjects
under an "exchange folder Items cycle"?

greets HelixX23

Dmitry Streblechenko said:
I can only guess tah t since you declare myItem as a generic Object, teh
compiler QI's it for IDispatch every timee and does not release the
reference.
Can you try to declare it as ContactItem (assuming you do not have any DLs
in that folder)?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

HelixX23 said:
Hi...
Thanks for the reply Dmitry.

something is getting better...
the failure changed the line... :)
maybe it is not explicitely declared enough??

Code:
Imports System.Runtime.InteropServices
Imports Microsoft.Office.Core
Imports Outlook = Microsoft.Office.Interop.Outlook
Imports Microsoft.VisualBasic.Information

Public Class SearchAndReplace

Public myContactFolder As Outlook.MAPIFolder '=
Outlook.Application.GetNamespace("MAPI").folders("Öffetnliche
Ordner").folders("Alle Öffentlichen Ordner").folders("EUKON Kontakte")
Private Sub btnPickOLFolder_Click(ByVal sender As System.Object, ByVal
e
As System.EventArgs) Handles btnPickOLFolder.Click
Dim myOlApp As Outlook.Application =
CreateObject("Outlook.Application")
Dim myNamespace As Outlook.NameSpace = myOlApp.GetNamespace("MAPI")
myContactFolder = myNamespace.PickFolder
If myContactFolder Is Nothing Then MsgBox("Sie haben keinen Ordner
ausgewählt...?") : Exit Sub
txtOutlookFolder.Text = myContactFolder.FolderPath
End Sub

Private Sub btnSearchAll_Click(ByVal sender As System.Object, ByVal e
As
System.EventArgs) Handles btnSearchAll.Click
SearchALL()
End Sub

Private Sub SearchALL()
Dim myContactFolderItems As Outlook.Items = myContactFolder.Items
Dim myItem As Object
Dim countItems As Integer = myContactFolderItems.Count
Dim myItemCategories As Object
Dim myItemFileAs As String

pgbSearchAndReplace.Enabled = True
pgbSearchAndReplace.Minimum = 0
pgbSearchAndReplace.Maximum = myContactFolder.Items.Count
pgbSearchAndReplace.Value = 0

MsgBox("Items.Count = " & countItems)

For i As Integer = 1 To countItems
pgbSearchAndReplace.Value = i ' my Progressbar

Debug.Print("Memory: " & GC.GetTotalMemory(True))
Debug.Print("generate Object")

myContactFolderItems = myContactFolder.Items
myItem = myContactFolderItems.Item(i) ' old failure has passed
when "i  as int = 250"
myItemCategories = myItem.Categories ' new failure drops
here...
? not explicite enough?
myItemFileAs = myItem.FileAs.ToString

Debug.Print("Memory: " & GC.GetTotalMemory(True))

If TypeName(myItem) = "ContactItem" Then

If InStr(myItemCategories, txtSearch.Text,
CompareMethod.Text) Then
lstSearchResults.Items.Add(myItemFileAs & " - " &
myItemCategories)
End If
Else
MsgBox(TypeName(myItem))
End If

' Try to release ComObjects
ReleaseMyComObject(myItem)
ReleaseMyComObject(myContactFolderItems)
ReleaseMyComObject(myItemCategories)
ReleaseMyComObject(myItemFileAs)

If i Mod 245 = 0 Then
' --- GC starten
Debug.Print("Memory: " & GC.GetTotalMemory(True))
Debug.Print("GC starting")
GC.Collect()
GC.WaitForPendingFinalizers()
Debug.Print("Garbage collected")
Debug.Print("Memory: " & GC.GetTotalMemory(True))
End If

Next i

pgbSearchAndReplace.Value = 0
pgbSearchAndReplace.Enabled = False
End Sub

Public Sub ReleaseMyComObject(ByVal myCOMObject As Object)
Try
If Not myCOMObject Is Nothing Then
Do
If Marshal.ReleaseComObject(myCOMObject) = 0 Then
Debug.Print("Object released")
Exit Do
End If
Loop
End If
Catch ex As Exception
Debug.Print("Can't release ComObject" & vbCrLf & ex.Message)
End Try
myCOMObject = Nothing
End Sub
End Class

What am i doing wrong?

greets HelixX23

Dmitry Streblechenko said:
Do not use multiple dot notation (e.g. myContactFolder.Items.Count) as
the
compiler creates implicit variables to hold the intermediate results.
Use explicit variables and explicitly release them.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

In my Environment Marshal is not defined

I´m using Visual Studio 2005 VBA Outlook Addin to get this working..

So i used the System.Runtime.InteropServices.Marshal.ReleaseComObject
referenced function to release my COM Object...

but.. it does not work..

Code:
For i As Integer = 1 To myContactFolder.Items.Count
Debug.Print("generate Object")
Debug.Print("Speicher: " & GC.GetTotalMemory(True))
Dim myItem As Outlook.ContactItem =
myContactFolder.Items.Item(i) ' here drops the failure when "i" reaches
"249
as int"
Debug.Print("Speicher: " & GC.GetTotalMemory(True))
If Microsoft.VisualBasic.Information.TypeName(myItem) =
"ContactItem" Then
If InStr(myItem.Categories, txtSearch.Text,
CompareMethod.Text) Then
lstSearchResults.Items.Add(myItem.FileAs.ToString &
" -
" & myItem.Categories)
End If
Else

Debug.Print(Microsoft.VisualBasic.Information.TypeName(myItem))
End If

' Try to Release ComObject
Try

System.Runtime.InteropServices.Marshal.ReleaseComObject(myItem)
Catch ex As Exception
Debug.Print("Can't release ComObject" & vbCrLf &
ex.Message)
End Try

myItem = Nothing

If i Mod 245 = 0 Then
' --- GC starten
GC.Collect()
GC.WaitForPendingFinalizers()
End If

Next i


:

Marshal.ReleaseComObject(myItem);

// followed by

GC.Collect();
GC.WaitForPendingFinalizers();




Maybe GC does not feel to release my objects...

"4. GC will release the COM objects whenever it feels like it, which
may
be
minutes later. And COM subsystem does not handle "all of that", GC
and
the
object itself do.
"
"When GC feels it is time to release it (whenever that might be),"

What can i do to force him to release myItem?
 
D

Dmitry Streblechenko

Try to remove everything from the loop and see if it runs Ok or fails with
the same problem.

myContactFolderItems = myContactFolder.Items
For i As Integer = 1 To myContactFolderItems.Count
myItem = myContactFolderItems.Item(i)
Marshal.ReleaseComObject(myItem)
Next i

Also, why do you keep recalculating
myContactFolderItems = myContactFolder.Items
*inside* the loop?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

HelixX23 said:
I tried to declare myItem as Outlook.ContactItem but this fails also...
something is wrong with the Garbage Collector... its not collecting
anything...
I also tried to start the Garbage Collector before that function and after
the 245´s Item but it fails also.

are there maybe any working examples how to successfully
releaseComObjects
under an "exchange folder Items cycle"?

greets HelixX23

Dmitry Streblechenko said:
I can only guess tah t since you declare myItem as a generic Object, teh
compiler QI's it for IDispatch every timee and does not release the
reference.
Can you try to declare it as ContactItem (assuming you do not have any
DLs
in that folder)?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

HelixX23 said:
Hi...
Thanks for the reply Dmitry.

something is getting better...
the failure changed the line... :)
maybe it is not explicitely declared enough??

Code:
Imports System.Runtime.InteropServices
Imports Microsoft.Office.Core
Imports Outlook = Microsoft.Office.Interop.Outlook
Imports Microsoft.VisualBasic.Information

Public Class SearchAndReplace

Public myContactFolder As Outlook.MAPIFolder '=
Outlook.Application.GetNamespace("MAPI").folders("Öffetnliche
Ordner").folders("Alle Öffentlichen Ordner").folders("EUKON Kontakte")
Private Sub btnPickOLFolder_Click(ByVal sender As System.Object,
ByVal
e
As System.EventArgs) Handles btnPickOLFolder.Click
Dim myOlApp As Outlook.Application =
CreateObject("Outlook.Application")
Dim myNamespace As Outlook.NameSpace =
myOlApp.GetNamespace("MAPI")
myContactFolder = myNamespace.PickFolder
If myContactFolder Is Nothing Then MsgBox("Sie haben keinen
Ordner
ausgewählt...?") : Exit Sub
txtOutlookFolder.Text = myContactFolder.FolderPath
End Sub

Private Sub btnSearchAll_Click(ByVal sender As System.Object, ByVal
e
As
System.EventArgs) Handles btnSearchAll.Click
SearchALL()
End Sub

Private Sub SearchALL()
Dim myContactFolderItems As Outlook.Items =
myContactFolder.Items
Dim myItem As Object
Dim countItems As Integer = myContactFolderItems.Count
Dim myItemCategories As Object
Dim myItemFileAs As String

pgbSearchAndReplace.Enabled = True
pgbSearchAndReplace.Minimum = 0
pgbSearchAndReplace.Maximum = myContactFolder.Items.Count
pgbSearchAndReplace.Value = 0

MsgBox("Items.Count = " & countItems)

For i As Integer = 1 To countItems
pgbSearchAndReplace.Value = i ' my Progressbar

Debug.Print("Memory: " & GC.GetTotalMemory(True))
Debug.Print("generate Object")

myContactFolderItems = myContactFolder.Items
myItem = myContactFolderItems.Item(i) ' old failure has
passed
when "i  as int = 250"
myItemCategories = myItem.Categories ' new failure drops
here...
? not explicite enough?
myItemFileAs = myItem.FileAs.ToString

Debug.Print("Memory: " & GC.GetTotalMemory(True))

If TypeName(myItem) = "ContactItem" Then

If InStr(myItemCategories, txtSearch.Text,
CompareMethod.Text) Then
lstSearchResults.Items.Add(myItemFileAs & " - " &
myItemCategories)
End If
Else
MsgBox(TypeName(myItem))
End If

' Try to release ComObjects
ReleaseMyComObject(myItem)
ReleaseMyComObject(myContactFolderItems)
ReleaseMyComObject(myItemCategories)
ReleaseMyComObject(myItemFileAs)

If i Mod 245 = 0 Then
' --- GC starten
Debug.Print("Memory: " & GC.GetTotalMemory(True))
Debug.Print("GC starting")
GC.Collect()
GC.WaitForPendingFinalizers()
Debug.Print("Garbage collected")
Debug.Print("Memory: " & GC.GetTotalMemory(True))
End If

Next i

pgbSearchAndReplace.Value = 0
pgbSearchAndReplace.Enabled = False
End Sub

Public Sub ReleaseMyComObject(ByVal myCOMObject As Object)
Try
If Not myCOMObject Is Nothing Then
Do
If Marshal.ReleaseComObject(myCOMObject) = 0 Then
Debug.Print("Object released")
Exit Do
End If
Loop
End If
Catch ex As Exception
Debug.Print("Can't release ComObject" & vbCrLf & ex.Message)
End Try
myCOMObject = Nothing
End Sub
End Class

What am i doing wrong?

greets HelixX23

:

Do not use multiple dot notation (e.g. myContactFolder.Items.Count)
as
the
compiler creates implicit variables to hold the intermediate results.
Use explicit variables and explicitly release them.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

In my Environment Marshal is not defined

I´m using Visual Studio 2005 VBA Outlook Addin to get this working..

So i used the
System.Runtime.InteropServices.Marshal.ReleaseComObject
referenced function to release my COM Object...

but.. it does not work..

Code:
For i As Integer = 1 To myContactFolder.Items.Count
Debug.Print("generate Object")
Debug.Print("Speicher: " & GC.GetTotalMemory(True))
Dim myItem As Outlook.ContactItem =
myContactFolder.Items.Item(i) ' here drops the failure when "i"
reaches
"249
as int"
Debug.Print("Speicher: " & GC.GetTotalMemory(True))
If Microsoft.VisualBasic.Information.TypeName(myItem) =
"ContactItem" Then
If InStr(myItem.Categories, txtSearch.Text,
CompareMethod.Text) Then
lstSearchResults.Items.Add(myItem.FileAs.ToString
&
" -
" & myItem.Categories)
End If
Else

Debug.Print(Microsoft.VisualBasic.Information.TypeName(myItem))
End If

' Try to Release ComObject
Try

System.Runtime.InteropServices.Marshal.ReleaseComObject(myItem)
Catch ex As Exception
Debug.Print("Can't release ComObject" & vbCrLf &
ex.Message)
End Try

myItem = Nothing

If i Mod 245 = 0 Then
' --- GC starten
GC.Collect()
GC.WaitForPendingFinalizers()
End If

Next i


:

Marshal.ReleaseComObject(myItem);

// followed by

GC.Collect();
GC.WaitForPendingFinalizers();




Maybe GC does not feel to release my objects...

"4. GC will release the COM objects whenever it feels like it,
which
may
be
minutes later. And COM subsystem does not handle "all of that",
GC
and
the
object itself do.
"
"When GC feels it is time to release it (whenever that might
be),"

What can i do to force him to release myItem?
 
G

Guest

Hi...

So i tried this... but it fails also... :(

"
myContactFolderItems = myContactFolder.Items
For i As Integer = 1 To myContactFolderItems.Count
myItem = myContactFolderItems.Item(i)
Marshal.ReleaseComObject(myItem)
Next i
"

i = 250 as integer

Das COM-Objekt des Typs "System.__ComObject" kann nicht in den
Schnittstellentyp "Microsoft.Office.Interop.Outlook.ContactItem" umgewandelt
werden. Dieser Vorgang konnte nicht durchgeführt werden, da der
QueryInterface-Aufruf an die COM-Komponente für die Schnittstelle mit der IID
"{00063021-0000-0000-C000-000000000046}" aufgrund des folgenden Fehlers nicht
durchgeführt werden konnte: Schnittstelle nicht unterstützt (Ausnahme von
HRESULT: 0x80004002 (E_NOINTERFACE)).

What am i doing wrong?

Maybe i should release the whole Outlook Application from my harddrive...
(joke) :)

greets HelixX23


Dmitry Streblechenko said:
Try to remove everything from the loop and see if it runs Ok or fails with
the same problem.

myContactFolderItems = myContactFolder.Items
For i As Integer = 1 To myContactFolderItems.Count
myItem = myContactFolderItems.Item(i)
Marshal.ReleaseComObject(myItem)
Next i

Also, why do you keep recalculating
myContactFolderItems = myContactFolder.Items
*inside* the loop?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

HelixX23 said:
I tried to declare myItem as Outlook.ContactItem but this fails also...
something is wrong with the Garbage Collector... its not collecting
anything...
I also tried to start the Garbage Collector before that function and after
the 245´s Item but it fails also.

are there maybe any working examples how to successfully
releaseComObjects
under an "exchange folder Items cycle"?

greets HelixX23

Dmitry Streblechenko said:
I can only guess tah t since you declare myItem as a generic Object, teh
compiler QI's it for IDispatch every timee and does not release the
reference.
Can you try to declare it as ContactItem (assuming you do not have any
DLs
in that folder)?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

Hi...
Thanks for the reply Dmitry.

something is getting better...
the failure changed the line... :)
maybe it is not explicitely declared enough??

Code:
Imports System.Runtime.InteropServices
Imports Microsoft.Office.Core
Imports Outlook = Microsoft.Office.Interop.Outlook
Imports Microsoft.VisualBasic.Information

Public Class SearchAndReplace

Public myContactFolder As Outlook.MAPIFolder '=
Outlook.Application.GetNamespace("MAPI").folders("Öffetnliche
Ordner").folders("Alle Öffentlichen Ordner").folders("EUKON Kontakte")
Private Sub btnPickOLFolder_Click(ByVal sender As System.Object,
ByVal
e
As System.EventArgs) Handles btnPickOLFolder.Click
Dim myOlApp As Outlook.Application =
CreateObject("Outlook.Application")
Dim myNamespace As Outlook.NameSpace =
myOlApp.GetNamespace("MAPI")
myContactFolder = myNamespace.PickFolder
If myContactFolder Is Nothing Then MsgBox("Sie haben keinen
Ordner
ausgewählt...?") : Exit Sub
txtOutlookFolder.Text = myContactFolder.FolderPath
End Sub

Private Sub btnSearchAll_Click(ByVal sender As System.Object, ByVal
e
As
System.EventArgs) Handles btnSearchAll.Click
SearchALL()
End Sub

Private Sub SearchALL()
Dim myContactFolderItems As Outlook.Items =
myContactFolder.Items
Dim myItem As Object
Dim countItems As Integer = myContactFolderItems.Count
Dim myItemCategories As Object
Dim myItemFileAs As String

pgbSearchAndReplace.Enabled = True
pgbSearchAndReplace.Minimum = 0
pgbSearchAndReplace.Maximum = myContactFolder.Items.Count
pgbSearchAndReplace.Value = 0

MsgBox("Items.Count = " & countItems)

For i As Integer = 1 To countItems
pgbSearchAndReplace.Value = i ' my Progressbar

Debug.Print("Memory: " & GC.GetTotalMemory(True))
Debug.Print("generate Object")

myContactFolderItems = myContactFolder.Items
myItem = myContactFolderItems.Item(i) ' old failure has
passed
when "i  as int = 250"
myItemCategories = myItem.Categories ' new failure drops
here...
? not explicite enough?
myItemFileAs = myItem.FileAs.ToString

Debug.Print("Memory: " & GC.GetTotalMemory(True))

If TypeName(myItem) = "ContactItem" Then

If InStr(myItemCategories, txtSearch.Text,
CompareMethod.Text) Then
lstSearchResults.Items.Add(myItemFileAs & " - " &
myItemCategories)
End If
Else
MsgBox(TypeName(myItem))
End If

' Try to release ComObjects
ReleaseMyComObject(myItem)
ReleaseMyComObject(myContactFolderItems)
ReleaseMyComObject(myItemCategories)
ReleaseMyComObject(myItemFileAs)

If i Mod 245 = 0 Then
' --- GC starten
Debug.Print("Memory: " & GC.GetTotalMemory(True))
Debug.Print("GC starting")
GC.Collect()
GC.WaitForPendingFinalizers()
Debug.Print("Garbage collected")
Debug.Print("Memory: " & GC.GetTotalMemory(True))
End If

Next i

pgbSearchAndReplace.Value = 0
pgbSearchAndReplace.Enabled = False
End Sub

Public Sub ReleaseMyComObject(ByVal myCOMObject As Object)
Try
If Not myCOMObject Is Nothing Then
Do
If Marshal.ReleaseComObject(myCOMObject) = 0 Then
Debug.Print("Object released")
Exit Do
End If
Loop
End If
Catch ex As Exception
Debug.Print("Can't release ComObject" & vbCrLf & ex.Message)
End Try
myCOMObject = Nothing
End Sub
End Class

What am i doing wrong?

greets HelixX23

:

Do not use multiple dot notation (e.g. myContactFolder.Items.Count)
as
the
compiler creates implicit variables to hold the intermediate results.
Use explicit variables and explicitly release them.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

In my Environment Marshal is not defined

I´m using Visual Studio 2005 VBA Outlook Addin to get this working..

So i used the
System.Runtime.InteropServices.Marshal.ReleaseComObject
referenced function to release my COM Object...

but.. it does not work..

Code:
For i As Integer = 1 To myContactFolder.Items.Count
Debug.Print("generate Object")
Debug.Print("Speicher: " & GC.GetTotalMemory(True))
Dim myItem As Outlook.ContactItem =
myContactFolder.Items.Item(i) ' here drops the failure when "i"
reaches
"249
as int"
Debug.Print("Speicher: " & GC.GetTotalMemory(True))
If Microsoft.VisualBasic.Information.TypeName(myItem) =
"ContactItem" Then
If InStr(myItem.Categories, txtSearch.Text,
CompareMethod.Text) Then
lstSearchResults.Items.Add(myItem.FileAs.ToString
&
" -
" & myItem.Categories)
End If
Else

Debug.Print(Microsoft.VisualBasic.Information.TypeName(myItem))
End If

' Try to Release ComObject
Try

System.Runtime.InteropServices.Marshal.ReleaseComObject(myItem)
Catch ex As Exception
Debug.Print("Can't release ComObject" & vbCrLf &
ex.Message)
End Try

myItem = Nothing

If i Mod 245 = 0 Then
' --- GC starten
GC.Collect()
GC.WaitForPendingFinalizers()
End If

Next i


:

Marshal.ReleaseComObject(myItem);

// followed by

GC.Collect();
GC.WaitForPendingFinalizers();




Maybe GC does not feel to release my objects...

"4. GC will release the COM objects whenever it feels like it,
which
may
be
minutes later. And COM subsystem does not handle "all of that",
GC
and
the
object itself do.
"
"When GC feels it is time to release it (whenever that might
be),"

What can i do to force him to release myItem?
 
D

Dmitry Streblechenko

Did you remember to declare myItem as Outlook.ContactItem rather than the
generic Object?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

HelixX23 said:
Hi...

So i tried this... but it fails also... :(

"
myContactFolderItems = myContactFolder.Items
For i As Integer = 1 To myContactFolderItems.Count
myItem = myContactFolderItems.Item(i)
Marshal.ReleaseComObject(myItem)
Next i
"

i = 250 as integer

Das COM-Objekt des Typs "System.__ComObject" kann nicht in den
Schnittstellentyp "Microsoft.Office.Interop.Outlook.ContactItem"
umgewandelt
werden. Dieser Vorgang konnte nicht durchgeführt werden, da der
QueryInterface-Aufruf an die COM-Komponente für die Schnittstelle mit der
IID
"{00063021-0000-0000-C000-000000000046}" aufgrund des folgenden Fehlers
nicht
durchgeführt werden konnte: Schnittstelle nicht unterstützt (Ausnahme von
HRESULT: 0x80004002 (E_NOINTERFACE)).

What am i doing wrong?

Maybe i should release the whole Outlook Application from my harddrive...
(joke) :)

greets HelixX23


Dmitry Streblechenko said:
Try to remove everything from the loop and see if it runs Ok or fails
with
the same problem.

myContactFolderItems = myContactFolder.Items
For i As Integer = 1 To myContactFolderItems.Count
myItem = myContactFolderItems.Item(i)
Marshal.ReleaseComObject(myItem)
Next i

Also, why do you keep recalculating
myContactFolderItems = myContactFolder.Items
*inside* the loop?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

HelixX23 said:
I tried to declare myItem as Outlook.ContactItem but this fails also...
something is wrong with the Garbage Collector... its not collecting
anything...
I also tried to start the Garbage Collector before that function and
after
the 245´s Item but it fails also.

are there maybe any working examples how to successfully
releaseComObjects
under an "exchange folder Items cycle"?

greets HelixX23

:

I can only guess tah t since you declare myItem as a generic Object,
teh
compiler QI's it for IDispatch every timee and does not release the
reference.
Can you try to declare it as ContactItem (assuming you do not have any
DLs
in that folder)?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

Hi...
Thanks for the reply Dmitry.

something is getting better...
the failure changed the line... :)
maybe it is not explicitely declared enough??

Code:
Imports System.Runtime.InteropServices
Imports Microsoft.Office.Core
Imports Outlook = Microsoft.Office.Interop.Outlook
Imports Microsoft.VisualBasic.Information

Public Class SearchAndReplace

Public myContactFolder As Outlook.MAPIFolder '=
Outlook.Application.GetNamespace("MAPI").folders("Öffetnliche
Ordner").folders("Alle Öffentlichen Ordner").folders("EUKON
Kontakte")
Private Sub btnPickOLFolder_Click(ByVal sender As System.Object,
ByVal
e
As System.EventArgs) Handles btnPickOLFolder.Click
Dim myOlApp As Outlook.Application =
CreateObject("Outlook.Application")
Dim myNamespace As Outlook.NameSpace =
myOlApp.GetNamespace("MAPI")
myContactFolder = myNamespace.PickFolder
If myContactFolder Is Nothing Then MsgBox("Sie haben keinen
Ordner
ausgewählt...?") : Exit Sub
txtOutlookFolder.Text = myContactFolder.FolderPath
End Sub

Private Sub btnSearchAll_Click(ByVal sender As System.Object,
ByVal
e
As
System.EventArgs) Handles btnSearchAll.Click
SearchALL()
End Sub

Private Sub SearchALL()
Dim myContactFolderItems As Outlook.Items =
myContactFolder.Items
Dim myItem As Object
Dim countItems As Integer = myContactFolderItems.Count
Dim myItemCategories As Object
Dim myItemFileAs As String

pgbSearchAndReplace.Enabled = True
pgbSearchAndReplace.Minimum = 0
pgbSearchAndReplace.Maximum = myContactFolder.Items.Count
pgbSearchAndReplace.Value = 0

MsgBox("Items.Count = " & countItems)

For i As Integer = 1 To countItems
pgbSearchAndReplace.Value = i ' my Progressbar

Debug.Print("Memory: " & GC.GetTotalMemory(True))
Debug.Print("generate Object")

myContactFolderItems = myContactFolder.Items
myItem = myContactFolderItems.Item(i) ' old failure has
passed
when "i  as int = 250"
myItemCategories = myItem.Categories ' new failure drops
here...
? not explicite enough?
myItemFileAs = myItem.FileAs.ToString

Debug.Print("Memory: " & GC.GetTotalMemory(True))

If TypeName(myItem) = "ContactItem" Then

If InStr(myItemCategories, txtSearch.Text,
CompareMethod.Text) Then
lstSearchResults.Items.Add(myItemFileAs & " - " &
myItemCategories)
End If
Else
MsgBox(TypeName(myItem))
End If

' Try to release ComObjects
ReleaseMyComObject(myItem)
ReleaseMyComObject(myContactFolderItems)
ReleaseMyComObject(myItemCategories)
ReleaseMyComObject(myItemFileAs)

If i Mod 245 = 0 Then
' --- GC starten
Debug.Print("Memory: " & GC.GetTotalMemory(True))
Debug.Print("GC starting")
GC.Collect()
GC.WaitForPendingFinalizers()
Debug.Print("Garbage collected")
Debug.Print("Memory: " & GC.GetTotalMemory(True))
End If

Next i

pgbSearchAndReplace.Value = 0
pgbSearchAndReplace.Enabled = False
End Sub

Public Sub ReleaseMyComObject(ByVal myCOMObject As Object)
Try
If Not myCOMObject Is Nothing Then
Do
If Marshal.ReleaseComObject(myCOMObject) = 0 Then
Debug.Print("Object released")
Exit Do
End If
Loop
End If
Catch ex As Exception
Debug.Print("Can't release ComObject" & vbCrLf &
ex.Message)
End Try
myCOMObject = Nothing
End Sub
End Class

What am i doing wrong?

greets HelixX23

:

Do not use multiple dot notation (e.g.
myContactFolder.Items.Count)
as
the
compiler creates implicit variables to hold the intermediate
results.
Use explicit variables and explicitly release them.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

In my Environment Marshal is not defined

I´m using Visual Studio 2005 VBA Outlook Addin to get this
working..

So i used the
System.Runtime.InteropServices.Marshal.ReleaseComObject
referenced function to release my COM Object...

but.. it does not work..

Code:
For i As Integer = 1 To myContactFolder.Items.Count
Debug.Print("generate Object")
Debug.Print("Speicher: " & GC.GetTotalMemory(True))
Dim myItem As Outlook.ContactItem =
myContactFolder.Items.Item(i) ' here drops the failure when "i"
reaches
"249
as int"
Debug.Print("Speicher: " & GC.GetTotalMemory(True))
If Microsoft.VisualBasic.Information.TypeName(myItem)
=
"ContactItem" Then
If InStr(myItem.Categories, txtSearch.Text,
CompareMethod.Text) Then

lstSearchResults.Items.Add(myItem.FileAs.ToString
&
" -
" & myItem.Categories)
End If
Else

Debug.Print(Microsoft.VisualBasic.Information.TypeName(myItem))
End If

' Try to Release ComObject
Try

System.Runtime.InteropServices.Marshal.ReleaseComObject(myItem)
Catch ex As Exception
Debug.Print("Can't release ComObject" & vbCrLf &
ex.Message)
End Try

myItem = Nothing

If i Mod 245 = 0 Then
' --- GC starten
GC.Collect()
GC.WaitForPendingFinalizers()
End If

Next i


:

Marshal.ReleaseComObject(myItem);

// followed by

GC.Collect();
GC.WaitForPendingFinalizers();




Maybe GC does not feel to release my objects...

"4. GC will release the COM objects whenever it feels like it,
which
may
be
minutes later. And COM subsystem does not handle "all of
that",
GC
and
the
object itself do.
"
"When GC feels it is time to release it (whenever that might
be),"

What can i do to force him to release myItem?
 
G

Guest

Hi...
thanks for reply :)

Sure... i tried it twice...
once with myItem as Outlook.ContactItem adn once with myItem as Object...
both fails... :( dont know why..

greetz HelixX²³

Dmitry Streblechenko said:
Did you remember to declare myItem as Outlook.ContactItem rather than the
generic Object?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

HelixX23 said:
Hi...

So i tried this... but it fails also... :(

"
myContactFolderItems = myContactFolder.Items
For i As Integer = 1 To myContactFolderItems.Count
myItem = myContactFolderItems.Item(i)
Marshal.ReleaseComObject(myItem)
Next i
"

i = 250 as integer

Das COM-Objekt des Typs "System.__ComObject" kann nicht in den
Schnittstellentyp "Microsoft.Office.Interop.Outlook.ContactItem"
umgewandelt
werden. Dieser Vorgang konnte nicht durchgeführt werden, da der
QueryInterface-Aufruf an die COM-Komponente für die Schnittstelle mit der
IID
"{00063021-0000-0000-C000-000000000046}" aufgrund des folgenden Fehlers
nicht
durchgeführt werden konnte: Schnittstelle nicht unterstützt (Ausnahme von
HRESULT: 0x80004002 (E_NOINTERFACE)).

What am i doing wrong?

Maybe i should release the whole Outlook Application from my harddrive...
(joke) :)

greets HelixX23


Dmitry Streblechenko said:
Try to remove everything from the loop and see if it runs Ok or fails
with
the same problem.

myContactFolderItems = myContactFolder.Items
For i As Integer = 1 To myContactFolderItems.Count
myItem = myContactFolderItems.Item(i)
Marshal.ReleaseComObject(myItem)
Next i

Also, why do you keep recalculating
myContactFolderItems = myContactFolder.Items
*inside* the loop?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

I tried to declare myItem as Outlook.ContactItem but this fails also...
something is wrong with the Garbage Collector... its not collecting
anything...
I also tried to start the Garbage Collector before that function and
after
the 245´s Item but it fails also.

are there maybe any working examples how to successfully
releaseComObjects
under an "exchange folder Items cycle"?

greets HelixX23

:

I can only guess tah t since you declare myItem as a generic Object,
teh
compiler QI's it for IDispatch every timee and does not release the
reference.
Can you try to declare it as ContactItem (assuming you do not have any
DLs
in that folder)?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

Hi...
Thanks for the reply Dmitry.

something is getting better...
the failure changed the line... :)
maybe it is not explicitely declared enough??

Code:
Imports System.Runtime.InteropServices
Imports Microsoft.Office.Core
Imports Outlook = Microsoft.Office.Interop.Outlook
Imports Microsoft.VisualBasic.Information

Public Class SearchAndReplace

Public myContactFolder As Outlook.MAPIFolder '=
Outlook.Application.GetNamespace("MAPI").folders("Öffetnliche
Ordner").folders("Alle Öffentlichen Ordner").folders("EUKON
Kontakte")
Private Sub btnPickOLFolder_Click(ByVal sender As System.Object,
ByVal
e
As System.EventArgs) Handles btnPickOLFolder.Click
Dim myOlApp As Outlook.Application =
CreateObject("Outlook.Application")
Dim myNamespace As Outlook.NameSpace =
myOlApp.GetNamespace("MAPI")
myContactFolder = myNamespace.PickFolder
If myContactFolder Is Nothing Then MsgBox("Sie haben keinen
Ordner
ausgewählt...?") : Exit Sub
txtOutlookFolder.Text = myContactFolder.FolderPath
End Sub

Private Sub btnSearchAll_Click(ByVal sender As System.Object,
ByVal
e
As
System.EventArgs) Handles btnSearchAll.Click
SearchALL()
End Sub

Private Sub SearchALL()
Dim myContactFolderItems As Outlook.Items =
myContactFolder.Items
Dim myItem As Object
Dim countItems As Integer = myContactFolderItems.Count
Dim myItemCategories As Object
Dim myItemFileAs As String

pgbSearchAndReplace.Enabled = True
pgbSearchAndReplace.Minimum = 0
pgbSearchAndReplace.Maximum = myContactFolder.Items.Count
pgbSearchAndReplace.Value = 0

MsgBox("Items.Count = " & countItems)

For i As Integer = 1 To countItems
pgbSearchAndReplace.Value = i ' my Progressbar

Debug.Print("Memory: " & GC.GetTotalMemory(True))
Debug.Print("generate Object")

myContactFolderItems = myContactFolder.Items
myItem = myContactFolderItems.Item(i) ' old failure has
passed
when "i  as int = 250"
myItemCategories = myItem.Categories ' new failure drops
here...
? not explicite enough?
myItemFileAs = myItem.FileAs.ToString

Debug.Print("Memory: " & GC.GetTotalMemory(True))

If TypeName(myItem) = "ContactItem" Then

If InStr(myItemCategories, txtSearch.Text,
CompareMethod.Text) Then
lstSearchResults.Items.Add(myItemFileAs & " - " &
myItemCategories)
End If
Else
MsgBox(TypeName(myItem))
End If

' Try to release ComObjects
ReleaseMyComObject(myItem)
ReleaseMyComObject(myContactFolderItems)
ReleaseMyComObject(myItemCategories)
ReleaseMyComObject(myItemFileAs)

If i Mod 245 = 0 Then
' --- GC starten
Debug.Print("Memory: " & GC.GetTotalMemory(True))
Debug.Print("GC starting")
GC.Collect()
GC.WaitForPendingFinalizers()
Debug.Print("Garbage collected")
Debug.Print("Memory: " & GC.GetTotalMemory(True))
End If

Next i

pgbSearchAndReplace.Value = 0
pgbSearchAndReplace.Enabled = False
End Sub

Public Sub ReleaseMyComObject(ByVal myCOMObject As Object)
Try
If Not myCOMObject Is Nothing Then
Do
If Marshal.ReleaseComObject(myCOMObject) = 0 Then
Debug.Print("Object released")
Exit Do
End If
Loop
End If
Catch ex As Exception
Debug.Print("Can't release ComObject" & vbCrLf &
ex.Message)
End Try
myCOMObject = Nothing
End Sub
End Class

What am i doing wrong?

greets HelixX23

:

Do not use multiple dot notation (e.g.
myContactFolder.Items.Count)
as
the
compiler creates implicit variables to hold the intermediate
results.
Use explicit variables and explicitly release them.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

In my Environment Marshal is not defined

I´m using Visual Studio 2005 VBA Outlook Addin to get this
working..

So i used the
System.Runtime.InteropServices.Marshal.ReleaseComObject
referenced function to release my COM Object...

but.. it does not work..

Code:
For i As Integer = 1 To myContactFolder.Items.Count
Debug.Print("generate Object")
Debug.Print("Speicher: " & GC.GetTotalMemory(True))
Dim myItem As Outlook.ContactItem =
myContactFolder.Items.Item(i) ' here drops the failure when "i"
reaches
"249
as int"
Debug.Print("Speicher: " & GC.GetTotalMemory(True))
If Microsoft.VisualBasic.Information.TypeName(myItem)
=
"ContactItem" Then
If InStr(myItem.Categories, txtSearch.Text,
CompareMethod.Text) Then

lstSearchResults.Items.Add(myItem.FileAs.ToString
&
" -
" & myItem.Categories)
End If
Else

Debug.Print(Microsoft.VisualBasic.Information.TypeName(myItem))
End If

' Try to Release ComObject
Try

System.Runtime.InteropServices.Marshal.ReleaseComObject(myItem)
Catch ex As Exception
Debug.Print("Can't release ComObject" & vbCrLf &
ex.Message)
End Try

myItem = Nothing

If i Mod 245 = 0 Then
' --- GC starten
GC.Collect()
GC.WaitForPendingFinalizers()
End If

Next i
 
D

Dmitry Streblechenko

And do you have *only* contacts in that older, no DLs?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

HelixX23 said:
Hi...
thanks for reply :)

Sure... i tried it twice...
once with myItem as Outlook.ContactItem adn once with myItem as Object...
both fails... :( dont know why..

greetz HelixX²³

Dmitry Streblechenko said:
Did you remember to declare myItem as Outlook.ContactItem rather than the
generic Object?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

HelixX23 said:
Hi...

So i tried this... but it fails also... :(

"
myContactFolderItems = myContactFolder.Items
For i As Integer = 1 To myContactFolderItems.Count
myItem = myContactFolderItems.Item(i)
Marshal.ReleaseComObject(myItem)
Next i
"

i = 250 as integer

Das COM-Objekt des Typs "System.__ComObject" kann nicht in den
Schnittstellentyp "Microsoft.Office.Interop.Outlook.ContactItem"
umgewandelt
werden. Dieser Vorgang konnte nicht durchgeführt werden, da der
QueryInterface-Aufruf an die COM-Komponente für die Schnittstelle mit
der
IID
"{00063021-0000-0000-C000-000000000046}" aufgrund des folgenden Fehlers
nicht
durchgeführt werden konnte: Schnittstelle nicht unterstützt (Ausnahme
von
HRESULT: 0x80004002 (E_NOINTERFACE)).

What am i doing wrong?

Maybe i should release the whole Outlook Application from my
harddrive...
(joke) :)

greets HelixX23


:

Try to remove everything from the loop and see if it runs Ok or fails
with
the same problem.

myContactFolderItems = myContactFolder.Items
For i As Integer = 1 To myContactFolderItems.Count
myItem = myContactFolderItems.Item(i)
Marshal.ReleaseComObject(myItem)
Next i

Also, why do you keep recalculating
myContactFolderItems = myContactFolder.Items
*inside* the loop?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

I tried to declare myItem as Outlook.ContactItem but this fails
also...
something is wrong with the Garbage Collector... its not collecting
anything...
I also tried to start the Garbage Collector before that function and
after
the 245´s Item but it fails also.

are there maybe any working examples how to successfully
releaseComObjects
under an "exchange folder Items cycle"?

greets HelixX23

:

I can only guess tah t since you declare myItem as a generic
Object,
teh
compiler QI's it for IDispatch every timee and does not release the
reference.
Can you try to declare it as ContactItem (assuming you do not have
any
DLs
in that folder)?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

Hi...
Thanks for the reply Dmitry.

something is getting better...
the failure changed the line... :)
maybe it is not explicitely declared enough??

Code:
Imports System.Runtime.InteropServices
Imports Microsoft.Office.Core
Imports Outlook = Microsoft.Office.Interop.Outlook
Imports Microsoft.VisualBasic.Information

Public Class SearchAndReplace

Public myContactFolder As Outlook.MAPIFolder '=
Outlook.Application.GetNamespace("MAPI").folders("Öffetnliche
Ordner").folders("Alle Öffentlichen Ordner").folders("EUKON
Kontakte")
Private Sub btnPickOLFolder_Click(ByVal sender As
System.Object,
ByVal
e
As System.EventArgs) Handles btnPickOLFolder.Click
Dim myOlApp As Outlook.Application =
CreateObject("Outlook.Application")
Dim myNamespace As Outlook.NameSpace =
myOlApp.GetNamespace("MAPI")
myContactFolder = myNamespace.PickFolder
If myContactFolder Is Nothing Then MsgBox("Sie haben
keinen
Ordner
ausgewählt...?") : Exit Sub
txtOutlookFolder.Text = myContactFolder.FolderPath
End Sub

Private Sub btnSearchAll_Click(ByVal sender As System.Object,
ByVal
e
As
System.EventArgs) Handles btnSearchAll.Click
SearchALL()
End Sub

Private Sub SearchALL()
Dim myContactFolderItems As Outlook.Items =
myContactFolder.Items
Dim myItem As Object
Dim countItems As Integer = myContactFolderItems.Count
Dim myItemCategories As Object
Dim myItemFileAs As String

pgbSearchAndReplace.Enabled = True
pgbSearchAndReplace.Minimum = 0
pgbSearchAndReplace.Maximum = myContactFolder.Items.Count
pgbSearchAndReplace.Value = 0

MsgBox("Items.Count = " & countItems)

For i As Integer = 1 To countItems
pgbSearchAndReplace.Value = i ' my Progressbar

Debug.Print("Memory: " & GC.GetTotalMemory(True))
Debug.Print("generate Object")

myContactFolderItems = myContactFolder.Items
myItem = myContactFolderItems.Item(i) ' old failure
has
passed
when "i  as int = 250"
myItemCategories = myItem.Categories ' new failure
drops
here...
? not explicite enough?
myItemFileAs = myItem.FileAs.ToString

Debug.Print("Memory: " & GC.GetTotalMemory(True))

If TypeName(myItem) = "ContactItem" Then

If InStr(myItemCategories, txtSearch.Text,
CompareMethod.Text) Then
lstSearchResults.Items.Add(myItemFileAs & " -
" &
myItemCategories)
End If
Else
MsgBox(TypeName(myItem))
End If

' Try to release ComObjects
ReleaseMyComObject(myItem)
ReleaseMyComObject(myContactFolderItems)
ReleaseMyComObject(myItemCategories)
ReleaseMyComObject(myItemFileAs)

If i Mod 245 = 0 Then
' --- GC starten
Debug.Print("Memory: " & GC.GetTotalMemory(True))
Debug.Print("GC starting")
GC.Collect()
GC.WaitForPendingFinalizers()
Debug.Print("Garbage collected")
Debug.Print("Memory: " & GC.GetTotalMemory(True))
End If

Next i

pgbSearchAndReplace.Value = 0
pgbSearchAndReplace.Enabled = False
End Sub

Public Sub ReleaseMyComObject(ByVal myCOMObject As Object)
Try
If Not myCOMObject Is Nothing Then
Do
If Marshal.ReleaseComObject(myCOMObject) = 0
Then
Debug.Print("Object released")
Exit Do
End If
Loop
End If
Catch ex As Exception
Debug.Print("Can't release ComObject" & vbCrLf &
ex.Message)
End Try
myCOMObject = Nothing
End Sub
End Class

What am i doing wrong?

greets HelixX23

:

Do not use multiple dot notation (e.g.
myContactFolder.Items.Count)
as
the
compiler creates implicit variables to hold the intermediate
results.
Use explicit variables and explicitly release them.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

In my Environment Marshal is not defined

I´m using Visual Studio 2005 VBA Outlook Addin to get this
working..

So i used the
System.Runtime.InteropServices.Marshal.ReleaseComObject
referenced function to release my COM Object...

but.. it does not work..

Code:
For i As Integer = 1 To myContactFolder.Items.Count
Debug.Print("generate Object")
Debug.Print("Speicher: " & GC.GetTotalMemory(True))
Dim myItem As Outlook.ContactItem =
myContactFolder.Items.Item(i) ' here drops the failure when
"i"
reaches
"249
as int"
Debug.Print("Speicher: " & GC.GetTotalMemory(True))
If
Microsoft.VisualBasic.Information.TypeName(myItem)
=
"ContactItem" Then
If InStr(myItem.Categories, txtSearch.Text,
CompareMethod.Text) Then

lstSearchResults.Items.Add(myItem.FileAs.ToString
&
" -
" & myItem.Categories)
End If
Else

Debug.Print(Microsoft.VisualBasic.Information.TypeName(myItem))
End If

' Try to Release ComObject
Try

System.Runtime.InteropServices.Marshal.ReleaseComObject(myItem)
Catch ex As Exception
Debug.Print("Can't release ComObject" & vbCrLf
&
ex.Message)
End Try

myItem = Nothing

If i Mod 245 = 0 Then
' --- GC starten
GC.Collect()
GC.WaitForPendingFinalizers()
End If

Next i
 
G

Guest

Yes...

There are only ContactItems in myContactFolder.
There are no Distributionlists in there... the only thing is... there are
subfolders in myContactFolder but subfolders are in the
myContactFolder.Folders() Collection and not in the myContactFolder.Items
Collection.
And all Items are at the same customForm (IPM.Contact.myCustomName)

Dmitry Streblechenko said:
And do you have *only* contacts in that older, no DLs?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

HelixX23 said:
Hi...
thanks for reply :)

Sure... i tried it twice...
once with myItem as Outlook.ContactItem adn once with myItem as Object...
both fails... :( dont know why..

greetz HelixX²³

Dmitry Streblechenko said:
Did you remember to declare myItem as Outlook.ContactItem rather than the
generic Object?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

Hi...

So i tried this... but it fails also... :(

"
myContactFolderItems = myContactFolder.Items
For i As Integer = 1 To myContactFolderItems.Count
myItem = myContactFolderItems.Item(i)
Marshal.ReleaseComObject(myItem)
Next i
"

i = 250 as integer

Das COM-Objekt des Typs "System.__ComObject" kann nicht in den
Schnittstellentyp "Microsoft.Office.Interop.Outlook.ContactItem"
umgewandelt
werden. Dieser Vorgang konnte nicht durchgeführt werden, da der
QueryInterface-Aufruf an die COM-Komponente für die Schnittstelle mit
der
IID
"{00063021-0000-0000-C000-000000000046}" aufgrund des folgenden Fehlers
nicht
durchgeführt werden konnte: Schnittstelle nicht unterstützt (Ausnahme
von
HRESULT: 0x80004002 (E_NOINTERFACE)).

What am i doing wrong?

Maybe i should release the whole Outlook Application from my
harddrive...
(joke) :)

greets HelixX23


:

Try to remove everything from the loop and see if it runs Ok or fails
with
the same problem.

myContactFolderItems = myContactFolder.Items
For i As Integer = 1 To myContactFolderItems.Count
myItem = myContactFolderItems.Item(i)
Marshal.ReleaseComObject(myItem)
Next i

Also, why do you keep recalculating
myContactFolderItems = myContactFolder.Items
*inside* the loop?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

I tried to declare myItem as Outlook.ContactItem but this fails
also...
something is wrong with the Garbage Collector... its not collecting
anything...
I also tried to start the Garbage Collector before that function and
after
the 245´s Item but it fails also.

are there maybe any working examples how to successfully
releaseComObjects
under an "exchange folder Items cycle"?

greets HelixX23

:

I can only guess tah t since you declare myItem as a generic
Object,
teh
compiler QI's it for IDispatch every timee and does not release the
reference.
Can you try to declare it as ContactItem (assuming you do not have
any
DLs
in that folder)?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

Hi...
Thanks for the reply Dmitry.

something is getting better...
the failure changed the line... :)
maybe it is not explicitely declared enough??

Code:
Imports System.Runtime.InteropServices
Imports Microsoft.Office.Core
Imports Outlook = Microsoft.Office.Interop.Outlook
Imports Microsoft.VisualBasic.Information

Public Class SearchAndReplace

Public myContactFolder As Outlook.MAPIFolder '=
Outlook.Application.GetNamespace("MAPI").folders("Öffetnliche
Ordner").folders("Alle Öffentlichen Ordner").folders("EUKON
Kontakte")
Private Sub btnPickOLFolder_Click(ByVal sender As
System.Object,
ByVal
e
As System.EventArgs) Handles btnPickOLFolder.Click
Dim myOlApp As Outlook.Application =
CreateObject("Outlook.Application")
Dim myNamespace As Outlook.NameSpace =
myOlApp.GetNamespace("MAPI")
myContactFolder = myNamespace.PickFolder
If myContactFolder Is Nothing Then MsgBox("Sie haben
keinen
Ordner
ausgewählt...?") : Exit Sub
txtOutlookFolder.Text = myContactFolder.FolderPath
End Sub

Private Sub btnSearchAll_Click(ByVal sender As System.Object,
ByVal
e
As
System.EventArgs) Handles btnSearchAll.Click
SearchALL()
End Sub

Private Sub SearchALL()
Dim myContactFolderItems As Outlook.Items =
myContactFolder.Items
Dim myItem As Object
Dim countItems As Integer = myContactFolderItems.Count
Dim myItemCategories As Object
Dim myItemFileAs As String

pgbSearchAndReplace.Enabled = True
pgbSearchAndReplace.Minimum = 0
pgbSearchAndReplace.Maximum = myContactFolder.Items.Count
pgbSearchAndReplace.Value = 0

MsgBox("Items.Count = " & countItems)

For i As Integer = 1 To countItems
pgbSearchAndReplace.Value = i ' my Progressbar

Debug.Print("Memory: " & GC.GetTotalMemory(True))
Debug.Print("generate Object")

myContactFolderItems = myContactFolder.Items
myItem = myContactFolderItems.Item(i) ' old failure
has
passed
when "i  as int = 250"
myItemCategories = myItem.Categories ' new failure
drops
here...
? not explicite enough?
myItemFileAs = myItem.FileAs.ToString

Debug.Print("Memory: " & GC.GetTotalMemory(True))

If TypeName(myItem) = "ContactItem" Then

If InStr(myItemCategories, txtSearch.Text,
CompareMethod.Text) Then
lstSearchResults.Items.Add(myItemFileAs & " -
" &
myItemCategories)
End If
Else
MsgBox(TypeName(myItem))
End If

' Try to release ComObjects
ReleaseMyComObject(myItem)
ReleaseMyComObject(myContactFolderItems)
ReleaseMyComObject(myItemCategories)
ReleaseMyComObject(myItemFileAs)

If i Mod 245 = 0 Then
' --- GC starten
Debug.Print("Memory: " & GC.GetTotalMemory(True))
Debug.Print("GC starting")
GC.Collect()
GC.WaitForPendingFinalizers()
Debug.Print("Garbage collected")
Debug.Print("Memory: " & GC.GetTotalMemory(True))
End If

Next i

pgbSearchAndReplace.Value = 0
pgbSearchAndReplace.Enabled = False
End Sub

Public Sub ReleaseMyComObject(ByVal myCOMObject As Object)
Try
If Not myCOMObject Is Nothing Then
Do
If Marshal.ReleaseComObject(myCOMObject) = 0
Then
Debug.Print("Object released")
Exit Do
End If
Loop
End If
Catch ex As Exception
Debug.Print("Can't release ComObject" & vbCrLf &
ex.Message)
End Try
myCOMObject = Nothing
End Sub
End Class

What am i doing wrong?

greets HelixX23

:

Do not use multiple dot notation (e.g.
myContactFolder.Items.Count)
as
the
compiler creates implicit variables to hold the intermediate
results.
Use explicit variables and explicitly release them.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

In my Environment Marshal is not defined

I´m using Visual Studio 2005 VBA Outlook Addin to get this
working..

So i used the
System.Runtime.InteropServices.Marshal.ReleaseComObject
referenced function to release my COM Object...

but.. it does not work..

Code:
For i As Integer = 1 To myContactFolder.Items.Count
Debug.Print("generate Object")
Debug.Print("Speicher: " & GC.GetTotalMemory(True))
Dim myItem As Outlook.ContactItem =
myContactFolder.Items.Item(i) ' here drops the failure when
"i"
reaches
"249
as int"
Debug.Print("Speicher: " & GC.GetTotalMemory(True))
If
Microsoft.VisualBasic.Information.TypeName(myItem)
=
"ContactItem" Then[/QUOTE][/QUOTE][/QUOTE]
 
D

Dmitry Streblechenko

Hmmm... I don't know. Somethign else is going on that is causing .Net to
hold on to the items.
Have you tried to call GC.Collect() inside the loop?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

HelixX23 said:
Yes...

There are only ContactItems in myContactFolder.
There are no Distributionlists in there... the only thing is... there are
subfolders in myContactFolder but subfolders are in the
myContactFolder.Folders() Collection and not in the myContactFolder.Items
Collection.
And all Items are at the same customForm (IPM.Contact.myCustomName)

Dmitry Streblechenko said:
And do you have *only* contacts in that older, no DLs?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

HelixX23 said:
Hi...
thanks for reply :)

Sure... i tried it twice...
once with myItem as Outlook.ContactItem adn once with myItem as
Object...
both fails... :( dont know why..

greetz HelixX²³

:

Did you remember to declare myItem as Outlook.ContactItem rather than
the
generic Object?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

Hi...

So i tried this... but it fails also... :(

"
myContactFolderItems = myContactFolder.Items
For i As Integer = 1 To myContactFolderItems.Count
myItem = myContactFolderItems.Item(i)
Marshal.ReleaseComObject(myItem)
Next i
"

i = 250 as integer

Das COM-Objekt des Typs "System.__ComObject" kann nicht in den
Schnittstellentyp "Microsoft.Office.Interop.Outlook.ContactItem"
umgewandelt
werden. Dieser Vorgang konnte nicht durchgeführt werden, da der
QueryInterface-Aufruf an die COM-Komponente für die Schnittstelle
mit
der
IID
"{00063021-0000-0000-C000-000000000046}" aufgrund des folgenden
Fehlers
nicht
durchgeführt werden konnte: Schnittstelle nicht unterstützt
(Ausnahme
von
HRESULT: 0x80004002 (E_NOINTERFACE)).

What am i doing wrong?

Maybe i should release the whole Outlook Application from my
harddrive...
(joke) :)

greets HelixX23


:

Try to remove everything from the loop and see if it runs Ok or
fails
with
the same problem.

myContactFolderItems = myContactFolder.Items
For i As Integer = 1 To myContactFolderItems.Count
myItem = myContactFolderItems.Item(i)
Marshal.ReleaseComObject(myItem)
Next i

Also, why do you keep recalculating
myContactFolderItems = myContactFolder.Items
*inside* the loop?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

I tried to declare myItem as Outlook.ContactItem but this fails
also...
something is wrong with the Garbage Collector... its not
collecting
anything...
I also tried to start the Garbage Collector before that function
and
after
the 245´s Item but it fails also.

are there maybe any working examples how to successfully
releaseComObjects
under an "exchange folder Items cycle"?

greets HelixX23

:

I can only guess tah t since you declare myItem as a generic
Object,
teh
compiler QI's it for IDispatch every timee and does not release
the
reference.
Can you try to declare it as ContactItem (assuming you do not
have
any
DLs
in that folder)?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

Hi...
Thanks for the reply Dmitry.

something is getting better...
the failure changed the line... :)
maybe it is not explicitely declared enough??

Code:
Imports System.Runtime.InteropServices
Imports Microsoft.Office.Core
Imports Outlook = Microsoft.Office.Interop.Outlook
Imports Microsoft.VisualBasic.Information

Public Class SearchAndReplace

Public myContactFolder As Outlook.MAPIFolder '=
Outlook.Application.GetNamespace("MAPI").folders("Öffetnliche
Ordner").folders("Alle Öffentlichen Ordner").folders("EUKON
Kontakte")
Private Sub btnPickOLFolder_Click(ByVal sender As
System.Object,
ByVal
e
As System.EventArgs) Handles btnPickOLFolder.Click
Dim myOlApp As Outlook.Application =
CreateObject("Outlook.Application")
Dim myNamespace As Outlook.NameSpace =
myOlApp.GetNamespace("MAPI")
myContactFolder = myNamespace.PickFolder
If myContactFolder Is Nothing Then MsgBox("Sie haben
keinen
Ordner
ausgewählt...?") : Exit Sub
txtOutlookFolder.Text = myContactFolder.FolderPath
End Sub

Private Sub btnSearchAll_Click(ByVal sender As
System.Object,
ByVal
e
As
System.EventArgs) Handles btnSearchAll.Click
SearchALL()
End Sub

Private Sub SearchALL()
Dim myContactFolderItems As Outlook.Items =
myContactFolder.Items
Dim myItem As Object
Dim countItems As Integer = myContactFolderItems.Count
Dim myItemCategories As Object
Dim myItemFileAs As String

pgbSearchAndReplace.Enabled = True
pgbSearchAndReplace.Minimum = 0
pgbSearchAndReplace.Maximum =
myContactFolder.Items.Count
pgbSearchAndReplace.Value = 0

MsgBox("Items.Count = " & countItems)

For i As Integer = 1 To countItems
pgbSearchAndReplace.Value = i ' my Progressbar

Debug.Print("Memory: " & GC.GetTotalMemory(True))
Debug.Print("generate Object")

myContactFolderItems = myContactFolder.Items
myItem = myContactFolderItems.Item(i) ' old failure
has
passed
when "i  as int = 250"
myItemCategories = myItem.Categories ' new failure
drops
here...
? not explicite enough?
myItemFileAs = myItem.FileAs.ToString

Debug.Print("Memory: " & GC.GetTotalMemory(True))

If TypeName(myItem) = "ContactItem" Then

If InStr(myItemCategories, txtSearch.Text,
CompareMethod.Text) Then
lstSearchResults.Items.Add(myItemFileAs &
" -
" &
myItemCategories)
End If
Else
MsgBox(TypeName(myItem))
End If

' Try to release ComObjects
ReleaseMyComObject(myItem)
ReleaseMyComObject(myContactFolderItems)
ReleaseMyComObject(myItemCategories)
ReleaseMyComObject(myItemFileAs)

If i Mod 245 = 0 Then
' --- GC starten
Debug.Print("Memory: " &
GC.GetTotalMemory(True))
Debug.Print("GC starting")
GC.Collect()
GC.WaitForPendingFinalizers()
Debug.Print("Garbage collected")
Debug.Print("Memory: " &
GC.GetTotalMemory(True))
End If

Next i

pgbSearchAndReplace.Value = 0
pgbSearchAndReplace.Enabled = False
End Sub

Public Sub ReleaseMyComObject(ByVal myCOMObject As Object)
Try
If Not myCOMObject Is Nothing Then
Do
If Marshal.ReleaseComObject(myCOMObject) =
0
Then
Debug.Print("Object released")
Exit Do
End If
Loop
End If
Catch ex As Exception
Debug.Print("Can't release ComObject" & vbCrLf &
ex.Message)
End Try
myCOMObject = Nothing
End Sub
End Class

What am i doing wrong?

greets HelixX23

:

Do not use multiple dot notation (e.g.
myContactFolder.Items.Count)
as
the
compiler creates implicit variables to hold the intermediate
results.
Use explicit variables and explicitly release them.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

message
In my Environment Marshal is not defined

I´m using Visual Studio 2005 VBA Outlook Addin to get this
working..

So i used the
System.Runtime.InteropServices.Marshal.ReleaseComObject
referenced function to release my COM Object...

but.. it does not work..

Code:
For i As Integer = 1 To myContactFolder.Items.Count
Debug.Print("generate Object")
Debug.Print("Speicher: " &
GC.GetTotalMemory(True))
Dim myItem As Outlook.ContactItem =
myContactFolder.Items.Item(i) ' here drops the failure when
"i"
reaches
"249
as int"
Debug.Print("Speicher: " &
GC.GetTotalMemory(True))
If
Microsoft.VisualBasic.Information.TypeName(myItem)
=
"ContactItem" Then[/QUOTE][/QUOTE][/QUOTE]
 
G

Guest

Hi...
thanks for reply...

Yes.
I tried to Collect Garbage inside the loop, before loop and inside, and
after every 245 items, but none of this works... :(

greetz from germany
HelixX²³


Dmitry Streblechenko said:
Hmmm... I don't know. Somethign else is going on that is causing .Net to
hold on to the items.
Have you tried to call GC.Collect() inside the loop?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

HelixX23 said:
Yes...

There are only ContactItems in myContactFolder.
There are no Distributionlists in there... the only thing is... there are
subfolders in myContactFolder but subfolders are in the
myContactFolder.Folders() Collection and not in the myContactFolder.Items
Collection.
And all Items are at the same customForm (IPM.Contact.myCustomName)

Dmitry Streblechenko said:
And do you have *only* contacts in that older, no DLs?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

Hi...
thanks for reply :)

Sure... i tried it twice...
once with myItem as Outlook.ContactItem adn once with myItem as
Object...
both fails... :( dont know why..

greetz HelixX²³

:

Did you remember to declare myItem as Outlook.ContactItem rather than
the
generic Object?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

Hi...

So i tried this... but it fails also... :(

"
myContactFolderItems = myContactFolder.Items
For i As Integer = 1 To myContactFolderItems.Count
myItem = myContactFolderItems.Item(i)
Marshal.ReleaseComObject(myItem)
Next i
"

i = 250 as integer

Das COM-Objekt des Typs "System.__ComObject" kann nicht in den
Schnittstellentyp "Microsoft.Office.Interop.Outlook.ContactItem"
umgewandelt
werden. Dieser Vorgang konnte nicht durchgeführt werden, da der
QueryInterface-Aufruf an die COM-Komponente für die Schnittstelle
mit
der
IID
"{00063021-0000-0000-C000-000000000046}" aufgrund des folgenden
Fehlers
nicht
durchgeführt werden konnte: Schnittstelle nicht unterstützt
(Ausnahme
von
HRESULT: 0x80004002 (E_NOINTERFACE)).

What am i doing wrong?

Maybe i should release the whole Outlook Application from my
harddrive...
(joke) :)

greets HelixX23


:

Try to remove everything from the loop and see if it runs Ok or
fails
with
the same problem.

myContactFolderItems = myContactFolder.Items
For i As Integer = 1 To myContactFolderItems.Count
myItem = myContactFolderItems.Item(i)
Marshal.ReleaseComObject(myItem)
Next i

Also, why do you keep recalculating
myContactFolderItems = myContactFolder.Items
*inside* the loop?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

I tried to declare myItem as Outlook.ContactItem but this fails
also...
something is wrong with the Garbage Collector... its not
collecting
anything...
I also tried to start the Garbage Collector before that function
and
after
the 245´s Item but it fails also.

are there maybe any working examples how to successfully
releaseComObjects
under an "exchange folder Items cycle"?

greets HelixX23

:

I can only guess tah t since you declare myItem as a generic
Object,
teh
compiler QI's it for IDispatch every timee and does not release
the
reference.
Can you try to declare it as ContactItem (assuming you do not
have
any
DLs
in that folder)?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

Hi...
Thanks for the reply Dmitry.

something is getting better...
the failure changed the line... :)
maybe it is not explicitely declared enough??

Code:
Imports System.Runtime.InteropServices
Imports Microsoft.Office.Core
Imports Outlook = Microsoft.Office.Interop.Outlook
Imports Microsoft.VisualBasic.Information

Public Class SearchAndReplace

Public myContactFolder As Outlook.MAPIFolder '=
Outlook.Application.GetNamespace("MAPI").folders("Öffetnliche
Ordner").folders("Alle Öffentlichen Ordner").folders("EUKON
Kontakte")
Private Sub btnPickOLFolder_Click(ByVal sender As
System.Object,
ByVal
e
As System.EventArgs) Handles btnPickOLFolder.Click
Dim myOlApp As Outlook.Application =
CreateObject("Outlook.Application")
Dim myNamespace As Outlook.NameSpace =
myOlApp.GetNamespace("MAPI")
myContactFolder = myNamespace.PickFolder
If myContactFolder Is Nothing Then MsgBox("Sie haben
keinen
Ordner
ausgewählt...?") : Exit Sub
txtOutlookFolder.Text = myContactFolder.FolderPath
End Sub

Private Sub btnSearchAll_Click(ByVal sender As
System.Object,
ByVal
e
As
System.EventArgs) Handles btnSearchAll.Click
SearchALL()
End Sub

Private Sub SearchALL()
Dim myContactFolderItems As Outlook.Items =
myContactFolder.Items
Dim myItem As Object
Dim countItems As Integer = myContactFolderItems.Count
Dim myItemCategories As Object
Dim myItemFileAs As String

pgbSearchAndReplace.Enabled = True
pgbSearchAndReplace.Minimum = 0
pgbSearchAndReplace.Maximum =
myContactFolder.Items.Count
pgbSearchAndReplace.Value = 0

MsgBox("Items.Count = " & countItems)

For i As Integer = 1 To countItems
pgbSearchAndReplace.Value = i ' my Progressbar

Debug.Print("Memory: " & GC.GetTotalMemory(True))
Debug.Print("generate Object")

myContactFolderItems = myContactFolder.Items
myItem = myContactFolderItems.Item(i) ' old failure
has
passed
when "i  as int = 250"
myItemCategories = myItem.Categories ' new failure
drops
here...
? not explicite enough?
myItemFileAs = myItem.FileAs.ToString

Debug.Print("Memory: " & GC.GetTotalMemory(True))

If TypeName(myItem) = "ContactItem" Then

If InStr(myItemCategories, txtSearch.Text,
CompareMethod.Text) Then
lstSearchResults.Items.Add(myItemFileAs &
" -
" &
myItemCategories)
End If
Else
MsgBox(TypeName(myItem))
End If

' Try to release ComObjects
ReleaseMyComObject(myItem)
ReleaseMyComObject(myContactFolderItems)
ReleaseMyComObject(myItemCategories)
ReleaseMyComObject(myItemFileAs)

If i Mod 245 = 0 Then
' --- GC starten
Debug.Print("Memory: " &
GC.GetTotalMemory(True))
Debug.Print("GC starting")
GC.Collect()
GC.WaitForPendingFinalizers()
Debug.Print("Garbage collected")
Debug.Print("Memory: " &
GC.GetTotalMemory(True))
End If

Next i

pgbSearchAndReplace.Value = 0
pgbSearchAndReplace.Enabled = False
End Sub

Public Sub ReleaseMyComObject(ByVal myCOMObject As Object)
Try
If Not myCOMObject Is Nothing Then
Do
If Marshal.ReleaseComObject(myCOMObject) =
0
Then
Debug.Print("Object released")
Exit Do
End If
Loop
End If
Catch ex As Exception
Debug.Print("Can't release ComObject" & vbCrLf &
ex.Message)
End Try
myCOMObject = Nothing
End Sub
End Class

What am i doing wrong?

greets HelixX23

:

Do not use multiple dot notation (e.g.
myContactFolder.Items.Count)
as
 
P

Peter Marchert

Only an idea: Can you reproduce this behaviour on another machine and/
or with a different store? Perhaps the installation in a virtual pc
will help you to find out more.

Peter

--
Infos, workshops & soft-
ware for your Outlook®:
www.outlook-stuff.com


Hi...
thanks for reply...

Yes.
I tried to Collect Garbage inside the loop, before loop and inside, and
after every 245 items, but none of this works... :(

greetz from germany
HelixX²³



Dmitry Streblechenko said:
Hmmm... I don't know. Somethign else is going on that is causing .Net to
hold on to the items.
Have you tried to call GC.Collect() inside the loop?
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
HelixX23 said:
Yes...
There are only ContactItems in myContactFolder.
There are no Distributionlists in there... the only thing is... thereare
subfolders in myContactFolder but subfolders are in the
myContactFolder.Folders() Collection and not in the myContactFolder.Items
Collection.
And all Items are at the same customForm (IPM.Contact.myCustomName)
:
And do you have *only* contacts in that older, no DLs?
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
Hi...
thanks for reply :)
Sure... i tried it twice...
once with myItem as Outlook.ContactItem adn once with myItem as
Object...
both fails... :( dont know why..
greetz HelixX²³
:
Did you remember to declare myItem as Outlook.ContactItem rather than
the
generic Object?
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
Hi...
So i tried this... but it fails also... :(
"
myContactFolderItems = myContactFolder.Items
For i As Integer = 1 To myContactFolderItems.Count
myItem = myContactFolderItems.Item(i)
Marshal.ReleaseComObject(myItem)
Next i
"
i = 250 as integer
Das COM-Objekt des Typs "System.__ComObject" kann nicht in den
Schnittstellentyp "Microsoft.Office.Interop.Outlook.ContactItem"
umgewandelt
werden. Dieser Vorgang konnte nicht durchgeführt werden, da der
QueryInterface-Aufruf an die COM-Komponente für die Schnittstelle
mit
der
IID
"{00063021-0000-0000-C000-000000000046}" aufgrund des folgenden
Fehlers
nicht
durchgeführt werden konnte: Schnittstelle nicht unterstützt
(Ausnahme
von
HRESULT: 0x80004002 (E_NOINTERFACE)).
What am i doing wrong?
Maybe i should release the whole Outlook Application from my
harddrive...
(joke) :)
greets HelixX23
:
Try to remove everything from the loop and see if it runs Ok or
fails
with
the same problem.
myContactFolderItems = myContactFolder.Items
For i As Integer = 1 To myContactFolderItems.Count
myItem = myContactFolderItems.Item(i)
Marshal.ReleaseComObject(myItem)
Next i
Also, why do you keep recalculating
myContactFolderItems = myContactFolder.Items
*inside* the loop?
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
I tried to declare myItem as Outlook.ContactItem but this fails
also...
something is wrong with the Garbage Collector... its not
collecting
anything...
I also tried to start the Garbage Collector before that function
and
after
the 245´s Item but it fails also.
are there maybe any working examples how to successfully
releaseComObjects
under an "exchange folder Items cycle"?
greets HelixX23
:
I can only guess tah t since you declare myItem as a generic
Object,
teh
compiler QI's it for IDispatch every timee and does not release
the
reference.
Can you try to declare it as ContactItem (assuming you do not
have
any
DLs
in that folder)?
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
Hi...
Thanks for the reply Dmitry.
something is getting better...
the failure changed the line... :)
maybe it is not explicitely declared enough??
Code:
Imports System.Runtime.InteropServices
Imports Microsoft.Office.Core
Imports Outlook = Microsoft.Office.Interop.Outlook
Imports Microsoft.VisualBasic.Information 
Public Class SearchAndReplace 
Public myContactFolder As Outlook.MAPIFolder '=
Outlook.Application.GetNamespace("MAPI").folders("Öffetnliche
Ordner").folders("Alle Öffentlichen Ordner").folders("EUKON
Kontakte")
Private Sub btnPickOLFolder_Click(ByVal sender As
System.Object,
ByVal
e
As System.EventArgs) Handles btnPickOLFolder.Click
Dim myOlApp As Outlook.Application =
CreateObject("Outlook.Application")
Dim myNamespace As Outlook.NameSpace =
myOlApp.GetNamespace("MAPI")
myContactFolder = myNamespace.PickFolder
If myContactFolder Is Nothing Then MsgBox("Sie haben
keinen
Ordner
ausgewählt...?") : Exit Sub
txtOutlookFolder.Text = myContactFolder.FolderPath
End Sub 
Private Sub btnSearchAll_Click(ByVal sender As
System.Object,
ByVal
e
As
System.EventArgs) Handles btnSearchAll.Click
SearchALL()
End Sub 
Private Sub SearchALL()
Dim myContactFolderItems As Outlook.Items =
myContactFolder.Items
Dim myItem As Object
Dim countItems As Integer = myContactFolderItems..Count
Dim myItemCategories As Object
Dim myItemFileAs As String 
pgbSearchAndReplace.Enabled = True
pgbSearchAndReplace.Minimum = 0
pgbSearchAndReplace.Maximum =
myContactFolder.Items.Count
pgbSearchAndReplace.Value = 0 
MsgBox("Items.Count = " & countItems) 
For i As Integer = 1 To countItems
pgbSearchAndReplace.Value = i ' my Progressbar 
Debug.Print("Memory: " & GC.GetTotalMemory(True))
Debug.Print("generate Object") 
myContactFolderItems = myContactFolder.Items
myItem = myContactFolderItems.Item(i) ' old failure
has
passed
when "i  as int = 250"
myItemCategories = myItem.Categories ' new failure
drops
here...
? not explicite enough?
myItemFileAs = myItem.FileAs.ToString 
Debug.Print("Memory: " & GC.GetTotalMemory(True)) 
If TypeName(myItem) = "ContactItem" Then 
If InStr(myItemCategories, txtSearch.Text,
CompareMethod.Text) Then
lstSearchResults.Items.Add(myItemFileAs &
" -
" &
myItemCategories)
End If
Else
MsgBox(TypeName(myItem))
End If 
' Try to release ComObjects
ReleaseMyComObject(myItem)
ReleaseMyComObject(myContactFolderItems)
ReleaseMyComObject(myItemCategories)
ReleaseMyComObject(myItemFileAs)[/QUOTE][/QUOTE]

...

Erfahren Sie mehr »- Zitierten Text ausblenden -

- Zitierten Text anzeigen -[/QUOTE]
 
G

Guest

Ok... i´ll try...

Peter Marchert said:
Only an idea: Can you reproduce this behaviour on another machine and/
or with a different store? Perhaps the installation in a virtual pc
will help you to find out more.

Peter

--
Infos, workshops & soft-
ware for your Outlook®:
www.outlook-stuff.com


Hi...
thanks for reply...

Yes.
I tried to Collect Garbage inside the loop, before loop and inside, and
after every 245 items, but none of this works... :(

greetz from germany
HelixX²³



Dmitry Streblechenko said:
Hmmm... I don't know. Somethign else is going on that is causing .Net to
hold on to the items.
Have you tried to call GC.Collect() inside the loop?
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
There are only ContactItems in myContactFolder.
There are no Distributionlists in there... the only thing is... there are
subfolders in myContactFolder but subfolders are in the
myContactFolder.Folders() Collection and not in the myContactFolder.Items
Collection.
And all Items are at the same customForm (IPM.Contact.myCustomName)
"Dmitry Streblechenko" wrote:
And do you have *only* contacts in that older, no DLs?
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
Hi...
thanks for reply :)
Sure... i tried it twice...
once with myItem as Outlook.ContactItem adn once with myItem as
Object...
both fails... :( dont know why..
greetz HelixX²³
"Dmitry Streblechenko" wrote:
Did you remember to declare myItem as Outlook.ContactItem rather than
the
generic Object?
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
So i tried this... but it fails also... :(
"
myContactFolderItems = myContactFolder.Items
For i As Integer = 1 To myContactFolderItems.Count
myItem = myContactFolderItems.Item(i)
Marshal.ReleaseComObject(myItem)
Next i
"
i = 250 as integer
Das COM-Objekt des Typs "System.__ComObject" kann nicht in den
Schnittstellentyp "Microsoft.Office.Interop.Outlook.ContactItem"
umgewandelt
werden. Dieser Vorgang konnte nicht durchgeführt werden, da der
QueryInterface-Aufruf an die COM-Komponente für die Schnittstelle
mit
der
IID
"{00063021-0000-0000-C000-000000000046}" aufgrund des folgenden
Fehlers
nicht
durchgeführt werden konnte: Schnittstelle nicht unterstützt
(Ausnahme
von
HRESULT: 0x80004002 (E_NOINTERFACE)).
What am i doing wrong?
Maybe i should release the whole Outlook Application from my
harddrive...
(joke) :)
greets HelixX23
"Dmitry Streblechenko" wrote:
Try to remove everything from the loop and see if it runs Ok or
fails
with
the same problem.
myContactFolderItems = myContactFolder.Items
For i As Integer = 1 To myContactFolderItems.Count
myItem = myContactFolderItems.Item(i)
Marshal.ReleaseComObject(myItem)
Next i
Also, why do you keep recalculating
myContactFolderItems = myContactFolder.Items
*inside* the loop?
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
I tried to declare myItem as Outlook.ContactItem but this fails
also...
something is wrong with the Garbage Collector... its not
collecting
anything...
I also tried to start the Garbage Collector before that function
and
after
the 245´s Item but it fails also.
are there maybe any working examples how to successfully
releaseComObjects
under an "exchange folder Items cycle"?
greets HelixX23
"Dmitry Streblechenko" wrote:
I can only guess tah t since you declare myItem as a generic
Object,
teh
compiler QI's it for IDispatch every timee and does not release
the
reference.
Can you try to declare it as ContactItem (assuming you do not
have
any
DLs
in that folder)?
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
Hi...
Thanks for the reply Dmitry.
something is getting better...
the failure changed the line... :)
maybe it is not explicitely declared enough??
Code:
Imports System.Runtime.InteropServices
Imports Microsoft.Office.Core
Imports Outlook = Microsoft.Office.Interop.Outlook
Imports Microsoft.VisualBasic.Information[/QUOTE]
[QUOTE]
Public Class SearchAndReplace[/QUOTE]
[QUOTE]
Public myContactFolder As Outlook.MAPIFolder '=
Outlook.Application.GetNamespace("MAPI").folders("Öffetnliche
Ordner").folders("Alle Öffentlichen Ordner").folders("EUKON
Kontakte")
Private Sub btnPickOLFolder_Click(ByVal sender As
System.Object,
ByVal
e
As System.EventArgs) Handles btnPickOLFolder.Click
Dim myOlApp As Outlook.Application =
CreateObject("Outlook.Application")
Dim myNamespace As Outlook.NameSpace =
myOlApp.GetNamespace("MAPI")
myContactFolder = myNamespace.PickFolder
If myContactFolder Is Nothing Then MsgBox("Sie haben
keinen
Ordner
ausgewählt...?") : Exit Sub
txtOutlookFolder.Text = myContactFolder.FolderPath
End Sub[/QUOTE]
[QUOTE]
Private Sub btnSearchAll_Click(ByVal sender As
System.Object,
ByVal
e
As
System.EventArgs) Handles btnSearchAll.Click
SearchALL()
End Sub[/QUOTE]
[QUOTE]
Private Sub SearchALL()
Dim myContactFolderItems As Outlook.Items =
myContactFolder.Items
Dim myItem As Object
Dim countItems As Integer = myContactFolderItems..Count
Dim myItemCategories As Object
Dim myItemFileAs As String[/QUOTE]
[QUOTE]
pgbSearchAndReplace.Enabled = True
pgbSearchAndReplace.Minimum = 0
pgbSearchAndReplace.Maximum =
myContactFolder.Items.Count
pgbSearchAndReplace.Value = 0[/QUOTE]
[QUOTE]
MsgBox("Items.Count = " & countItems)[/QUOTE]
[QUOTE]
For i As Integer = 1 To countItems
pgbSearchAndReplace.Value = i ' my Progressbar[/QUOTE]
[QUOTE]
Debug.Print("Memory: " & GC.GetTotalMemory(True))
Debug.Print("generate Object")[/QUOTE]
[QUOTE]
myContactFolderItems = myContactFolder.Items
myItem = myContactFolderItems.Item(i) ' old failure
has
passed
when "i  as int = 250"
myItemCategories = myItem.Categories ' new failure
drops
here...
? not explicite enough?
myItemFileAs = myItem.FileAs.ToString[/QUOTE]
[QUOTE]
Debug.Print("Memory: " & GC.GetTotalMemory(True))[/QUOTE]
[QUOTE]
If TypeName(myItem) = "ContactItem" Then[/QUOTE]
[QUOTE]
If InStr(myItemCategories, txtSearch.Text,
CompareMethod.Text) Then
lstSearchResults.Items.Add(myItemFileAs &
" -
" &
myItemCategories)
End If
Else
MsgBox(TypeName(myItem))
End If[/QUOTE]
[QUOTE]
' Try to release ComObjects
ReleaseMyComObject(myItem)
ReleaseMyComObject(myContactFolderItems)
ReleaseMyComObject(myItemCategories)
ReleaseMyComObject(myItemFileAs)[/QUOTE]

...

Erfahren Sie mehr »- Zitierten Text ausblenden -

- Zitierten Text anzeigen -[/QUOTE]
[/QUOTE]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top