Exception in Web Service locks DLL and prevents publishing. Workaround? - c#

I'm using a native DLL (FastImage.dll) in a C# ASP.NET Web Service that sometimes locks (can't delete it---says access denied); this requires stopping IIS to delete the DLL. The inability to delete this DLL in the bin folder of my published Web Service prevents me from publishing successfully (even though it thinks it published successfully!), which makes development and fixing the bug difficult (especially when it just happily runs old code since my changes may not be reflected on the server!). Note that the bug causing the Web Service to bomb and lock up the DLL is in my code, which is outside of said DLL, so I think this is a more general problem than just the FreeImage library (not to bring them any heat).
Has anyone experienced this?
Is there a way to make sure that when it says "Publish succeeded" from the VS IDE that it really means it, or to run sort of script to check that the files are really deleted before it attempts to Publish (like a pre-build step in VC++). (Right now I manually delete the files before publishing to make sure that I know the DLLs were replaced, instead of running old DLLs. It's still a problem, though if I can't delete the DLL.)
How would I detect whether a file was successfully deleted from a batch file? (so I can stop and start IIS if it fails)
Is it possible to stop and start IIS from a script (preferably from the Publish... action in the VS IDE) and if so, how?

Using the IISReset command line tool will only restart IIS on the local machine, not on a remote server to which you are publishing.
Assuming that you are publishing to a Windows 2003 server, I'd suggest trying the slightly less drastic step of stopping and restarting the IIS AppPool in the web site or virtual folder in which the web service runs. (That way you are not taking all sites that run on the target server offline.) This too assumes that the web service runs in its own app pool. Ideally it should, so you keep it isolated.
I'd recommend getting away from using the Publishing process and to look into using a Web Deployment Project. Here is a post on ScottGu's blog detailing VS 2005 Web Deployment Projects.
The advantage to the Web Deployment Project approach is that it provides you with all the power and capability of MSbuild, as it is really just a convenience wrapper around MSBuild. Here's a post from the MSBuild team about pre-build and post-build capabilities
Hope this helps.

You could use the IISReset command line tool to stop/restart iis. So you could write a simple batch file to stop iis, copy your files, and then restart iis. I'm not sure how to integrate this with the VS publish feature however.

Related

Updated to VS 2015, Azure 2.7, publish fails 'Access to path ... denied'

I have a cloud service project with three worker roles. Previously (VS 2013, Azure 2.5) everything published fine. When VS 2015 was available, I installed it on a clean VM and then installed Azure 2.7. I promoted my old solution and I can build and run locally just fine. I can build the cloud service project. But when I try to publish or package, I get the following error and the build fails.
Error:
Access to the path
'C:\Users[username]\AppData\Local\Temp\3xhd2e4m.wlw\roles[rolename]\base\x86\msshrtmi.dll'
is denied. C:\Program
Files\MSBuild\Microsoft\VisualStudio\v14.0\Windows Azure
Tools\2.7\Microsoft.WindowsAzure.targets 3003
When I go to Temp - there is no directory corresponding to 3xhd2e4m.wlw.
My resolution attempts so far include:
Removing the worker roles from the solution and trying to publish - fails with same error for the remaining project.
Removed read-only from temp
Tried to set everything to build x64
I really need some help since this blocking deployment and testing.
I have the same problem. According to an answer in another post (Deploying to Azure: "Access to the path ... msshrtmi.dll is denied"), the problem is related with an issue with the Azure SDK 2.7 and will be solved in version 2.7.1, supposed to be released shortly.
The problem occurs only when you try to publish from a 32-bit machine. Changing to a 64-bit machine should work.
I can't offer a specific solution as I haven't taken the plunge and upgraded to VS2015 yet, however I imagine this has something to do with the project file for the Worker Role's Cloud Service.
So, two options come to mind:
Create a new blank Worker Role Project with a single boilerplate Worker Role and check that it publishes/packages correctly. This will confirm whether this functionality works in VS2015 with Azure SDK 2.6.
If (1) works, consider adding one of your existing Worker Role Projects to the blank Worker Role Project in (1) and try the publish/package process again.
I find it hard to believe that the chaps at Microsoft have tried the upgrade path from v2.5 -> v2.6 of the SDK for Worker Roles... I've checked the v2.6 Release Notes and there doesn't appear to be any breaking changes related to this issue: https://azure.microsoft.com/en-gb/documentation/articles/azure-sdk-dotnet-release-notes-2_6/
I just got hit with this same issue and lost a few brain cells from it.
I have a defined directory in my ServiceDefinition.csdef that contains all the files I'm trying to copy out during my cloud service publish for my startup tasks, and I ended up including some .dll files as well. I was getting the same error as the OP of this question and after some time found out that I just couldn't include the *.dll files in my SourceDirectory path. I was able to include .cmd files just fine, but .dll and .config's were no good.
It wasn't good enough to exclude them from my project either, just the fact that the files were in that directory was enough to make VS yell at me.
For now I've just put all the offending files in a zip and I'm sending the zip file in my deployment, so it's a workaround, but was a painful one until I figured this much out.
Hope this helps..

Visual Studio 2010 Build issues

