TReKiE / msnp-sharp

Automatically exported from code.google.com/p/msnp-sharp
0 stars 0 forks source link

IOException when adding or removing contacts #93

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
When adding/removing several contacts, IOException occurs:

the .mcl file is already in use... I guess the code is trying to write to 
an open file.

May you please check it for me?

Thank you very much!

Original issue reported on code.google.com by tczol...@gmail.com on 10 Mar 2009 at 7:56

GoogleCodeExporter commented 9 years ago

Original comment by freezing...@gmail.com on 11 Mar 2009 at 3:22

GoogleCodeExporter commented 9 years ago
Can you give us more details about how to reproduce the problem?

Original comment by freezing...@gmail.com on 11 Mar 2009 at 3:23

GoogleCodeExporter commented 9 years ago
Of course.

The code is reading a file with the contacts' e-mail addresses, then it starts 
adding 
them the the contact list:

'-----------------------------------------------------------------

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As 
System.EventArgs) 
Handles Button2.Click
        If Mess.Nameserver.IsSignedIn Then
            Dim FName As String = ""
            Dim Clist As String = ""
            Dim OpenBox As New OpenFileDialog

            If OpenBox.ShowDialog = Windows.Forms.DialogResult.OK Then
                FName = OpenBox.FileName

                Dim objReader As New System.IO.StreamReader(FName)
                Clist = objReader.ReadToEnd
                objReader.Close()

                Dim Contacts() As String
                Contacts = Clist.Split(vbLf)

                For Each C As String In Contacts
                    C = C.Replace(vbCr, "")
                    C = Trim(C)

                    If C <> "" Then
                        ToAddList.Add(C, C)
                    End If
                Next

                AddHandler Mess.Nameserver.ContactService.ContactAdded, AddressOf 
MessContactAdded
                MessContactAdded(Mess.Nameserver.ContactService, Nothing)
            End If
        End If
    End Sub

    Private Sub MessContactAdded(ByVal sender As System.Object, ByVal e As 
MSNPSharp.ListMutateEventArgs)
        Dim CS As ContactService
        CS = sender

        If ToAddList.Count > 0 Then
            Dim T As String

            For Each T In ToAddList
                CS.AddNewContact(T)
                AddContactItem(T, 1)
                Debug.WriteLine("Contact added: " & T)
                Exit For
            Next

            If ToAddList.Contains(T) Then
                ToAddList.Remove(T)
            End If
        End If
    End Sub

'-----------------------------------------------------------

So, first of all, it reads the file, puts the lines into a Collection, and 
starts 
putting them onto the Contact List. When adding the first contact is finished, 
ContactService.ContactAdded is fired and it's handled by MessContactAdded - it 
adds 
the next contact and so on. Until the Collection contains any item. "ToAddList" 
and 
"Mess" are global variables by the way.

The exception occurs after adding N pieces of contacts... it could be 5 or 100, 
the 
same.

Here's the output:

-----------------------------------------------------------
System.Transactions Critical: 0 : <TraceRecord 
xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" 
Severity="Critical"><TraceIdentifier>http://msdn.microsoft.com/TraceCodes/System
/Acti
vityTracing/2004/07/Reliability/Exception/Unhandled</TraceIdentifier><Descriptio
n>Nem 
kezelt 
kivétel</Description><AppDomain>BOTond.exe</AppDomain><Exception><ExceptionType
>Syste
m.UnauthorizedAccessException, mscorlib, Version=2.0.0.0, Culture=neutral, 
PublicKeyToken=b77a5c561934e089</ExceptionType><Message>A következő elérési 
úthoz 
való hozzáférés megtagadva: „C:\Documents and 
Settings\tcz.EMPO\Asztal\BOTond\project\BOTond\BOTond\bin\Debug\681333294d.mcl��
�.</Mes
sage><StackTrace>   a következő helyen: System.IO.__Error.WinIOError(Int32 
errorCode, 
String maybeFullPath)
   a következő helyen: System.IO.FileStream.Init(String path, FileMode mode, 
FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 
bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, 
Boolean bFromProxy)
   a következő helyen: System.IO.FileStream..ctor(String path, FileMode mode, 
FileAccess access, FileShare share)
   a következő helyen: System.IO.File.WriteAllBytes(String path, Byte[] bytes)
   a következő helyen: MSNPSharp.IO.MCLFile.SaveImpl(String filename, Byte[] content)
   a következő helyen: MSNPSharp.IO.MCLFile.SaveAndHide(String filename)
   a következő helyen: MSNPSharp.IO.MCLSerializer.SaveToHiddenMCL(String filename)
   a következő helyen: MSNPSharp.IO.MCLSerializer.Save(String filename)
   a következő helyen: MSNPSharp.IO.DeltasList.Save(String filename)
   a következő helyen: MSNPSharp.IO.MCLSerializer.Save()
   a következő helyen: MSNPSharp.ContactService.handleServiceHeader(ServiceHeader sh, 
Type requestType)
   a következő helyen: 
