0

I've tested some RestSharp code in a Windows Form application without any issues. However the code won't work in a Windows Service. After some testing, I found that the:

var client = new RestClient();

Is the first thing that fails. By "fail" I mean that the thread never returns from this call. If I run it from the OnStart() event, the service fails to start properly.

Some interesting observations: The try/catch doesn't pick up the error, and nothing else in the function works, including code before this line. Writes to the Event Log before the call never make it to the log. I've tried replacing this line with a bit of code that would cause an error (divide something by zero) and the event log has the line I wrote out beforehand, and the error caught in the try/catch.

  • What account is your service running in? More than likely you are running in LOCALSYSTEM –  Apr 26 '18 at 04:55
  • Can you please post the code, say of the Windows form application vis-a-vis the Windows Service? –  Apr 26 '18 at 04:55
  • Food for thought: _[The difference between the 'Local System' account and the 'Network Service' account?](https://stackoverflow.com/questions/510170/the-difference-between-the-local-system-account-and-the-network-service-acco)_ –  Apr 26 '18 at 05:01
  • Further info...Placing the offending call inside another function, with it's own try/catch, cause the try/catch in the original function to capture the error. "Could not load file or assembly 'RestSharp, Version=106.2.2.0..." The DLL is 106.2.2.20. Not sure that's the issue, though. Sounds like similar issues people have had with NuGet. – Evangelos Mourmourakis Apr 26 '18 at 05:19
  • Found it. The REstSharp DLL wasn't copied into the bin directory! Cleared out the Packages folder, deleted the bin folder, did a 'Clean Solution' followed by a 'Rebuild Solution' and the DLL copied in. I suppose I could have manually copied it in, too, but I wanted to see it work properly. Getting the error message finally pointed me in the right direction. – Evangelos Mourmourakis Apr 26 '18 at 05:37

0 Answers0