question

kingmoot-5803 avatar image
0 Votes"
kingmoot-5803 asked MotoX80 commented

Windows Service written in Visual Studio 2022 won't start

Hi, I have written a windows service using Visual Studio 2022. The service utilises an IBM Library that was pulled into the project using Visual Studio's NuGet package manager.

I tested the code beforehand by writing a class library and testing it in a class module (vb). It worked once the IBM Library was pulled into the Console Application via the NuGet package manager.

I want to use this code as a windows service, so I wrote a Service, and pulled in the code. The class module has a single public sub which does all the work. The service calls that Sub. Again, I added the DLL to the project via the NuGet package manager.

When you compile the service, it appears to put the exe and related DLLs in the release folder.

I copied these files to a C:\Program Files\ area and installed the service using the .NET installutil utility.

However, when I run up the service, I get this error:

tmrService_Tick() failed:Could not load file or assembly 'amqmxmsstd, Version=9.2.5.0, Culture=neutral, PublicKeyToken=d2666ab12fca862b' or one of its dependencies. The system cannot find the file specified.

Interestingly, the compiled console application DOES work when I run the EXE...but I can't seem to get the service to start. How do I distribute the windows service exe and related DLLs so that the service will start?

If there are dependencies to amqmxmsstd, how would I work out what they are?



dotnet-visual-basic
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

If there are dependencies to amqmxmsstd, how would I work out what they are?

If this is a NuGet package, find it on NuGet, click the dependency button.
0 Votes 0 ·

Here is the item in question

https://www.nuget.org/packages/IBMXMSDotnetClient/9.2.5?_src=template




It says no dependancies. Could it be something to do with the framework? Maybe I'm not compiling the service in the right way.

0 Votes 0 ·
kingmoot-5803 avatar image
0 Votes"
kingmoot-5803 answered

Could it be that the DLLs have to be copied somewhere else on the server, rather than alongside the Service binary exe?

Any ideas about that?

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

kingmoot-5803 avatar image
0 Votes"
kingmoot-5803 answered

I have copied the amqmxmsstd DLL to C:\Windows\SysWOW64\

I now get a different error:

Faulting application name: MyService.exe, version: 1.0.0.0, time stamp: 0xda21fcfc
Faulting module name: ntdll.dll, version: 10.0.19041.1566, time stamp: 0xbde09443
Exception code: 0xc0000374
Fault offset: 0x000e6d03
Faulting process ID: 0x72e8
Faulting application start time: 0x01d8638e9a147894
Faulting application path: C:\Program Files\MyService\MyService.exe
Faulting module path: C:\WINDOWS\SYSTEM32\ntdll.dll
Report ID: b2756903-acc4-4e89-bc6d-fb0fd313a79d
Faulting package full name:
Faulting package-relative application ID:


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

JiachenLiMFST-9349 avatar image
0 Votes"
JiachenLiMFST-9349 answered

Hi @kingmoot-5803 ,
Check the following link to see if it helps.
https://social.msdn.microsoft.com/Forums/vstudio/en-US/197aed35-544e-4047-965d-da6c3835e4a8/error-in-starting-windows-serviceservice-cannot-be-started-systemiofileloadexception-could-not?forum=netfxbcl
Best Regards.
Jiachen Li


If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

kingmoot-5803 avatar image
0 Votes"
kingmoot-5803 answered

Hi, thanks but I don't think that's the same error. My error doesn't refer to "Assembly binding logging"

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

MotoX80 avatar image
0 Votes"
MotoX80 answered

I have copied the amqmxmsstd DLL to C:\Windows\SysWOW64\

Is your service compiled as 32 bit and is that the 32 bit version of the amqmxmsstd.DLL?

You might want to trace the service startup with process monitor.

https://docs.microsoft.com/en-us/sysinternals/downloads/procmon

I believe that when your service starts, the current working directory will be C:\Windows\system32 (or maybe syswow64 for 32 bit). If your dependent dll's are over in C:\Program Files\SomeDir, then Windows might not be able to find them. If the dll's are registered in the GAC, then they should be found.

Tracing the startup with procmon will show you the dll's it's looking for and what directories it's searching.

Did you also install a MQ client or MQ SDK? I don't know what's required these days. You might have to search the IBM.com documentation.

I'll apologize in advance, it's been a number of years since I last wrote a service or played with MQ. Hope this helps.



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

kingmoot-5803 avatar image
0 Votes"
kingmoot-5803 answered MotoX80 commented

Ok so I have the solution.

The service must be running as "Local Service", not "Local System". It will only run as "Local Service".

I would like to know why that is, do you have any suggestions?

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

The system account should have access to everything on your machine.

When you try to start the service what related events show up in the security and system event logs?

You could also try tracing the service with Process Monitor and search for "access denied" events.

0 Votes 0 ·