MSNPSharp.ContactService.&lt;&gt;c__DisplayClass1b.&lt;AddNewOrPendingCon
tact&gt;b__18(Object service, ABContactAddCompletedEventArgs e)
   a következő helyen: 
MSNPSharp.MSNWS.MSNABSharingService.ABServiceBinding.OnABContactAddOperationComp
leted
(Object arg)
   a következő helyen: 
System.Threading._ThreadPoolWaitCallback.WaitCallback_Context(Object state)
   a következő helyen: System.Threading.ExecutionContext.runTryCode(Object userData)
   a következő helyen: 
System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(
TryCo
de code, CleanupCode backoutCode, Object userData)
   a következő helyen: System.Threading.ExecutionContext.RunInternal(ExecutionContext 
executionContext, ContextCallback callback, Object state)
   a következő helyen: System.Threading.ExecutionContext.Run(ExecutionContext 
executionContext, ContextCallback callback, Object state)
   a következő helyen: 
System.Threading._ThreadPoolWaitCallback.PerformWaitCallbackInternal(_ThreadPool
WaitC
allback tpWaitCallBack)
   a következő helyen: 
System.Threading._ThreadPoolWaitCallback.PerformWaitCallback(Object 
state)</StackTrace><ExceptionString>System.UnauthorizedAccessException: A 
következő 
elérési úthoz való hozzáférés megtagadva: „C:\Documents and 
Settings\tcz.EMPO\Asztal\BOTond\project\BOTond\BOTond\bin\Debug\681333294d.mcl��
�.
   a következő helyen: System.IO.__Error.WinIOError(Int32 errorCode, String 
maybeFullPath)
   a következő helyen: System.IO.FileStream.Init(String path, FileMode mode, 
FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 
bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, 
Boolean bFromProxy)
   a következő helyen: System.IO.FileStream..ctor(String path, FileMode mode, 
FileAccess access, FileShare share)
   a következő helyen: System.IO.File.WriteAllBytes(String path, Byte[] bytes)
   a következő helyen: MSNPSharp.IO.MCLFile.SaveImpl(String filename, Byte[] content)
   a következő helyen: MSNPSharp.IO.MCLFile.SaveAndHide(String filename)
   a következő helyen: MSNPSharp.IO.MCLSerializer.SaveToHiddenMCL(String filename)
   a következő helyen: MSNPSharp.IO.MCLSerializer.Save(String filename)
   a következő helyen: MSNPSharp.IO.DeltasList.Save(String filename)
   a következő helyen: MSNPSharp.IO.MCLSerializer.Save()
   a következő helyen: MSNPSharp.ContactService.handleServiceHeader(ServiceHeader sh, 
Type requestType)
   a következő helyen: 
MSNPSharp.ContactService.&lt;&gt;c__DisplayClass1b.&lt;AddNewOrPendingCon
tact&gt;b__18(Object service, ABContactAddCompletedEventArgs e)
   a következő helyen: 
MSNPSharp.MSNWS.MSNABSharingService.ABServiceBinding.OnABContactAddOperationComp
leted
(Object arg)
   a következő helyen: 
System.Threading._ThreadPoolWaitCallback.WaitCallback_Context(Object state)
   a következő helyen: System.Threading.ExecutionContext.runTryCode(Object userData)
   a következő helyen: 
System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(
TryCo
de code, CleanupCode backoutCode, Object userData)
   a következő helyen: System.Threading.ExecutionContext.RunInternal(ExecutionContext 
executionContext, ContextCallback callback, Object state)
   a következő helyen: System.Threading.ExecutionContext.Run(ExecutionContext 
executionContext, ContextCallback callback, Object state)
   a következő helyen: 
System.Threading._ThreadPoolWaitCallback.PerformWaitCallbackInternal(_ThreadPool
WaitC
allback tpWaitCallBack)
   a következő helyen: 
