Running as a webapp as a service crashes

Hi everyboby…
I have an standalone webapp that runs without any problem when I start it by double clicking the exe file.
But when I run it as a service it crashes.
The line of code that produces the crash is when the webapp tries to check if a file exists:
dim pdfFile as folderitem = SpecialFolder.Desktop.Child(“Uploads”).Child(“Temp”).Child(“Myfile.pdf”)
if pdfFile.Exists then <-- here crashes
'do something
end if
Any idea how to solve it because I do need to have the web app running as a service.

Hi Mariano,

Did you check if “pdfFile” is Nil at that point? If it is the case, then the app will crash because you’re trying to access the “Exist” property on a NILed object.

1 Like

When your exe runs as a service it possibly runs with another user account so “Desktop” refers to something that does not exists.

Javier, thanks for your answer…
If Myfile.pdf exists or not the webapp crashes but ONLY when the webapp is running as a service.
This does not happened if is is running by double clicking the exe file.
It is weird that it crashes running in some way and not in other, because the failure happends when testing the existance of a file.
If I delete that line of code the webapp do not crashes

@Maurizio Rossi … Your advice is in the same line of the one Javier gave me, and it make sense… I will try it…

You can show in a webpage the resulting folderitem’s nativepath (without accessing it).

“Desktop” may not exist in service context. When you double-click the executable it runs as yourself (the username/password you used to log in.) Services usually run differently. Even if you supply the username and password for the service, Desktop may not have meaning since its a background process. Which operating system is this running on?

Move your pdf file to SpecialFolder.SharedApplicationData. The Service Desktop is not your Desktop.

1 Like

Thanks @Wayne_Golding
After all frind in the forum said, your suggest is the better solution of where to place this files