"Security error" with threaded app

I have an app that calls a Sub via the Thread class:

            Dim POPThread As New Thread(AddressOf ProcessPOP)
            POPThread.IsBackground = True
            POPThread.Start()

The ProcessPOP sub creates a text file in the Windows temp folder (Path.GetTempPath).  After writing some data to the file, it then tries to Kill() the file.  This is generating an error:

Security error.
   at Microsoft.VisualBasic.CompilerServices.ProjectData.GetAssemblyData(Assembly assem)
   at Microsoft.VisualBasic.FileSystem.Kill(String PathName)
   at SPAMGrinderProxy.SPAMGrinderProxy.ProcessPOP() in C:\Documents and Settings\Mike\My Documents\Visual Studio Projects\SPAMGrinderProxy\SPAMGrinderProxy.vb:line 756

Yet if I pause the program in debug mode, I can manually delete this file, so I know it's not being held open.  Also, if I call the ProcessPOP sub without using a thread, this error does not occur.

Is there some type of thread security involved here that I don't know about   I seem to recall reading something about that, but not sure.


Answer this question

"Security error" with threaded app

  • Ketaki

    In VB if the CallingAssembly is different from the ExecutingAssembly the Kill call fails it appears.  That means if you have a library, you won't be able to call Kill from there I think.  At least that is way the ILDasm is reading.  Try just doing a System.IO.File.Delete(string fileName) and see if that works instead.
  • Jono378

    The executing assembly in this case is probably registering as whatever host the service is running underneath of then.  Since VB imposes this special security, not the run-time itself, just use the run-time methods.
  • Jubeh

    Well I'm not sure I understand why, but that worked.  Since this code is all part of the same assembly (one .vb file) I'm not sure how that is causing a problem.  I should have mentioned that this program runs as a service, if that matters.

    Thanks.

  • "Security error" with threaded app