Unable to install new version of .NET Windows Service - c#

I have a 64-bit Windows Service, written in C#. It was previously installed on a Windows 7 64-bit machine. We've made some changes to it, and are trying to deploy the new version to the same machine.
However, no matter what we do, the behavior we are seeing seems to indicate that the service that is running is the old version.
Here are the steps we've taken in an attempt to resolve this issue:
Uninstalled the service using INSTALLUTIL.
Used SC DELETE to verify that it is removed.
Deleted all files from the service's installation directory, as specified in the service's properties page in the Services snap-in.
Removed any registry entries associated with the service from HKLM\System\CurrentControlSet001\Services.
Rebuilt the service and its dependencies with new version numbers.
Deployed the new version to the service's installation directory.
Reinstalled the service using INSTALLUTIL.
Verified that the Services snap-in and the registry are pointing to the correct location for the service executable.
Nonetheless, the behavior of the newly deployed service appears to be identical to the previous version. (Specifically, it is injecting messages into a queue in MSMQ, when that functionality was removed and can be verified to have been done so.)
We are positive that we are deploying the right version. This same behavior occurs even if we install the new version of the service from the Visual Studio project build folder (bin\x64\release).
Why is/would this be occurring? How do I resolve it? Are services cached somewhere and run from a cache when you install them? If so, where are they, and how do I properly clear them?
Or is this just something I've boned in the code?

Related

Could not load file or assembly after publishing to Azure app service

I am suddenly seeing this error when running my app (published on Azure app service:
Could not load file or assembly 'Microsoft.SharePoint.Client, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' or one of its dependencies. The system cannot find the file specified. at SharePointLibrary.SPClient.GetAllUsers()
at ADVWKSP.Managers.UserManager.GetUsers() in C:\Users\bassie\source\repos\TFS\ADVWKSP\ADVWKSP\Managers\UserManager.cs:line 21
It runs fine on my machine, and it used to run fine after publish but now it just suddenly starts crying about this file missing.
I checked in Kudu and I can only see the SharePoint.Client.Runtime:
Why? How can I ensure that all required libraries are published with the project. Why did this suddenly stop working?
The hosting environment of azure web app contains a standard installation of .Net framework 2.0 to .Net framework 4.5.
If your application referenced assemblies which is not build in .Net framework, you have to "include" them with your deploy package.
Even these are Microsoft assemblies.
Setting the Copy Local property to True for the referenced assembly may fix it.
1.In Solution Explorer find your project's reference to the library.
2.Right click and choose Properties.
3.In the Properties window set Copy Local to True.
As you said, it works locally on IIS Express, please try to deploy your website content manually to Azure via KUDU or FTP client and find out whether it works or not.
Adding the following parameter
/deployonbuild=false
to the msbuild command line fixed the issue.
I faced the similar kind of issue when my app service function version was 3, but function source was targeted function version 4. updating the app service sorted the issue

Installing second windows service says service already exists

In VS 2013, I have a service installed on the development machine and it works well. I created another one today, but it won't install, saying the service already exists.
Let's call them Service A (old) and Service B (new)
I uninstalled Service A, then installed successfully Service B. Then tried to reinstall Service A but it says it already exists.
So whatever the combination, I can only install one service. I tried with Project Installer and InstallShield, both yeild the same result.
Any idea how to overcome that? If it's on any use, both services have some common dependencies (dll).
It is on Windows Server 2012.
So both your services must define the same value for System.ServiceProcess.ServiceBase.ServiceName in the subclass that is in your service project.
Search for it in one of your service projects, and replace it with an alternative name.

Removing/installing a Windows Service

I've created a Windows Service project in C#, just some very simple code. It worked when i installed the service, but now I have to add some code and so on,but that has caused some issues:
1) When trying to uninstall using "installutil /u" it says its removed however its still on the service list in computeradministration.
1a) I tried to delete it with cmd using "sc delete ServiceName" which removes it from the list
2) BUT when i install the new build it succeeds, however it still uses the old build for some reason, and im kindda at a loss.
You only have to install once. The service will be registered with the .exe you registered using sc or installutil.
To replace the binary, just stop the service, replace the binary with the "new" one and restart: the new service will be running.
Also, you have to restart services.msc to see that some services are removed (there seems to be some "pending removal" flag).
If your service is in use (e.g. it is running) when you uninstall it you may have to restart your computer after uninstalling it before it is completely uninstalled. installutil and sc does not give you any information about this. And when a service is pending removal you can get into all sorts of problems if you try to install it again (which seems to the problem that you experience).
Make sure that the service is stopped before uninstalling it to avoid having to restart your computer to complete the uninstall.
If you just want to update the binary of the service you can simply stop it and replace the executable files before restarting the service.

