The application domain in which the thread was running has been unloaded. menu

Shout-Out

User Tag List

Results 1 to 14 of 14
  1. #1
    xzidez's Avatar Member
    Reputation
    12
    Join Date
    Dec 2007
    Posts
    136
    Thanks G/R
    1/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    The application domain in which the thread was running has been unloaded.

    Hi there.

    To avoid that my dlls get locked Im hosting a new domain inside my target, which is wow : P..
    In my code later on I do the Present hook for D3D11 etc etc.

    However, here is my problem.
    When I reload my domain I it crashes, with the error "The application domain in which the thread was running has been unloaded.".
    I would guess that its because wow is currently inside my present hook while I unload the domain. But Im kinda clueless about what to do about it.

    Since the stuff is running in a different domain I cant really tell it to unload before I shut down the domain. If I try to unload inside deconstructors it still crashes. The only thing I can think of right now is communicating with my code using some sort of interprocess communication, wait for it to release all stuffs, and then unload the domain. But this feels really not like the best solution... And I figured Im not the first one using this approach ( searched the forum for alternative domain ), but I have yet to find someone with the similar problem?

    Anyone who have any bright ideas of how I should approach this problem?

    I hope you understand what I'm trying to say here Thank you

    The application domain in which the thread was running has been unloaded.
  2. #2
    Bananenbrot's Avatar Contributor
    Reputation
    153
    Join Date
    Nov 2009
    Posts
    384
    Thanks G/R
    1/3
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm throwing an exception when I want to stop my bot. This exception finally is caught in the shutdown handler, where I unhook from EndScene/Present and fire up a delayed (100 ms) worker thread, which is then responsible for unloading.

    I believe the AppDomainUnloadedException is thrown, because WoW's main thread is no .net thread (in some sense).
    Because of that, the unloader Thread (see AppDomain.Unload on MSDN) performs the unload operation immediately, when the window thread is still in your code. This makes it boom.

    I didn't really come up with a better thread sync solution yet, but waiting 100 ms should be enough for even the slowest cleanup code.

  3. #3
    lanman92's Avatar Active Member
    Reputation
    50
    Join Date
    Mar 2007
    Posts
    1,033
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's because the hook is set to call managed code. You have to unhook before exiting. I have a loop that idles around in my entry point code until Exit == true.

  4. #4
    Nesox's Avatar ★ Elder ★
    Reputation
    1280
    Join Date
    Mar 2007
    Posts
    1,238
    Thanks G/R
    0/3
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I had the same problem for a while. I forgot to uninstall some of my hooks before unloading the domain.
    Make sure you uninstall all your hooks before unloading the domain.

  5. #5
    Bananenbrot's Avatar Contributor
    Reputation
    153
    Join Date
    Nov 2009
    Posts
    384
    Thanks G/R
    1/3
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Nesox View Post
    I had the same problem for a while. I forgot to uninstall some of my hooks before unloading the domain.
    Make sure you uninstall all your hooks before unloading the domain.
    This only works if you call AppDomain.Unload either from an own .net Thread or from a different appdomain (e.g. the default appdomain).
    Like I said, I fully cleaned up my hooks and tried to unload from within the EndScene hook. This would unload the domain and cause every .net thread to throw a ThreadAbortException.
    Since the hijacked thread is no .net thread, no exception is thrown and it tries to execute further, what throws the AppDomainUnloadedExcpetion.

    Originally Posted by xzidez View Post
    If I try to unload inside deconstructors it still crashes.
    Lookup AppDomain.Unload on MSDN. This is expected behaviour.

  6. #6
    xzidez's Avatar Member
    Reputation
    12
    Join Date
    Dec 2007
    Posts
    136
    Thanks G/R
    1/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The thing is I know why its crashing. The problem is that I cant communicate with my code (which is running inside the domain) from outside.

    I can manually unhook the stuffs on my bot before I reload the domain. But this requires "two clicks". What I want to achieve is just pressing once to reload the domain.

    Edit: Bananenbrot, do you throw your exception from outside of the domain and catching it inside?.. or exactly how does this work?

  7. #7
    Bananenbrot's Avatar Contributor
    Reputation
    153
    Join Date
    Nov 2009
    Posts
    384
    Thanks G/R
    1/3
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When I press the 'stop button', my named pipe host sets a termination flag.
    When my EndScene hook is called the next time, I check for that flag and fire a custom exception, which I catch in the last possible handler.
    I do my usual cleanup stuff and then fire up a worker thread to call AppDomain.Unload for the current appdomain with a 100 ms delay.
    Meanwhile, the window thread exited my EndScene hook and WoW continues running.

  8. #8
    xzidez's Avatar Member
    Reputation
    12
    Join Date
    Dec 2007
    Posts
    136
    Thanks G/R
    1/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Bananenbrot View Post
    When I press the 'stop button', my named pipe host sets a termination flag.
    When my EndScene hook is called the next time, I check for that flag and fire a custom exception, which I catch in the last possible handler.
    I do my usual cleanup stuff and then fire up a worker thread to call AppDomain.Unload for the current appdomain with a 100 ms delay.
    Meanwhile, the window thread exited my EndScene hook and WoW continues running.
    Hmm ye I guess named pipes could work. Its an interesting solution you have there : ) Ill try it out later this week. Thank you


  9. #9
    Bananenbrot's Avatar Contributor
    Reputation
    153
    Join Date
    Nov 2009
    Posts
    384
    Thanks G/R
    1/3
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by xzidez View Post
    Hmm ye I guess named pipes could work. Its an interesting solution you have there : ) Ill try it out later this week. Thank you

    I was required to use named pipes, because I have an external Gui Application from where I monitor and inject into all running wow processes.
    If you host your user interface from within the same process, you don't have to use -inter-process communication.

  10. #10
    xzidez's Avatar Member
    Reputation
    12
    Join Date
    Dec 2007
    Posts
    136
    Thanks G/R
    1/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well correct me if Im wrong here.

    But if I typ something like

    Domain tmp = new ..... inside the process.
    I still have no way to communicate with the stuffs running inside tmp ( ? ).
    Here is the problem. I have this domain, in which wow is hooked, but I cant release my hooks from outside the domain and I dont know how to tell the stuff inside it to release.

  11. #11
    Bananenbrot's Avatar Contributor
    Reputation
    153
    Join Date
    Nov 2009
    Posts
    384
    Thanks G/R
    1/3
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use AppDomain.CreateInstanceAndUnwrap and inherit from MarshalByRefObject.

  12. #12
    xzidez's Avatar Member
    Reputation
    12
    Join Date
    Dec 2007
    Posts
    136
    Thanks G/R
    1/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When I tried this my shadowcopy refused to work. But perhaps this is the right approach, ill see what I can do about it
    Thanks for all help

  13. #13
    lanman92's Avatar Active Member
    Reputation
    50
    Join Date
    Mar 2007
    Posts
    1,033
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Look up Apoc's domain loader code. He has a few classes that work really well as a bootstrap for your actual modules.

  14. #14
    xzidez's Avatar Member
    Reputation
    12
    Join Date
    Dec 2007
    Posts
    136
    Thanks G/R
    1/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Got it running now. Problem was when I had a reference from my "main" project to the actual bot and tried to unwrap as the botclass itself he locked the dll..

    Switched so I have an interface in my domain handler, which the bot implements. Not it works like a charm

    Thanks for the help

Similar Threads

  1. [Bot] how to check the number of pokestop has been looted in Necrobot?
    By mickeymike1834 in forum Pokemon GO Hacks|Cheats
    Replies: 2
    Last Post: 08-15-2016, 12:57 AM
All times are GMT -5. The time now is 06:32 AM. Powered by vBulletin® Version 4.2.3
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Google Authenticator verification provided by Two-Factor Authentication (Free) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search