System.Threading._ThreadPoolWaitCallback.PerformWaitCallback(Object 
state)</ExceptionString></Exception></TraceRecord>
The program '[3536] BOTond.exe: Managed' has exited with code 0 (0x0).
----------------------------------------------------------

I've attached the screenshots. The exception message ca. means: The file is 
udes by 
another program.

Original comment by tczol...@gmail.com on 11 Mar 2009 at 9:21

Attachments:

GoogleCodeExporter commented 9 years ago
it may be IOException as well... varying...

Original comment by tczol...@gmail.com on 11 Mar 2009 at 11:41

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Please try revision 902 on 25_STABLE. I hope this fixes this problem.

Original comment by hepha...@gmail.com on 11 Mar 2009 at 6:29

GoogleCodeExporter commented 9 years ago
great :) one of my eyes is laughing the other is crying :( it seems to solve 
the 
IOException, but UnauthorizedAccessException still remains... :(

I've gave full access rights to Everyone for the whole project directory and 
it's 
child objects...

my program adds the first 100-200 contact now, and then the exception occurs 
again. at least now i have debugging symbols as well.

but i can't be thankful enough for developing this great project!

Original comment by tczol...@gmail.com on 12 Mar 2009 at 10:33

Attachments:

GoogleCodeExporter commented 9 years ago
the filename is always 681333294d.mcl, does it mean something?

Original comment by tczol...@gmail.com on 12 Mar 2009 at 1:08

GoogleCodeExporter commented 9 years ago
Try it now.

Original comment by freezing...@gmail.com on 12 Mar 2009 at 1:55

GoogleCodeExporter commented 9 years ago
i guess you've missed permission.Demand();

but it still isn't ok, with the demand() either... :(
always 681333294d.mcl....

what does it mean?

Original comment by tczol...@gmail.com on 12 Mar 2009 at 3:39

GoogleCodeExporter commented 9 years ago
There are 2 contact list files.
681333294 is "yourmail@hotmail.com".GetHashCode() and "d" is deltas file.
681333294.mcl = addressbook (Msnpsharp Contact List)
681333294d.mcl = deltas mcl

Please delete these files and login again.

Original comment by hepha...@gmail.com on 12 Mar 2009 at 5:23

GoogleCodeExporter commented 9 years ago
i've deleted the files, tried all version of codes, tries another msn 
address... 
can't solve the problem...

any other ideas?

Original comment by tczol...@gmail.com on 15 Mar 2009 at 1:19

GoogleCodeExporter commented 9 years ago
Hi again,

Could you attach the project you are using with .zip format?

I will run it with my machine.

Original comment by hepha...@gmail.com on 15 Mar 2009 at 1:51

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Ok, try new version.
I have added 900+ accounts continuously and it is fixed now.
The problem was saving the delta file continuously.

Thanks for the report.

Original comment by hepha...@gmail.com on 15 Mar 2009 at 7:09

GoogleCodeExporter commented 9 years ago
no :(((

i've updated DeltaList.cs, but the exception's the same... after 278 contacts 
added 
it stops again.

may i miss something, some updated source file?
how can i download the actual version of all source files?

Original comment by tczol...@gmail.com on 16 Mar 2009 at 4:15

GoogleCodeExporter commented 9 years ago
use the svn client check out all of the source and re-compile it.

Original comment by freezing...@gmail.com on 16 Mar 2009 at 5:31

GoogleCodeExporter commented 9 years ago
i've checked the whole code out with svn, and it works great! thank you very 
much!!!

Original comment by tczol...@gmail.com on 17 Mar 2009 at 3:56

GoogleCodeExporter commented 9 years ago
A tip:

When you add a new contact wait ContactAdded event then add next contact.
ContactService.AddNewContact is async method that is not real time, so you must 
wait
ContactAdded event...

I have tested it with 900+ contacts and about ~200 threads were created and they
writing the same file at the same time. Now, it is written in 5 seconds 
interval, so
the proplem is fixed. Just apply the tip, wait ContactAdded and then add 
following
contact.

Original comment by hepha...@gmail.com on 17 Mar 2009 at 6:53

GoogleCodeExporter commented 9 years ago
yeah, it used to be that way, but during tryin debug the code, i changed it to 
the 
timed way...

thanks, it's a great project, great job!

Original comment by tczol...@gmail.com on 18 Mar 2009 at 9:15