Hook before BeforeInstall Installer Method - Windows Installer

I have created an installer which installs windows service. I have used Visual studio default installer in VS 2010.
The service will access and write on the database file(SQLite) present in the installation folder.
During uninstall when the service is stopped or running, the service is uninstalling without any error.
But if the installer is migrated from version 1 to 2, and the service of previous version is running then"The file is being accessed by some application. Try again" error has been shown, since the previous installation service accessing the DB file.
So I need to stop the previous version service before Installing new version.
I have a custom action script for managing install and uninstall.
In BeforeInstall method I have written code to stop the service using ServiceController. That can stop the service.
ServiceController service = new ServiceController("SERVICE_NAME");
if (!(service.Status.Equals(ServiceControllerStatus.Stopped)))
{
service.Stop();
service.WaitForStatus (System.ServiceProcess.ServiceControllerStatus.Stopped);
}
But even before BeforeInstall method the installer is copying new version files replacing my previous version files.
I always have same installation folder.
So if I write code to stop the service in BeforeInstall custom Action it will still throw error, because the DB file being accessed by previous version service was tried to delete by new version.. So I am getting "The file is being accessed by some application. Try again".
So I need some hook even before the installer copies the files to the installation folder. So that I can stop the service before the installer try to update the Db file.
Any idea would be appreciated.
Windows Installer doesn't have a concept of "before install". This is a Visual Studio Setup and Deployment project abstraction. This project type failed to expose many underlying Windows Installer features and this is why Microsoft eliminated it in VS2012.
Another concept that isn't exposed is the ServiceInstall and ServiceControl tables. This is why you are being forced to write custom actions. Custom actions that are hosted in such a way ( beyond your control ) to tattoo the MSIEXEC process with a CLR version and throw modal 1001 exceptions (even during silent installation) when there is a problem.
But there is a solution. Switch to a better tool such as free and open source Windows Installer XML (WiX) and Industrial Strength Windows Installer XML (IsWiX). With these tools you can create a windows service, create the installer for it and test the install/uninstall on a VM in 10 minutes. Watch my silent demo at:
Building and Deploying a Windows Service using IsWiX

Installing a Windows Service - No error but it isn't in Service Control Manager

I've created a windows service in c# and I'm trying to install it for debug using the installutil as recommended here: http://msdn.microsoft.com/en-us/library/sd8zc8ha.aspx
The installutil says Install completed. However, nothing appears in the service control manager.
I've tried this on Server 2008 and XP with the same result.
Any ideas?
A colleague of mine had a more or less identical problem.
Did you add an installer to your project? For the service to be installed you need to add an installer to your Visual Studio Project.
The easiest way to add an installer in Visual Studio is to open your service in Design Mode and right click the design area and select Add Installer. This will add a file ProjectInstaller.cs with itself contains a ServiceInstaller object and a ServiceProcessInstaller object.
With the installer added you can set the Service Name, Description and other options that will be used when installing the service. If you now try to use InstallUtil your service should be installed and should show up in the Services list.
I had a similar issue (build installer, no errors, no service appears in services.msc) but a different solution, as I had configured the installers.
In my case, the Service-project's Application Properties (Alt-Enter, Application-tab) Startup object was (not set) as shown below:
Picking the default .Program and rebuilding service and installer worked (service appeared in services.msc).
Setting this property is one of the steps in the MSDN service installer walkthrough referenced in this SO answer. Make sure to follow all of the steps!
I can't speak specifically to any issues that are the fault of C# or .NET, but I have a writeup of what has to happen for a service to be installed and work in the form of an extensively documented framework (source code included) for writing services in Lua. I offer it up here as an example of another way to do it, because sometimes just seeing things from another point of view can be helpful.
Disclaimer: It is very much at an alpha quality level, and yes, I am its author.
The framework has all the code needed to interact with the Windows SCM to install and remove the service.

Categories

Resources