[.NET 4 hosting] Loading config, exception handling menu

Shout-Out

User Tag List

Results 1 to 2 of 2
  1. #1
    Kryso's Avatar Active Member
    Reputation
    40
    Join Date
    Jul 2009
    Posts
    97
    Thanks G/R
    0/3
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [.NET 4 hosting] Loading config, exception handling

    .NET 4 doesn't allow us to catch "corrupted state exceptions" by default which is real pain when writing in-process stuff. Good thing is that we can re-enable it - either globally with app.config or HandleProcessCorruptedStateExceptionsAttribute.

    Source: HANDLING CORRUPTED STATE EXCEPTIONS


    HandleProcessCorruptedStateExceptionsAttribute works fine, but I'd like to enable it globally. The app.config works on standard application, but I'm unable to load app.config in injected assembly.

    My clr startup code
    Code:
    CComPtr<ICLRMetaHostPolicy> pMetaHostPolicy = NULL;
    CComPtr<ICLRRuntimeInfo> pRuntimeInfo = NULL;
    CComPtr<ICorRuntimeHost> pRuntimeHost = NULL;
    CComPtr<IUnknown> pAppDomainSetupUnk;
    CComPtr<IAppDomainSetup> pAppDomainSetup;
    CComPtr<IUnknown> pAppDomainUnk;
    CComPtr<_AppDomain> pAppDomain;
    
    HRCHK( CoInitialize( NULL ) );
    
    HMODULE loaderModule = GetModuleHandle( L"DotNetLoader.dll" );
    if ( loaderModule == NULL )
    	throw std::string( "Failed to locate loader module" );
    
    TCHAR moduleName[ 1024 ];
    if ( !GetModuleFileName( loaderModule, moduleName, 1024 ) )
    	throw std::string( "Failed to retrieve module name" );
    
    std::wstring loaderFullPath = moduleName;
    std::wstring libFile = L"Bsus.exe";
    std::wstring libDir = std::wstring( moduleName ).substr( 0, loaderFullPath.find_last_of( L"\\" ) );
    std::wstring libFullPath = std::wstring( libDir ).append( L"\\" ).append( libFile );
    std::wstring libConfig = std::wstring( libFullPath ).append( L".config" );
    DWORD retVal = 0;
    				
    HRCHK( CLRCreateInstance( CLSID_CLRMetaHostPolicy, IID_ICLRMetaHostPolicy, (LPVOID*)&pMetaHostPolicy ) );
    
    DWORD pcchVersion = 0;
    DWORD dwConfigFlags = 0;
    HRCHK( pMetaHostPolicy->GetRequestedRuntime( METAHOST_POLICY_HIGHCOMPAT, 
    	libFullPath.c_str(), NULL,
    	NULL, &pcchVersion,
    	NULL, NULL, &dwConfigFlags,
    	IID_ICLRRuntimeInfo,
    	(LPVOID*)&pRuntimeInfo ) );
    
    HRCHK( pRuntimeInfo->BindAsLegacyV2Runtime() );
    
    HRCHK( pRuntimeInfo->GetInterface( CLSID_CorRuntimeHost, IID_ICorRuntimeHost, (LPVOID*) &pRuntimeHost ) );
    
    HRCHK( pRuntimeHost->Start() );
    		
    HRCHK( pRuntimeHost->CreateDomainSetup( &pAppDomainSetupUnk ) ); 
    
    HRCHK( pAppDomainSetupUnk->QueryInterface( __uuidof(IAppDomainSetup), (void**)&pAppDomainSetup ) );
    
    HRCHK( pAppDomainSetup->put_ApplicationBase( CComBSTR( libDir.c_str() ) ) );
    HRCHK( pAppDomainSetup->put_ConfigurationFile( CComBSTR( libConfig.c_str() ) ) );
    
    HRCHK( pRuntimeHost->CreateDomainEx( L"Bsus", pAppDomainSetup, NULL, &pAppDomainUnk ) );
    
    HRCHK( pAppDomainUnk->QueryInterface( __uuidof(_AppDomain), (void**)&pAppDomain ) );
    
    HRCHK( pAppDomain->ExecuteAssembly_2( CComBSTR( libFullPath.c_str() ), NULL ) );
    
    pRuntimeHost->UnloadDomain( pAppDomain );
    
    FreeLibraryAndExitThread( loaderModule, 0 );
    As you can see I'm creating new domain and executing assembly in it. I can get configuration path later AppDomain.CurrentDomain.SetupInformation.ConfigurationFile but corrupt state exceptions are still not handled. If I put invalid content into app.config, it doesn't complain or anything - standart executable refuses to run with invalid app.config. Any idea how to make AppDomain load app.config?
    Tea and cake or death?!

    [.NET 4 hosting] Loading config, exception handling
  2. #2
    caytchen's Avatar Contributor
    Reputation
    138
    Join Date
    Apr 2007
    Posts
    162
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not a "proper" fix, but try putting your config file as "WoW.exe.config" into the respective WoW directory.

Similar Threads

  1. how do i edit script to load config file for necrobot
    By hardknoxni69a in forum Pokemon GO Chat
    Replies: 3
    Last Post: 08-16-2016, 12:23 AM
  2. [Selling] Selling my HOTS battle net account. Fully loaded!!!!
    By masterjfederer in forum General MMO Buy Sell Trade
    Replies: 1
    Last Post: 04-28-2014, 09:07 PM
  3. .NET CLR Hosting + Console woes
    By Shenlok in forum WoW Memory Editing
    Replies: 5
    Last Post: 10-21-2013, 03:55 AM
  4. [Selling] Battle.net Account Pre Loaded With $20
    By Leetraw in forum WoW-US Account Buy Sell Trade
    Replies: 7
    Last Post: 08-09-2012, 06:55 PM
  5. (Error) Stops At Loading Configs.
    By Ickybad in forum WoW EMU Questions & Requests
    Replies: 3
    Last Post: 03-02-2009, 09:18 PM
All times are GMT -5. The time now is 04:33 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