Web service on IIS 7.5 suddenly ceases to work - c#

I have developed a SOAP Service on basis of C# and .NET 4.0 (service.dll). The service internally loads a C++ DLL (cpp.dll) and does stuff. I deployed that on an IIS 7.5 running on Windows 7 and it all worked well. However, recently the service stopped working.
If I now try to create a service using the wcftestclient application shipped with Visual Studio, I get following error message:
Warning: There were errors loading types in an assembly loaded from
'C:\Windows\assembly\GAC_MSIL\System.ServiceModel\3.0.0.0__b77a5c561934e089\System.ServiceModel.dll'
some types in the assembly could not be loaded and will not be
available to the tool.Error: An error occurred in the tool.Error:
Object reference not set to an instance of an object.
I did not touch any of the DLLs or so. Googling the error message didn't lead me anywhere, so I'm desperate now and would appreciate some help with this. What does the message mean and what should I investigate?
I can open http://myserver/myservice/service.svc?wsdl and it shows me the correct WSDL. Also, I have a command line tool which itself loads the cpp.dll and this works too, so the problem cannot be there. It has to be something with the service.dll or with the settings in IIS or with a recent Windows update screwing up my .NET environment... right?

Related

.NET Core ASP.NET app unable to load unmanaged DLLs under IIS

In our ASP.NET Core web api, we are attempting to load unmanaged C++ code from a DLL that we included in our published folder.
This fails upon calling the endpoint that loads the DLL. The exception is as follows:
DllNotFoundException: Unable to load DLL 'libespeak-ng' or one of its dependencies: The specified module could not be found. (Exception from HRESULT: 0x8007007E)
It should be noted that this DLL loads and functions fine when the app is run through Visual Studio. Running the app in Kestrel with the dotnet command also works properly, on the same server. It is only inside of IIS that the app fails to load this DLL.
We have made sure the IIS user (as well as the default app pool) has permission to read and execute the DLL. We've tried placing the DLL in the app bin folder, in System32, in SysWOW64, and in the various inetsrv directories. None of this has resolved the issue.
Looking at ProcMon, it seems like IIS does not even attempt to load the DLL. Dependency Walker doesn't reveal any missing dependencies that aren't also missing when running it with Kestrel on any machine.
After many hours of struggling, and attempting the solutions commented by other users, we finally figured out the issue.
The DLL was trying to access some Windows APIs that did not exist in Windows Server 2012 R2, apparently. Once we updated the server to the latest windows server version, everything worked without issue.

Visual Studio External references not working on published website

I have created a web project that works fine when published and when debugging inside Visual Studio. When I add an external reference via the reference manager, it adds it properly and runs within Visual Studio to the internal IIS Express. When I publish the website to my server, the external apps do not work and it looks as though they are not even available.
What am I missing to get these Interop dll's to be seen in the web server?
There must be some 'hook' to connect to these dll's that is used when run locally that doesn't exist when deployed. In a nutshell, this is an API that I am trying to deploy to the server where the app is installed and running. The API functions normally when run locally within VS, but does not work when I deploy it to the IIS website on the same server. The IIS website has full permissions, which is not an issue because this site is only run on an internal network and not to the web.
UPDATE:
Digging deeper in the mystery I suspect it has something to do with The way the COM interops, or API's, are used. I have set the project properties to 'Generate COM interop' and have the API reference properties set to Isolated=false and Embed Interop Type=True. I have also set the ComVisible=true for the entire project. There are no build errors. There are no errors in the .net or IIS logs that I can see. I have set full permissions to all the applicable folders. So, what am I missing?
I guess I have the community stumped on this one. I am going to try to change to a late bound caller and see if that helps.
For those interested it seems the issue was with the DCOM permissions on the server. Still doesn't work, but at least the server sees the API now, just has COM Exception errors but that is way beyond my ability. There is no source code or vendor support for the API. Kind of makes me mad since I paid for the API and when I ask for assistance they say there is no support available.
If you're referencing local external assemblies, then add them as part of the solution (say in a ThirdPartyAssemblies folder), and then set each DLL to "Copy Always" under Properties.
That should make sure that your assemblies are copied to your bin on build, and they'll be visible on your web server.

C# - InstallUtil 32bit installs service but throws error on startup

