Issues during Installation of windows service - c#

I am installing windows service using installutil.exe and got the following error.
C:\Windows\Microsoft.NET\Framework\v4.0.30319>InstallUtil.exe D:\WindowsService1
.exe;
Microsoft (R) .NET Framework Installation utility Version
4.0.30319.33440 Copyright (C) Microsoft Corporation. All rights reserved. Exception occurred while initializing the installation:
System.IO.FileNotFoundException: Could not load file or assembly
'file:///D:\Win dowsService1.exe;' or one of its dependencies. The
system cannot find the file s pecified..
My file is located in exactly that location.

install your service with sc command.
open an CMD with admin permission and run following command to install.
SC create WindowsService1 displayname= "WindowsService1" binpath= "D:\WindowsService1.exe" start= auto

Fist thing I see is the space before ".exe" but that is probably a type here on the site. What you could do is build the service with all reference set "copy local" to true, and copy the entire bin folder to the machine you need to publisch

Related

Running in VS2019 Admin Cmd window -- gacutil.exe error: "Failure adding assembly to the cache. The system cannot find the file specified."

Running in VS2019 Admin Cmd window -- gacutil.exe error: "Failure adding assembly to the cache. The system cannot find the file specified."
GAC util path: C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.7.2 Tools\gacutil.exe
Command line: gacutil.exe -i "DuraSysOrdFuncs.dll" -r FILEPATH "C:\Windows\DuraSysOrdFuncs.dll" ""
I picked this version of GACUtil just because the C# library was built with a target framework of .Net 4.7. It isn't clear to me that it much matters.
Doesn't matter what I put in the 3rd parameter of -r. Doesn't matter where I put my assembly on my local disk. Same error message.
I'm trying to put this in GAC because I need to call it from an SSIS package running on SQL Server 2016. I have opened Sysinternals ProcMon per a suggestion of #HansPassant in a different post. Not familiar with tool so haven't found the file location error. . . if that is the actual issue.
Any input much appreciated
The answer, as the commenters noted, and as ProcMon indicates, is to just include the path for the .net assembly you're registering: gacutil.exe -i "C:\YourAssemblyFileLocation\YourDLL.Dll" That's all it takes. . .you don't normally need -r parameters, etc. Thanks!
You can use powershell to register assemblies into GAC. It doesn't need any specific installation.
Set-location "C:\Temp"
[System.Reflection.Assembly]::Load("System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
$publish = New-Object System.EnterpriseServices.Internal.Publish
$publish.GacInstall("C:\Temp\myGacLibrary.dll")
If you need to get the name and PublicKeyToken, refer How do I find the PublicKeyToken for a particular dll?

Error on Creating EventLog source with windows service installation

I have developed a windows service in c#, The project works fine in DEBUG mode, also the project is built with out any errors. When I try to install the service using InstallUtil.exe, I get below error and the service is not installed. Could someone please help what is going wrong here.
Installation command
Open command prompt in admin mode
Navigate to C:\Windows\Microsoft.NET\Framework64\v4.0.30319\
Run below command
installutil.exe C:\Users\Public\TestService\MyService\bin\Release\MyService.exe
Error
Creating EventLog source MyService in log Application...
An exception occurred during the Install phase.
System.Exception: Value cannot be null.
Parameter name: path1
Below is the complete installation log.
Microsoft (R) .NET Framework Installation utility Version 4.8.4161.0
Copyright (C) Microsoft Corporation. All rights reserved.
Running a transacted installation.
Beginning the Install phase of the installation.
See the contents of the log file for the C:\Users\Public\TestService\MyService\bin\Release\MyService.exe assembly's progress.
The file is located at C:\Users\Public\TestService\MyService\bin\Release\MyService.InstallLog.
Installing assembly 'C:\Users\Public\TestService\MyService\bin\Release\MyService.exe'.
Affected parameters are:
logtoconsole =
assemblypath = C:\Users\Public\TestService\MyService\bin\Release\MyService.exe
logfile = C:\Users\Public\TestService\MyService\bin\Release\MyService.InstallLog
Installing service MyService...
Service MyService has been successfully installed.
Creating EventLog source MyService in log Application...
An exception occurred during the Install phase.
System.Exception: Value cannot be null.
Parameter name: path1
The Rollback phase of the installation is beginning.
See the contents of the log file for the C:\Users\Public\TestService\MyService\bin\Release\MyService.exe assembly's progress.
The file is located at C:\Users\Public\TestService\MyService\bin\Release\MyService.InstallLog.
Rolling back assembly 'C:\Users\Public\TestService\MyService\bin\Release\MyService.exe'.
Affected parameters are:
logtoconsole =
assemblypath = C:\Users\Public\TestService\MyService\bin\Release\MyService.exe
logfile = C:\Users\Public\TestService\MyService\bin\Release\MyService.InstallLog
Restoring event log to previous state for source MyService.
Service MyService is being removed from the system...
Service MyService was successfully removed from the system.
Attempt to stop service MyService.
The Rollback phase completed successfully.
The transacted install has completed.
The installation failed, and the rollback has been performed.
did you try to go into your path : C:\Users\Public\TestService\MyService\bin\Release (if you built in debug use the debug folder)
and here, use command : installutil MyService.exe
You said the projet work well in debug mode. can you install it in debug ?

Unable to compile .cs file from regular command prompt, only Developer Command Prompt?

I have this rather simple console application I developed using Visual Studio. With it, I have put together a simplistic C# program where using the "Developer Command Prompt for VS2015" I navigate to my directory and run "csc Program.cs" to compile the "Program.exe" file. From there I can type "Program ***" and pass a filename such as "Program file.asm".
Everything is working perfectly. However, I want to run this from the normal command prompt. When I compile within the Developer Command Prompt for VS2015 the below two lines are output:
Microsoft (R) Visual C# Compiler version 1.3.1.60616
Copyright (C) Microsoft Corporation. All rights reserved.
And when I navigate I can see that under C:\Windows\Microsoft.NET\Framework I have folder options for:
v1.0.3705
v1.1.4322
v2.0.50727
v3.0
v3.5
v4.0.30319
When I do:
C:\Windows\Microsoft.NET\Framework\v3.5\csc.exe C:\directory...\Program.cs
Output is:
Microsoft (R) Visual C# 2008 Compiler Version 3.5.30729.5420 for Microsfot (R) .NET Framework version 3.5
Copyright (C) Microsoft COrporation. All rights reserved.
c:\Users\directory...\Program.cs(5,24): error CS0234: The type or namespace name 'Tasks' does not exist in the namespace 'System.Threading' (are you missing an assembly reference?)
I then tried with v4.0.30319:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe C:\directory...\Program.cs
Which outputs:
Microsoft (R) Visual C# Compiler Version 4.6.1055.0 for C# 5
Copyright (C) Microsoft COrporation. All rights reserved.
This compiler is provided as part of the Microsoft (R) .NET Framework, but only supports language versions up to C# 5, which is no longer the latest version. For compilers that support newer versions of the C# programming language, see http://go.microsoft.com/fwlink/?LinkID=533240
CSCD777AE6152014D6AAEC769E73B879B29.TMP: error CS1567: Error generating Win32 resource: Access is denied.
wrning CS1610: Unable to delete temporary file 'c:\Windows\Microsoft.NET\Framework\v4.0.30319\CSCD777AE6152014D6AAEC769E73B879B29.TMP' used for default Win32 resource -- The system cannot find the file specified.
Can anyone help me understand why this is all working fine for Developer Command Prompt but failing for regular command prompt even when fully quantifying the path for "csc.exe"?
I think you are trying quite a few things without understanding what is happening.
I have put together a simplistic C# program where using the "Developer Command Prompt for VS2015" I navigate to my directory and run "csc Program.cs" to compile the "Program.exe" file.
When you run the C# compiler from this specific command prompt, csc.exe it is in the path. To find out what exact command is being run, on UNIX, we use a command called which. You can try gnu-utils or cygwin, or just manually iterate over all directories specified in the PATH (any case) variable to find out which exact path the csc.exe in question resides. This way you will know what is the exact path of the compiler.
UPDATED: You can use the where command on windows to find the full path of the command (Thanks to #ScottChamberlain)
c:\Users\directory...\Program.cs(5,24): error CS0234: The type or namespace name 'Tasks' does not exist in the namespace 'System.Threading' (are you missing an assembly reference?)
run csc.exe /? at the same prompt and see all the options that the compiler supports. One of them is /r for adding a reference to a dll
When I do:
C:\Windows\Microsoft.NET\Framework\v3.5\csc.exe C:\directory...\Program.cs
CSCD777AE6152014D6AAEC769E73B879B29.TMP: error CS1567: Error generating Win32 resource: Access is denied. wrning CS1610: Unable to delete temporary file 'c:\Windows\Microsoft.NET\Framework\v4.0.30319\CSCD777AE6152014D6AAEC769E73B879B29.TMP' used for default Win32 resource -- The system cannot find the file specified.
You probably want to be in the directory of your file Program.cs. This way you have write permissions to the folder for generating necessary output files. You can also use the /out option to specify the output file name
Can anyone help me understand why this is all working fine for Developer Command Prompt but failing for regular command prompt even when fully quantifying the path for "csc.exe"?
Most probably since the PATH environment variable is different. The Visual Studio Command Prompt, sets up a bunch of environment variable after starting the command prompt. You can see the difference in the environment between the two prompts by running the set command on both the terminals and doing a diff of their outputs. Needless to say, certain environment variables will always be different and that is not due to VS.NET
And as #KeithNicholas had mentioned in the comments, you can simply invoke C:\Program Files (x86)\Microsoft Visual Studio *\Common7\Tools\VsDevCmd.bat to set up your regular command prompt like visual studio command prompt

Project upgrade from VS 2013 to VS 2015 windows 8.1 universal apps

I was about to update my existing windows 8.1 universal app to VS2015 along with its portable projects.But it fails with below error
"Error : DEP6810 : MdilXapCompile.exe failed with error code 1004. See log file 'C:\xxx\xxx.WindowsPhone\obj\ARM\Debug\MDIL\MDILXapCompileLog.txt' for more details"
The Log file Contents
Error: Compile filter argument specified non-existent file: C:\xxx\xxx\xxx.WindowsPhone\obj\ARM\Debug\MSIL\PhoneLibrary\Microsoft.SharePoint.Client.Portable.dll
Invalid argument
Microsoft (R) MDIL XAP Compiler - Version 4.0.0.0
Copyright (c) Microsoft Corporation. All rights reserved.
Usage: MDILXAPCompile /In:<InputPath> /Out:<OutputPath> /Config:<ConfigPath> [/CompileFilter:<Assembly Path>;<Assembly Path>] [/Timeout:<Timeout>] [/Log:<LogPath>] [/AppX]
/In - Path to directory containing files to process
/Out - Path to directory to place processed files in
/Config - Path to configuration file
/CompileFilter - Optional restrictive list of assembly files in InputPath,
separated by semi-colons, to be compiled.
/Timeout - Optional timeout in milliseconds before killing the Crossgen process. Overrides config file timeout value. Use -1 for infinite timeout, 0 for application default (2 hours).
/Log - Optional path to log file
/AppX - Specifies that assemblies correspond to an AppX package
Relative paths are relative to this executable's directory.
I get this error only when I debug the project but it works normal when i generate package and deploy it to device.
Answers are highly appreciated.
I got this solved. But may not be the direct way. Its quite strange.
I referred my dll's from the folder(named as PhoneLibrary) inside the app. As per log file location "C:\xxx\xxx\xxx.WindowsPhone\obj\ARM\Debug\MSIL\PhoneLibrary\Microsoft.SharePoint.Client.Portable.dll" it failed to create the folder.
So i just created folder in that location and copied my dll's in that folder and worked great.

IBM DB2 issue--System.BadImageFormatException: Could not load file or assembly IBM.DB2.DLL or one of its dependencies

I am getting the above mentioned error message. I have made enough research and tried out various options but still no luck.
Here arethe details below:
OS: Windows 7 64 bit version
Visual studio version: 2013 Premium
.NET framework version is : 4.0.30319
ASP.NET version: 4.0.30319.34249
IIS version: 7.0
DB2 installed path: C:\Program Files (x86)\IBM
DLL path: C:\Program Files (x86)\IBM\SQLLIB\BIN\netf40\IBM.DB2.dll
DLL Version: 9.7.4.4
I have also changed my solution configuration manager platform to Any CPU and also I have changed the settings in the application pool by setting the property enable 32-bit application to True.
But still am getting the same error. Is there any other workaround?
Please help me with your suggestions.
This problem happened me these days and it was solved following what this IBM document says, that is to go to the reference in the project and set "Copy local" to false for DB2 dlls, referencing diretly the ones from the DB2 client setup
I'm going to jump in here and put my steps to fully automate the deploy of the .Net Data Providers from IBM since this is the first of MANY errors that I ran into attempting to get this to work. I hope someone avoids being put on the wheel of pain by reading these steps.
Add the reference to the DB2 .Net Data Providers using nuget: https://www.nuget.org/packages/IBM.Data.DB2/
You will notice that it give you a hint of the pain you are about to endure:
NOTICE - This packakge requires the IBM DB2 client software to be installed locally and available on your %PATH% environment variable.
Next, you will need to set the DLLs that you just referenced not be included in the BIN folder by setting the DLLs to Copy Local FALSE by Right Clicking the references and going to properties.
If these are put in the BIN you will get the error message:
[BadImageFormatException: Could not load file or assembly 'IBM.Data.DB2' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
IBM's reference to the issue: http://www-01.ibm.com/support/docview.wss?uid=swg21902663
Now in order to begin developing you will need to install the driver packages or the run time client from here https://www-945.ibm.com/support/fixcentral/ (good luck) or you will be receiving the following errors:
Exception Message: Could not load file or assembly 'IBM.Data.DB2, Version=9.7.4.4, Culture=neutral, PublicKeyToken=7c307b91aa13d208' or one of its dependencies. The system cannot find the file specified.
Developing time! Have fun!
Now you need to deploy and you realize you have a problem with automating installing a DB2 driver and start looking for solutions:
How to properly deploy IBM DB2 data provider
ASP.NET -- IIS7 -- IBM DB2 Issue
Not wanting to manually install on DEV/QA/STG/PROD, I found the that you can install IBM Data Server Client Package silently via command line using a response file. About halfway down this page: https://www.ibm.com/support/knowledgecenter/SSEPGG_11.1.0/com.ibm.swg.im.dbclient.install.doc/doc/t0007315.html you will find the relevant information after this line:
To install the IBM Data Server Driver Package software, run the v10.5fpX_ntxYY_dsdriver_EN command. The X represents the fix pack number value and the YY represents either 32-bit or 64-bit release.
A link to a sample response file to copy and change with your information is here: https://www.ibm.com/support/knowledgecenter/SSEPGG_11.1.0/com.ibm.db2.luw.apdv.sample.doc/doc/dsdriver/s-dsdriver-rsp.html
Now you are all set right? WRONG. Apparently a "successful install" doesn't include moving the appropriate DLLs to the GAC and registering them in the Registry. Thanks IBM: https://www-01.ibm.com/support/docview.wss?uid=swg21618434
Not wanting to give up in my automated deploy dreams, I put all the above knowledge into a Powershell script:
param([string]$driverPath,[string]$installPath)
[System.Reflection.Assembly]::Load("System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
$publish = New-Object System.EnterpriseServices.Internal.Publish
Write-output "Installing v11.1.2fp2a_ntx64_dsdriver_EN.exe"
& "$driverPath\v11.1.2fp2a_ntx64_dsdriver_EN.exe" /u "$driverPath\DB2.cfg" /l "$driverPath\log.txt" | Out-null
$publish.GacInstall("$installPath\bin\netf20\IBM.Data.DB2.dll") | Out-null
$publish.GacInstall("$installPath\bin\netf20_32\IBM.Data.DB2.dll") | Out-null
$publish.GacInstall("$installPath\bin\netf40\IBM.Data.DB2.dll") | Out-null
$publish.GacInstall("$installPath\bin\netf40_32\IBM.Data.DB2.dll") | Out-null
$publish.GacInstall("$installPath\bin\netf20\IBM.Data.DB2.Entity.dll") | Out-null
$publish.GacInstall("$installPath\bin\netf20_32\IBM.Data.DB2.Entity.dll") | Out-null
$publish.GacInstall("$installPath\bin\netf40\IBM.Data.DB2.Entity.dll") | Out-null
$publish.GacInstall("$installPath\bin\netf40_32\IBM.Data.DB2.Entity.dll") | Out-null
Now you will find that you are getting another error. Until now you were only fighting IBM.Data.DB2.*.dll issues. The following error is now present:
Exception Message: Unable to load DLL 'db2app64.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
Come on IBM!! A quick Google search finds the same results we got with the #1. "Change your app to 32-bit" This is wrong, of course, we know better now!
I'll help you out and let you know that this DLL was installed along with the OTHER DLLs, just in a different path!
Just add them to the bottom of the Powershell script:
$publish.GacInstall("$installPath\bin\db2app.dll") | Out-null
$publish.GacInstall("$installPath\bin\db2app64.dll") | Out-null
Now you have a fully automated DB2 .Net Provider to connect to a DB2 Server.
Hope this helps.
EDIT: You can alternately isolate the required DLLs and only include those in a folder (like /lib/) and deploy those instead of installing with an exe. Reference the /lib/ location instead of the driver install location to move to the GAC.
In my case, this was happening with Windows Server 2012 R2 Standard,
This is an error caused by the package not installing in the Global Cache Assembly make sure you check C:\Windows\Assembly to ensure your program is installed properly under GAC_32 , GAC_64, you should see
If not this is what I had to do in order to solve it.
1)I had to check the version I had installed in order to ensure compatibility.
2)The "IBM DATA SERVER CLIENT" did not install properly, using the GUI due to a bug, so it had to be run silently using this as an administrator
3) Due to the server nature I had to install .Net 3.5 using IBM-Steps <-- Link
That did not work for me so I had to use MS-Steps <-- Link
with these lines
DISM /Image:C:\test\offline /Enable-Feature /FeatureName:NetFx3 /All /LimitAccess /Source:D:\sources\sxs
4) Found out the one of the issues is that the "IBM DATA SERVER CLIENT" was still not install properly by checking the DB2LOG folder which is in your C:\User_Dir\Document\DB2LOG
5) Had to install the "IBM DATA RUN TIME CLIENT" latest fix in my case for 9.7 is fix 10, can be accessed free on IBM's download page you just have to register it takes 1 minute and you get a response asap, make sure you follow through else wait until your stupidity factor kicks in.... me...
6) Then I was able to install "IBM DATA SERVER CLIENT"
7) Double check to ensure you can see "DB2COPY1" or whatever you choose to call your installation copy.
I'm sure you don't need both, however I will no loginder mess with this thing.
DB2 Install
Download latest IBM Data Server Driver Package from this (https://www-01.ibm.com/support/docview.wss?uid=swg27016878) link.
Execute the file As Administrator and keep defaults except for the place where it asks to install features on your local driver. Click on that and select Install all features and subfeatures ... on your local drive. Not sure if it effects.
The driver will be installed by default in C:\Program Files\IBM\IBM DATA SERVER DRIVER.
Instance will be installed by default in C:\ProgramData\IBM\DB2\IBMDBCL1. Default instance name for this is IBMDBCL1.
You should set your connetion sting in this location C:\ProgramData\IBM\DB2\IBMDBCL1\cfg, in this file db2dsdriver.cfg.
<dsncollection>
<dsn alias="DBDSNSAMPLE" name="DBDSNSAMPLE" host="127.0.0.1" port="50001"/>
</dsncollection>
<databases>
<database name="DBDSNSAMPLE" host="127.0.0.1" port="50001">
</database>
</databases>
</configuration>
Note: you can uninstall the driver from Programs and Features
After adding connection you can test the connection with testconn40.exe. Open cmd and locate to C:\Program Files\IBM\IBM DATA SERVER DRIVER\bin and execute:
> testconn40 DBDSNSAMPLE
This command won't login you (because we did't specify user credentials in .cfg file), but at least it will show the proper message, which means your .NET app will work. Otherwise, it will show some exception errors.
DB2 in Visual Studio
Install IBM.Data.DB2 package from nuget.
Then, in the References you will see both IBM.Data.DB2.dll and IBM.Data.DB2.Entity.dll.
Here is the testing code:
using (var conn = new DB2Connection($"Database={u.db2a};UserID={u.db2u};Password={u.db2p};Server={u.db2i}"))
using (var cmd = new DB2Command())
{
cmd.CommandText = "SELECT * FROM Table1";
cmd.Connection = conn;
conn.Open();
using (var reader = cmd.ExecuteReader())
{
while (reader.Read())
{
Console.WriteLine(reader.GetValue(3));
}
}
}
Notes
In case if dlls are having issues:
Go to References and click on IBM.Data.DB2, in Properies windows set Copy Local to False. Same thing to IBM.Data.DB2.Entity . (This will make sure that those two dlls will not show up in bin folder anytime, when you build/compile your project. Instead project will use these DLLS from GAC. And we are using them only to resolve our code)
Another thing is, it might be that those dlls were not install correctly in GAC while initial installation. Thus you may try to install them manually:
Go to Developer Command Prompt for Visual Studio and run those lines step by step:
gacutil /i "C:\Program Files\IBM\IBM DATA SERVER DRIVER\bin\netf20\IBM.Data.DB2.dll"
gacutil /i "C:\Program Files\IBM\IBM DATA SERVER DRIVER\bin\netf20_32\IBM.Data.DB2.dll"
gacutil /i "C:\Program Files\IBM\IBM DATA SERVER DRIVER\bin\netf40\IBM.Data.DB2.dll"
gacutil /i "C:\Program Files\IBM\IBM DATA SERVER DRIVER\bin\netf40_32\IBM.Data.DB2.dll"
gacutil /i "C:\Program Files\IBM\IBM DATA SERVER DRIVER\bin\netf20\IBM.Data.Informix.dll"
gacutil /i "C:\Program Files\IBM\IBM DATA SERVER DRIVER\bin\netf20_32\IBM.Data.Informix.dll"
gacutil /i "C:\Program Files\IBM\IBM DATA SERVER DRIVER\bin\netf40\IBM.Data.Informix.dll"
gacutil /i "C:\Program Files\IBM\IBM DATA SERVER DRIVER\bin\netf40_32\IBM.Data.Informix.dll"
gacutil /i "C:\Program Files\IBM\IBM DATA SERVER DRIVER\bin\netf20\IBM.Data.DB2.Entity.dll"
gacutil /i "C:\Program Files\IBM\IBM DATA SERVER DRIVER\bin\netf20_32\IBM.Data.DB2.Entity.dll"
gacutil /i "C:\Program Files\IBM\IBM DATA SERVER DRIVER\bin\netf40\IBM.Data.DB2.Entity.dll"
gacutil /i "C:\Program Files\IBM\IBM DATA SERVER DRIVER\bin\netf40_32\IBM.Data.DB2.Entity.dll"
gacutil /i "C:\Program Files\IBM\IBM DATA SERVER DRIVER\bin\db2app.dll"
gacutil /i "C:\Program Files\IBM\IBM DATA SERVER DRIVER\bin\db2app64.dll"
from cmd you can try this:
regsvr32 "C:\Program Files\IBM\IBM DATA SERVER DRIVER\bin\db2app64.dll"
regsvr32 "C:\Program Files\IBM\IBM DATA SERVER DRIVER\bin\db2app.dll"
Also, before doing these all, you need to make sure that connection between you and your vendor is open (what ever it's, VPN, Site to Site VPN and etc)
It sounds like you are trying to load a 32 bit compiled IBM DB2 driver from a .NET application running in 64 bit mode. Try changing configuration manager to run in x86 mode.
I just recently had this problem. I found that the publishing process in Visual Studio was putting a copy of IBM.Data.DB2.dll in the BIN directory of the web application. When it is manually deleted, the web application starts operating correctly. I do not know why it's getting published, as it is not directly referenced.
The easiest way I've found to resolve this, is to use a Post-build event.
Project properties --> Build Events --> Post-build event command line
Here's the command line I'm using:
del $(TargetDir)\IBM.Data.DB2.dll
I faced the same problem and got the solution from the following link. It worked when I removed the local copy and set copy to local property to False.
A link to the solution

Categories

Resources