I am using visual studio 2010 on .net4.0 for my projects and I've found that each time I do a change in my project, I build and run but I cannot see my changes. I've found this happening once or twice mostly with my web service projects. I'm no pro with web services and am encountering this problem for the first time so would be grateful to anybody who can tell me what has gone wrong with my project and how to fix it.
Edit
My asmx file is where I have added an additional method but am not able to see it when I run F5
When you change the compiled code in a web service or site, you need to make sure you restart the web server hosting that service or site.
You are probably using the ASP.Net Development Server. Although Visual Studio starts this server for you, it does not restart it automatically when you rebuild. As a result, the server will still be referencing the previous version of the assembly that you changed.
In the Windows system tray you should see one or more icons depicting a web page with a purple gear overlapping it at the bottom-left.
There are three of them in this example:
You can stop the server by right-clicking its icon and selecting "Stop". (If you have more than one, you will learn to identify the one you need to stop by recognizing the port number shown in the tooltip when you hover the mouse over the icon.) Visual Studio will restart it when needed.
When you're making changes to a service or site, use this workflow:
Make code changes
Stop the ASP.Net Development Server
Rebuild the project containing the changes
Run
Client-side code vs. Server-side code
If you're changing client-side code (HTML or JavaScript), then you may need to force your web browser to refresh its cache. In Windows this is normally done by pressing CTRL+F5 in the browser (see refreshyourcache.com/en/cache for more info). If you're changing compiled code (C#), and restarting the server doesn't help, try restarting Visual Studio, then do Build -> Clean Solution, then Rebuild.
If you are facing issues in ASP.Net Development Server, I think you are better off creating a virtual directory in IIS and host your web service there. That way you should be able to make your changes, just build it (don't run it) and that should be available on your virtual directory and you just browse to webservice. Then you don't have to hit F5 again and again and don't have to worry about instances of ASP.NET dev server.
Following article contains good step-by-step instructions on how you do it on IIS 7.0. This article is about hosting a website - however, hosting a webservice is not different.
http://www.codeproject.com/Articles/28693/Deploying-ASP-NET-Websites-on-IIS-7-0

Unable to delete managed dll after using it in an asp.net web application

I am using NHunspell in an ASP.net web application. NHunspell wraps either Hunspellx86.dll or Hunspellx64.dll, both of which are unmanaged dlls.
The problem is this: when I dispose of my NHunspell object (which calls FreeLibrary from kernel32.dll), it seems that IIS is still hanging on to it - as evidenced by both windbg and tasklist /m. This is problematic if, say, I try to replace that dll using an automated build process, or run an installer to update my web application: everything fails because that dll is in use.
I'm wondering if anyone can confirm my suspicions that it is, in fact, IIS that is caching it? Also, why can I delete managed dlls right out from under IIS (even when tasklist reports those dlls as used by IIS)?
Finally, I'm looking for suggestions on what to do about actually being able to delete this dll for automated builds/installs?
Thanks very much!
If you are running on IIS 6 or greater, you could just stop the specific application pool. However, what is the exact build command that is not overwriting the file? We use a TFS build automation step that copies our files out to a test server running IIS which has all the dlls in use and it is no problem. What I can't confirm is how it does that, I suspect it is using XCOPY but I can't be sure.

Strange ASP.NET temporary dll FileNotFoundException!

I have strange problem during developing my ASP.NET website.
Facts:
The project is a "Website" not web application
Application pool runs under "Local system"
IIS 7.0 is in use
By killing iis worker process or restarting iis issue is gone.
I randomly get the following error from random locations!
Could not find file 'C:\Windows\TEMP\rksbjov5.dll'.
where each time dll name is something random.
Has anybody had this issue before? Any solution? or Why is this happening?
This is a known problem ...
Its because when you are debugging a website in visual studio you are constantly getting half way through things then stopping so memory leaks occur then files get randomly locked then a rebuild occurs and not everything is rebuilt.
perform an IIS reset then flush out the asp.net temporary files in the folder C:\windows\microsoft.net\your framework version\temp asp.net files\
you wont be able to delete all of these files without an iis reset.
This is simply a sign of not ideal integration between visual studio and IIS ... thats why visual studio comes with its own web service that you can use because on every rebuild the server is dropped, the app is recompiled, the service is the restarted and the app / site reloaded in to the fresh web service.
This is a particularly annoying problem when you do things like using db connections and don't close them before breaking out of a code block (typically happens when debugging) think of it as being much the same as calling gc.colect without having actually marked anything for garbage collection yet.
annoying i know.

Setting up CruiseControl.NET

I'm trying to set up CruiseControl.NET (1.6)
The installation completes successfully, however i cannot seem to start the actual service.
When running the CCNET.exe i get a console window that the last thing it writes is: Initialising Security.
Running the service from service control manager also does not work..
Trying to access localhost/ccnet returns no response.
What am i missing here? I have installed the product in the past with success, not sure what is wrong this time.
#lysergic-acid - Even if the main config is done (server/ccnet.config) and you are running it from a command prompt, you won't see the web dashboard yet.
If you are installing on IIS7, the setup process for the web dashboard requires steps that aren't in the CC.Net webdashboard setup docs in sourceforge.
What got me working was this CC.Net web dashboard installer page, which is from the Confluence site, rather than the source forge site: http://confluence.public.thoughtworks.org/display/CCNET/Installing+the+Web+Dashboard
In the comments area, there are specifics about IIS7 (I'm assuming that's part of the problem).
I am still having trouble with the service, so I can't help you there, but you can definitely run the web dashboard without the service as long as the cmd prompt version is running.
The setup of the virtual directory for the web front-end might of not completed successfully. Try using the IIS Service Manager to create an application around the Service folder. I think there's an issue with the install if you forget to unblock the download, but I haven't fiddled with it enough to be sure.
Keep in mind that the web front-end and ccnet service are two totally isolated pieces. You should be able to see the web front-end even if the ccnet service doesn't run.
I had trouble one time when installing it and IIS was set to disabled (and thus was not running), I had to uninstall CruiseControl.NET, start IIS and then reinstall CC.Net.
Do you have a firewall that blocks ports? The default port is 21234.
You need both the web part and the service part installed to be able to run CC.Net.

Categories

Resources