简体   繁体   中英

Is there a way to programatically “reboot” a .net assembly?

Hypothetical situation: let's say I have a 3rd party .net assembly being used in the ASP.Net web system that I'm working on that just kinda crashes every now and then. When it does so, all calls to it throw exceptions until the system is rebooted. This is, obviously, a little sub-optimal.

Is there a way to reboot just that assembly from the exception handler?

(Addendum: of course, the correct answer here is to get the vendor to fix their bug. However, the vendor in question is somewhat... "reluctant" to answer our emails. So, this reboot the assembly idea came about this morning as a MacGyver-eqsue piece of duct-tape. And then we realized none of us knew how to do it.)

Calling HttpRuntime.UnloadAppDomain() will force the application to terminate itself and restart when the next web request arrives. This results in everything being reloaded from scratch and should eliminate the corrupted assembly data.

Granted, this will kill any active sessions, but if the application is essentially crashed anyway this is probably acceptable.

您可以回收应用程序池,但这将启动所有当前用户并丢失其会话信息 - 这可能无关紧要,如果该网站已被坏dll冲洗了

OK, real answer... When the Web.Config file changes, the app gets recompiled and the app pool gets reset.

So, (and I hate to say this) programmatically change your web.config file.

BTW, I don't recommend doing this, so you can save your down vote for someone else.

假设...回到第三方供应商并让他们修复他们的错误。

It may be that when it crashes weirdly it still leaves an active process alive that hoses any subsequent attempts to call the DLL. If so, you may be able to find it programatically and kill it, which may fix the problem that was requiring a reboot.

Apart from modifying the web.config you can create an arbitrary file in your bin folder. This would restart your application.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM