I'm trying to write my first Windows Service in C#. If I follow the MS tutorial to the letter, I can create a simple service with a timer that works and writes to the eventLog. The second I change ANYTHING it will not start with 1064.
I installed the service by calling C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe from the solution's bin\debug folder.
I have uninstalled the service and reinstalled it.
I have used SC DELETE and reinstalled it.
I have rebooted. Nothing works, unless I start a new project from scratch, which fails again when I try to change anything. Does something have to be reset if you change code?
Starting again with baby steps and careful use of the event log I was able to determine that the service could not access a file path which referred to a drive created with a SUBST command (I don't have an E drive on the development machine). I presume this is because the SUBST is not in the service's process, however why that caused the service controller to error on startup I don't know, possibly because the path was accessed from Properties.Settings.Default. The mystery fact remains that a working version stopped working when I only changed the service display name and rebuilt (after uninstalling & reinstalling).
Related
We're trying to run R.net from an ASP.Net webpage in IIS, but encounter the problem that the R engine can't access external libraries. I know this is a common problem, but the typical solutions haven't worked when it comes to IIS (only IIS express from inside VS).
For example, when trying to use 'colorRampPalette' in R which relies on a DLL, the following error message appears:
"Error in inDL(x, as.logical(local), as.logical(now), ...) : unable to load shared object 'C:/Program Files/R/R-3.4.2/library/stats/libs/x64/stats.dll': LoadLibrary failure: The specified module could not be found."
It is not the stats.dll that is the problem, but rather another DLL it references.
Now, using the function in R works fine. Using the function from R.net in VS debugging works fine. However, running it from IIS does not work. Normally, it's just a path variable missing to get it to work, but this doesn't seem to be the case here.
What we've tried:
Ensured that the PATH variable has the necessary folders (i.e. C:\Program Files\R\R-3.4.3\bin\x64 etc). If this was wrong then R.net wouldn't work locally, and I've also verified that IIS doesn't reset the PATH variables which has been pointed out in other sources. When I check the PATH variable from inside IIS the necessary folders are listed.
Checked that the library, home and bin path in R.net is correct when running under IIS.
Ensured that the IIS_IUSRS user has read/write access to the necessary folders and files.
Verified that the R code is correct.
It seems that this is a common problem, but most solutions refer to making sure the PATH variable is correct, which simply isn't enough in this case.
We're running (Amazon web service):
Windows Server 2016 x64,
IIS 10,
R.NET 1.7,
C# 4.5.2,
R 3.4.2
I've also tried on another (non-AWS) server with a similar setup.
Any ideas of what can cause this? Since a lot of people have issues with R.Net and IIS I suspect someone encountered the same problem where the PATH variable wasn't enough?
As mentioned by user2967150, It is not the stats.dll that is the problem, but rather another DLL it references.
After doing lot of research I found that It try to find Rlapack.dll in 'C:/Program Files/R/R-3.4.2/library/stats/libs/x64/ path.
so you just have to copy Rlapack.dll from 'C:\Program Files\R\R-3.4.4\bin\x64 \Rlapack.dll'
to 'C:/Program Files/R/R-3.4.2/library/stats/libs/x64/ .
After this the web Application can access external R libraries.
Note: I assume that your web Application Run locally but creates a problem when you try to run it on IIS.
I was solving same issue. For IIS I did not find the solution. I was also debugging the R.NET code, but solution by setting correct path to R folder did not work.
The solution is created additional layer, which cover running R project (actually create own R server). I used self hosted WCF service,
https://learn.microsoft.com/en-us/dotnet/framework/wcf/feature-details/how-to-host-a-wcf-service-in-a-managed-windows-service
which is practically console application and has benefits application running not in IIS application pool. This solution also cover singleton REngine problem. In case you run the instance or REngine in IIS, there is no posibility dispose it, only by stop application pool. For self-hosted service you can set trigger for restarting application in case memory leak.
During this implementation I discover problem run R.NET again R 3.4.3 in debug mode on console application I get error "The library "..." could not be load", so I used the R 3.4.2. which work nice. 86x installation is required - independent the your application run in 64x/ANYCPU environment.
Have you found any other solution for that?
I am working on a Service Fabric application that contains a number of stateless services and a single stateful service. When I publish the first time, everything is fine and it's deployed to my local cluster. After this, if I try to package or publish the app without explicitly stopping it first, I get the following error:
CSC : error CS2012: Cannot open 'C:...\ProjectFolder\obj\x64\Debug\ProjectName.pdb' for writing -- 'The process cannot access the file 'C:...\ProjectFolder\obj\x64\Debug\ProjectName.pdb' because it is being used by another process.'
According to process explorer, the PDB is locked by my own ProjectName.exe. This is the single stateful service in my application.
Why would my exe lock its own PDBs? I could understand if it was Visual Studio doing it.
I see nothing in my own code that should cause this, so I'm assuming it's something in the Fabric code I'm calling.
The PDBs are deployed with the application, but it's the files in the original source directory that are locked - why not the PDBs adjacent to the running code?
Why do I only see this error relating to the stateful service, and not the stateless services?
I suspect this has something to do with the stateful service generating lots of errors on startup, which Fabric may need symbols to properly display.
How can I stop it happening - either using the correct PDBs or not using them at all unless I'm debugging through Visual Studio?
Edit: Raised on github. Current workaround for this:
A current workaround at this point in time would be to restrict the Network Service access to the pdb in the build folder (obj\x64\Debug).
Based on the issue that was raised, it looks like this is now fixed.
"Going to close the issue as we believe both issues have now been addressed by the 5.6 runtime and the 1.6 tooling."
Seems upgrading is now the answer to point 4. If anyone can answer 1-3 I'd be very happy to move the big green tick.
I have a problem regarding the Visual Studio Setup Project and uninstalling an application.
This is a very basic installer, installing an ApplicationLauncher.exe C# .NET 4.0 console application and an Application.Common.dll (a dependency of the application ApplicationLauncher.exe).
The installation is a success, copying both the exe and DLL into the program files folder C:\Program Files (x86)\Company\ApplicationLauncher\.
My problem comes when uninstalling the application (through the MSI) - the uninstall seems successful, however it leaves Application.Common.dll behind, and doesn't remove it as I would expect.
I've used ProcessExplorer to make sure nothing else is using the DLL, no explorer windows are open during the uninstall.
Is this the expected functionality and do I have to create a custom action to remove this DLL? Or have I done something wrong? :S
It seems I was able to fix this issue by renaming the solution and product name of the application, I'm not sure how this fixed it, but it did.
My only thoughts here is this traversed through to the installer, where the application installed into a different folder, thus not applying the same permissions to the DLL..
It's not expected, no. It will happen if you ever done any of the following with your setup and installed it:
Marked the file Permanent.
Marked the file SharedLegacyFile true.
These are project settings, but if you set either of them and do the install it will stay behind. You can unset them in the setup project but that's too late - you've marked that component permanent or sharedlegacy on the system. If you use a brand new system, like a fresh virtual machine, reset these values if they are set and rebuild the MSI and do the install/uninstall does it still happen?
I had the same problem. Then I have tried to install and unistall my app on Windows XP and that had worked.
Renaming the ProductCode is treating the symptoms not the cause. The problem occurs when the uninstaller doesn't remove the dll. The next install will use the dll again and can't remove it on an uninstall event because it's still used by the other program.
These steps hopefully solve the problem:
Install your Software
Open CMD (with admin privileges) and run:
msiexec /x {ProductCode} /L*V "C:\CustomPath\FileName.log"
The ProductCode can be found when hitting F4 on the Setup Project
Open the log file and search for the lines that look something like this:
Disallowing uninstallation of component: {6CEC09F6-9108-7062-A692-2BCBACEE3BD8} since another client exists
Disallowing uninstallation of component: {A0A0FA84-CC0D-C5C4-1F57-169788C4482D} since another client exists
Disallowing uninstallation of component: {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX} since another client exists
All these components have to be removed from the registry by hand. To do this the GUID (e.g. {6CEC09F6-9108-7062-A692-2BCBACEE3BD8}) first has to be converted into a packed/compressed GUID (e.g. 6F90CEC6801926076A29B2BCCAEEB38D). I found a Website where one can run a script to do this. Find the following code on the website and replace the right side with the GUID from the log.
string inStrGUID = "{6CEC09F6-9108-7062-A692-2BCBACEE3BD8}";
Open the registry (as an administrater) and search (Edit -> Find...) for the compressed GUID (uasually it's somewhere in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Components\)
Delete the folder that is equal to the compressed GUID. The values inside the folder should be a path to the dll.
Once deleted select the parent folder (...\S-1-5-18\components) and hit Edit -> Find...
Repeat these steps (4-7) for all components from the log file.
It's also a good idea to delete all files still present in the original folder that weren't uninstalled.
Can one prevent this from happening?
I don't know. This really isn't that easy to reproduce. Some other post on SO have suspected the install/uninstall option in Visual Studio to be the cause of the problem but I have a different theory:
This bug might be the result of RemoveExistingProducts in InstallExecuteSequence in the Setup being executed too late and therefore not removing dlls at the right time. This bug is known for years and can be fixed by doing this. If you need help with Orca this explains how to install it.
My question is, when an application uses a web reference is one supposed to hand out something extra along with the .exe file?
I have made an application that uses a web reference for dotMailer API (it's for email campaign management).
The application compiles and runs fine on my PC. But tested it on another machine and kept crashing. After loads of troubleshooting I found this is due to calls using the dotMailer API.
I discovered that Fusion logger is the right tool to show me the reason for failing, downloaded and installed it on the test machine and viewed the logs. Some say the operation was successful while others say it failed even though the assembly download was successful. The test machine has web connectivity. I am just starring at the screen frozen don't know how to tackle this.
Is one supposed to copy something from the Visual Studio project folder over to the test machine for a web reference to work?
I am using Visual Studio 2010
Go to your Project -- > Reference --> Right Click on dotMailer (Your Reference) --> Go to Properties --> Set Copy Local property value as True. Like Below
While distribution of project, we should set the references "Copy local Property as True". Then only the referred Dll's will be copied to publish bin folders.
Reference is here
Related Question / Thread is here
I'm trying to create an installer for a Windows Service I developed. This installer has a custom UI at one point and it's the first time I do something like that so I installed and uninstalled the service a few times to make sure everything was like I wanted to in the installer.
Now my issue is that when I try to install the service, it fails with Error 1001: Specified service already exists, but the service is listed nowhere in the registry, the services.msc console, or by sc query.
Can anyone give me a clue of what's happening and how to fix it?
Thank you
Edit: Thanks for your replies. I re-opened the management console and restarted the computer and am still getting the error. Changing the ProductCode and UpgradeCode did not fix the issue either. There's also absolutely no reference to the service in the registry.
Run in command line (adm mode):
sc delete service_name
Service names with spaces must be quoted.
Update: Try this:
sc query type= service > services.txt
and verify that the service does not appear with another name.
if you try to remove a service when it's still running, it's marked as deleted so you won't see it in the list of services but any attempt to add a service with the same name will fail afterward. the easy solution is to restart. this way windows removes the service before login or you can remove it from Registry in HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services
be careful with that
Some time when we install windows service from setup then also problem arises like we can not uninstall. here i will discuss few steps which solve this problem to remove install application entry from Add/Remove panel and again we can install the same application.
Open registry by Regedit and To locate the program's uninstall key, navigate to the following sub-folder:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
select Uninstall icon and start find your program by name. when it will appear then just remove that entry from registry. after remove the program name will not display in Add/Remove. problem will be solved and again user can install the same application.
i got this tips from this location http://eugene2k.hubpages.com/hub/How-to-force-uninstall-a-program and i tested and it worked.
The below steps is for how to remove services when service is not starting or file missing or corrupted.
1- Open cmd as administrator
sc delete servicename
2- open run > regedit , back it up first and then browse to
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services
and delete the service key
3- remove the folder where win service was installed
4- reboot the machine
http://www.winvistatips.com/windows-service-wont-uninstall-t535569.html
Have you closed and re-opened the management console? Also restarting your comp might help. Sometimes a service gets marked for uninstall and doesn't really finish until one of the two things listed above happen.
This has happened to me before and generally one of these two things fixed it.