mercredi 20 mai 2015

Puzzling differences in behavior between console and web apps

I have a piece of code in a Web API app:

private Stream ConvertWorkBookToStream(WorkBook workBook)
{
    var tempFileName = Path.GetTempFileName();

    // The following line throws a NullReferenceException
    workBook.write(tempFileName);

   // Remainder elided for brevity
}

Neither workBook nor tempFileName are null.

On a whim, I changed the app pool to run under a domain administrator account, to eliminate any permissions issues (since I've observed some general wonkiness on my machine of late) and re-ran it. The same exception was thrown.

Then I created a console application and copied the method, verbatim, into the app and ran it. No exception was thrown.

Now, it bears noting that just yesterday, I ran into a similar puzzling behavior regarding File.Exists.

Consider the following call:

var exists = File.Exists(@"\\myshare\\myexistingfile.ext");

Assuming that the path refers to a file that actually exists:

  • Under a web app, exists returns false on my machine.
  • The same operation, in a console application, returns true.

My coworkers are experiencing the opposite behaviors.

Can anyone explain this? I'm rather at my wits' end.




Aucun commentaire:

Enregistrer un commentaire