How to stop .NET Core application from shutting down when it's dll is overwritten? - c#

I have a .NET Core application which is invoked from my NodeJS web application (this .NET Core app is migrated from .NET Framework to run it on a Linux server to perform some specific tasks).
So far it works fine, but every time I overwrite the .dll file (to update the app) all running instances of the app are being automatically shut down without any exceptions or anything. As if I would call Environment.Exit(). All work in progress is gone and the calling NodeJS service is receiving just an empty response.
I don't quite understand the need for that as Linux allows to overwrite the file while it's running...
Probably it's working like this to make sure web servers are restarted if their .dlls are updated. But this behavior is undesired in my case and I hope there is a way to disable it.
Tried to google it up but cannot find anything on the matter.
Thanks in advance for any advices :)

I've ended up with writing some kind of shadow copy system.
When my NodeJS app is noticing a new version of the .NET Core app uploaded to the server it renames the folder with the current version ('active') to something like 'old' + timestamp, then renames the new version to 'active'. It is blocking any attempts to launch the app while this renaming process is happening.
This approach helped to completely solve the issue.

Related

How to deploy an EntityFramework application in a intranet?

I have deployed a Windows Forms Application (Visual Studio 2013 C#) to a file share and will get my users to run the app from this file share. The app uses Entity Framework 6 and works fine from the file share but there is a delaying in loading the EntityFramework.dll during execution for the first time.
Is it possible to move just this dll from the file share to the local pc and tell the app to use it from the local pc?
As #tede24 stated, before trying to solve this problem, make sure EntityFramework.dll is actually your problem.
Once you make sure it is, here are the options I can think of:
1) Use ClickOnce
ClickOnce is not popular, but it still seems to be the preferred way for deploying intranet applications. Yes, it supports version checking and auto updates.
2) Use some sort of XCopy installation
You can create a batch/PowerShell to copy the application content locally from your intranet. If you want to go futher, you can even verify whether the version is the latest before launching.
3) Try putting EntityFramework in the GAC on the client machine (not recommended)
EntityFramework is not meant to be GACed, but you can still try to do that. I would strongly avoid it because of dependencies and update problems you might run into.

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.

how to run a winform Exe in normal Pc not having .net frame work installed

I developed a winform application using C# in visual studio 2008. Now i want to run the exe on another PC which doesn't have .net framework or Visual Studio. I am sending the application using Zip via email. The second PC downloads that application and extracts into a normal folder and then it executes the exe file.
But i am getting the exception that .net frame work v 2.0 must be installed.
Can you please tell me how to run that exe without .net frame work installed?
(Amended for #Merhdad's sanity :-))
The short answer: You can. You shouldn't.
The long answer: You could technically create your own unmanaged bootstrapper that goes and download the .NET client profile redist and silently installs it using the MSI APIs, and then loads the CLR and hosts it in the process in order to execute the managed code, after which it silently uninstalls the .NET Framework from the machine.
The Disclaimer: I know few people that could pull that off. They would be the first to tell you not to do it.
The alternative hack answer: You can also use one of the tools #Mehrdad mentioned. i can't comment whether they work or not. However, you should be aware that this leaves your app linked to a specific snapshot of the .Net framework code, and for every security update you need to take, yuo have to relink and release an update of your application as well.
The alternative open source answer: You could ensure your WinForms app builds and runs on Mono, and deploy Mono side-by-side with the app. I've heard it supports that scenario.
The alternative IT answer: You could create a VM appliance with stripped down Window image that has .Net and your app only, and ship it as a single executable.
The right answer: Create an installer for your app that installs the .NET Framework for your customers.
Yes! You can do this with a variety of programs, and Spoon seems to be among the most up-to-date ones.
(Of course, this doesn't mean that you should, just that you can.)
This cannot be done. You must have the .NET Framework in order to run the application.
I solved the problem.I added a package in visual studio.I added Setup and deployment as a new project to my solution.later i added exe to that package.so if client machine runs the setup it'l create exe and can run the application successfully.
yeah,you can do that by converting your whole application to an installer.just check it out, it will helps u a lot
http://www.youtube.com/watch?v=PCnfGUT-K-4

Is it possible to deploy an ASP.NET application as desktop application (with server component)

Question: I created an ASP.NET web application.
Now it originally was meant for deployment on a webserver.
That is working, so, so far so good.
My question now is: Is it possible to deploy it as a desktop-application, too?
That is to say the installer installs some kind of server, plus the web application, configures the server to run this application on a localhost URL, and then creates a link in the start menu/desktop, where it opens that url (website, the application) on localhost in a web browser?
I think it should be possible, though the server wouldn't be IIS, because this is a windows component which can't be separately installed.
Is there anything like this already out there ?
The nonplusultra would be that it only starts the server when you click on the shortcut.
I'm not sure, but you could use IIS express, when it will be released. Take a look to ScottGu's post Introducing IIS Express.
I almost went for Cassini.
But in the meantime, I found something better:
http://code.google.com/p/aspnetserve/
My mistake was searching for 'asp.net deployment server component' instead of 'asp.net embedded webserver'.
A really cool project.
Seems to work, at least for my needs.
Edit:
A much better choice is xsp4 from package xsp-2.10.2, courtesy of the mono-project.
http://download.mono-project.com/sources/xsp/
Works on both Linux and Windows, as well as Mac, with both mono and .NET framework, and that without GAC installation (in fact, without any installation).
The latest source is here:
https://github.com/mono/xsp/tree/master/src
You can use an easily installable ASP.Net webserver such as UltiDev Cassini.
I think what you are looking for is something like Adobe Air: http://en.wikipedia.org/wiki/Adobe_Integrated_Runtime
However you want to be able to run ASP.NET, which Adobe Air does not. My suggestion is to use Silverlight

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

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.

Categories

Resources