| Author |  | 
      
        | crg1970 Newbie
 
  
 
 Joined: 27 August 2008
 Location: Panama
 Online Status: Offline
 Posts: 4
 | 
          I have a Windows Service that reads EML files using the MIME classes.  It reads the file no problem, but when it tries to write the file (it needs to output it to another folder) I get an exception.
           | Posted: 27 August 2008 at 12:30pm | IP Logged |   |  
           | 
 |  
 The problem is that the destination folder is inside an IIS application that has FORMS AUTHENTICATION configured. The error I get is thrown by ASP.NET "Forms authentication failed for the request. Reason: The ticket supplied is Invalid. ".  I don't have an authenticaton ticket, because the service should be running outside IIS and it is accessing the folder using a full path rather than a URL.
 
 Has anyone ever seen a problem like this?  The actual Mailbee exception is a mailbeeioexcption.
 | 
       
        | Back to Top |     | 
       
       
        |  | 
        | Andrew AfterLogic Support
 
  
 
 Joined: 28 April 2006
 Location: United States
 Online Status: Offline
 Posts: 1189
 | 
          We're not sure that clearly understood you. You said a Windows Service writes the file, but the exception is thrown in an ASP.NET application. Are you sure the issue happens because the file is written by the Windows Service?
           | Posted: 28 August 2008 at 1:34am | IP Logged |   |  
           | 
 |  
 Best regards,
 Andrew
 | 
       
        | Back to Top |     | 
       
       
        |  | 
        | crg1970 Newbie
 
  
 
 Joined: 27 August 2008
 Location: Panama
 Online Status: Offline
 Posts: 4
 | 
          Quite sure.  The error has gone away since I removed the Forms authentication from that FOLDER.  However, now I have the following error (again, running a Windows Service that uses the Mailbee.MIME.mailmessage object to read an .EML file from the c:\inetpub\mailroot\drop folder):
           | Posted: 29 August 2008 at 2:05pm | IP Logged |   |  
           | 
 |  
 1.0.0.0
 48b85a36
 mailbee.net
 4.0.2.105
 48a1794e
 f78
 6b
 mailbee.mailbeeioexception
 NIL
 
 Element not found
 
 The thing is that as far as I can tell the Mailbee object is not supposed to be doing anything at that moment.  Can you tell me more about what this error could mean?
 | 
       
        | Back to Top |     | 
       
       
        |  | 
        | Igor AfterLogic Support
 
  
 
 Joined: 24 June 2008
 Location: United States
 Online Status: Offline
 Posts: 6167
 | 
          MailBee I/O Exception message usually means some access related issue, for example the application was unable to read from or write into a file.
           | Posted: 01 September 2008 at 1:33am | IP Logged |   |  
           | 
 |  
 Could you please provide us with detailed exception information including stack trace?
 
 Please also try to debug your application to find out what exactly your application tries to do when the exception is thrown.
 
 Regards,
 Igor
 | 
       
        | Back to Top |     | 
       
       
        |  | 
        | crg1970 Newbie
 
  
 
 Joined: 27 August 2008
 Location: Panama
 Online Status: Offline
 Posts: 4
 | 
          Thanks for all your help, but I continue to have problems.  How can I provide you with a full stack trace???
           | Posted: 01 September 2008 at 11:04am | IP Logged |   |  
           | 
 |  
 I have been debugging as much as I can with the service.  I use the fileSystemWatcher class to monitor when a file is put in the MAILROOT\drop folder.  When I try to read the file after the event is raised, SOMETIMES I get this error.  I don't understand why sometimes it can read the file fine, others it can't.
 
 THERE is nothing else trying to read the file, and supposedly when the CREATED event is fired for the FSW, the IIS process should be done with it right?  Anyone have any experience with anything similar?
 | 
       
        | Back to Top |     | 
       
       
        |  | 
        | Andrew AfterLogic Support
 
  
 
 Joined: 28 April 2006
 Location: United States
 Online Status: Offline
 Posts: 1189
 | 
          
           | Posted: 02 September 2008 at 2:09am | IP Logged |   |  
           | 
 |  
| Quote: 
 
    
    | 
      
       | How can I provide you with a full stack trace??? |  |  |  
 Just add try/catch block and implement writing exception.ToString() to a file in the catch block.
 
 Are you sure the FSW event means "file has been created, written and closed"? Perhaps, it just means "file has been created and is being written, but not closed yet". So, if your application tries to access that file while it's locked, the exception may be thrown. Try to add a delay (second or two) into your FSW event handler, so the file wouldn't be accessed immediately and the writing process would have time to complete writing. Does it help?
 
 The "SOMETIMES" may depend on file size (i.e. time required to write the file) and filesytem load (additional lags).
 
 Best regards,
 Andrew
 | 
       
        | Back to Top |     | 
       
       
        |  | 
        | crg1970 Newbie
 
  
 
 Joined: 27 August 2008
 Location: Panama
 Online Status: Offline
 Posts: 4
 | 
          Sure enough, it is a problem with the fact that the FSW triggers the CREATED event, before IIS has finished writing the file.
           | Posted: 02 September 2008 at 2:45pm | IP Logged |   |  
           | 
 |  
 I had to use a loop with a try/catch inside to get this to work.  Anyone else ever written a Mail Reader program to read from the IIS MailRoot\drop folder???  Was this the RIGHT or only solution???
 | 
       
        | Back to Top |     | 
       
       
        |  | 
        | Andrew AfterLogic Support
 
  
 
 Joined: 28 April 2006
 Location: United States
 Online Status: Offline
 Posts: 1189
 | 
          What if to start waiting for "Changed" event right after "Created" event? Try to add "Changed" event handler where your application should check if the file is still locked, once it gets unlocked, you should process it.
           | Posted: 03 September 2008 at 1:25am | IP Logged |   |  
           | 
 |  
 This solution is similar to the loop with a try/catch inside you implemented, but looping without a delay consumes more CPU time than waiting for event.
 
 Best regards,
 Andrew
 | 
       
        | Back to Top |     | 
       
       
        |  | 
        | Andrew AfterLogic Support
 
  
 
 Joined: 28 April 2006
 Location: United States
 Online Status: Offline
 Posts: 1189
 | 
          We found additional info which should be useful for you.
           | Posted: 03 September 2008 at 4:19am | IP Logged |   |  
           | 
 |  
 Also, pay your attention to the comments, especially to:
 
 
 
| Quote: 
 
    
    | 
      
       | I have seem similar situations being handled in a different manner. 
 Lets say you have a folder where files are being dropped from a remote location at regular intervals. You would like to be notified of new files being available, to do further processing on them.
 
 In this scenario, instead of using the NotifyFilters.FileName property, use the NotifyFilters.LastWrite Property to trigger the event handler. This will prevent a double callback and make sure that the file is completely transfered before triggering the change event.
 |  |  |  
 Best regards,
 Andrew
 | 
       
        | Back to Top |     | 
       
       
        |  |