I've been working on a Windows Service off and on for some time now and I have finally finished it. On my local machine (Win7, 64bit, .NET 4.5, VS 2013), I've been able to successfully install and run the service which takes info from a website and places it in a SQL table.
Now I want to install this service on a different computer on the network, and it has to be this computer because I've been told to do it like this.
The other computer is running 64 bit Windows Server 2003 R2.
My problems arise when I try to install the service. I'm using plain old command prompt because I do not have the VS command prompt. The code is:
C:\WINDOWS\Microsoft.NET\Framework64\v4.0.30319>InstallUtil.exe C:\MyService.exe
Doing this gives me the error "Exception occurred while initializing the installation:
System.BadImageFormatException: Could not load file or assembly 'filepath' or one of its dependencies. An attempt was made to load a program with an incorrect format.."
So I tried doing this instead:
C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319>InstallUtil.exe C:\MyService.exe
Using this 32 bit InstallUtil.exe seemed to work as the service would install successfully and it showed up in my services.msc list. When I try to start the service I then get this error message: "Could not start the service on Local Computer. Error 193: 0xc1"
I'm getting really frustrated/confused with this, so any help what-so-ever would be greatly appreciated!! Thanks for reading.
<---------------------------------------------EDIT---------------------------------------->
I've changed the configuration to Release and Any CPU, copied and pasted it to the server via Network Folder and installed it once again. Still getting the same error.
<---------------------------------------------EDIT---------------------------------------->
The answer is in my post below if anyone is wondering, or are having the same issue I was.
And I've figured it out. Where I was using Windows Server 2003, it tends to like the .NET 4 Framework and where the service was developed in Visual Studio 2013 it defaults to the .NET 4.5 Framework. All I had to do, along with several edits to make the service a bit more efficient, was change the target in the VS project to the .NET 4 Framework and rebuild/reinstall on the server.
It has now started without an issue and is communicating with the SQL server as intended. Big thanks to Hans Passant for pointing me in the right direction, I would more than likely still be in the process of figuring this out. So thanks!!

Inquiry on debugging an IIS web application

I developed a web application which is working perfectly on my local (laptop), now, when I copied-pasted the .dll (which came from my laptop) and other .aspx files on another PC and browsing the web application on the localhost (new machine), I am encountering an error saying Server error in "/" application,
Parser error message: Could not load type 'namespace.of.my.library'
Additional info:
When I build/publish the .dll, it's only producing one dll file, so I am sure that I didn't missed anything when I copy-pasted the code into a different machine.
I also checked the framework version of the generated dll and the framework version of IIS and they are the same with my laptop.
And since the web page is producing this error, I don't know how to debug, I can't get any relevant info out of it.
Did I missed something?
Thanks!

WCF remote debugging fails - no symbols loaded

I am trying to remotely debug wcf service on IIS 6. It has been working fine until yesterday. Now breakpoints are not being hit and warning message says "No symbols have been loaded for this document". I've solved this by restarting iis and app pool, but it worked just for a few days. Now I have the same problem. I've read almost all advices on the Internet about this, I've checked build options, GAC, ASP Temporary folder. When the service file is loading the VS is writing that my dlls is loaded. But when I looking at the debug->modules window it shows that this modules haven't been loaded. I still can see exceptions while debugging. Now I am temporarily using Debug.WriteLn() for debugging, but it takes a lot of time and effort. Any help will be appreciated.
P.S. I use VS 2010, WinXp Sp3 on my PC and Windows Server 2003 on server.
[Updated] Is there any patches for VS 2010 that can fix remote debugging problem ?
[Updated] I've noticed that w3wp process type is x86 now, although my service was called by client before and it should be managed type.
Finally, I 've found a solution. I copy my WCF output files to the same location on the server as in my pc. It is quite wierd but debugging works perfect.
Here is your answer, and the issue I ran into:
I've noticed that w3wp process type is x86 now, although my service
was called by client before and it should be managed type.
Typically to get the w3wp.exe process to actually show in the Attach to Process debug dialog is to just browse to a site in IIS locally. This will spin up that process and make sure it is available to select.
However, you must browse to a site using the same app pool type as the WCF service you want to debug. If you select an app pool using a 32-bit process (x86) and attach to this for a WCF service expecting a x64 version, the resulting "No symbols have been loaded for this document" will be displayed and breakpoints will appear as 'hollow' red circles.
First: Please Install IIS 7, its much recommended!
2nd: it happens sometimes with everyone I guess, deploying the service again with the options (Delete existing files (checked), with source code (checked) ), resolves the problem.
Actually that's the only solution is working in my case
Regards,
Mazhar Karimi

Categories