BUG: ??????? AppDomainUnloaded ??? ??????? ????? ?????? ??????? Visual C++

?????? ????????? ?????? ?????????
???? ???????: 309694 - ??? ???????? ???? ????? ????? ??? ???????.
????? ???? | ?? ????

?? ??? ??????

???????

???? ??? ??????? ??? ??????? ?? ????????? ???????? ??? ???????? ??? ??????? ?????? ??? ??????? ??? ?? ??? ??????? ??? ???? - ??? - ????? ????? ???? DLL ????. ??? ???? ??????? ?? ???? ??? ??????? ??? MEC + +/ IJW ??????? ?? ASP.NET ?????????. ?? ASP.NET ? ???? ?? ???? ??????? ???????? ????????? ????? ????? ??? AppDomain ????. ??? ??? ?????? MEC ++ ??????? IJW ?? ??? ??????? ?? ????? ????? ??? AppDomainUnloadException.

?????

???? ?? ????? IJW ??? ????? DLL ????? ???? ??? ???????? ???????? ?????? ??????? ??????? C++ ??? ??????? ???? thunks ?????? ??? ?????????? ?? ?????? ??? ?????? ??? ??????? ?????? ??? ???????. ????? ??? thunks ??? AppDomain ????? DLL. ????? ??? ??????? ??? ????? ??? thunks ????? DLL ??? ????; ?????? ??? ??????? ?? ??? ????? ?????? ??? ????? ????? AppDomain ?????? ????? DLL ?? AppDomain ???.

????? ???????? ????? ?????? ?? ????????? ???????? ??? ???????? ??? ??????? ?????? ??? ??????? ?????? ?????? ???? AppDomain ??????? ?????? ??????? ?????? ??? ???????. ??? ??? ??? ?? ???? ????? AppDomain ??????, ?? ???? ?????? ???????? ???????? ??? ???? ????? ??? ?????? ??????? AppDomain.

???? ??????

??? ????? ?????? ??????? ???????? ??? ????? ??????? ?????:
  • ?????? ?? ?????? ??? ?????? ??? ??????? ?????? ??? ??????? ??? DLLs ?????
  • ?????? ?? ?????? ??? ?????? ??? ??????? ?????? ??? ??????? ?? ??? ????? ???????? ?????? (DLL)

????? ??? ???? ??? ????? ?????? ??? ????? DLLs ??????

?????? ???? ????? ??????? ??? ??? ??????? ????????.

???? ?????? 1

?????? ASP.NET ???? ????? ?????? ASP.NET ????? ????? ?? ???? ????? ????? ????? DomainUnload. ??? ???? ??? ????? ?????? ???? ???? DomainUnload. ?????? ????? ???? ??????? ???????:
  1. ?? ????? Application_Start ????? ASP.NET ????? ????? ???? ???? ????????? ??? ????? ????? AppDomain.
  2. ?? ?????? ?????? ????? Aspnet_wp.exe ?? ???????.
?????? ???? ??? ???? ?????? ???? ??????? ASP.NET ??? ????? ???????; ??? ????? ?????? ???? ???? ????? ??? ??????? ????? ??? ?????????. ?? ??????? ?????? ???? (IIS) 6.0 ??? ???? ??????? ???? ????? ??????? Windows Server 2003, ???? ????? ?????? ????? ???? ??? ??? ???????. ????? ?? ????????? ??? ?????? ????????? configuing ?? ?????? ???? Microsoft ?????? ??? ?????:
http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/2a231dcb-d786-4b6d-b3ba-bda04061a5e7.mspx?mfr=true
//Register a delegate to be called when the DomainUnload event fires.
protected void Application_Start(Object sender, EventArgs e)
{
     AppDomain.CurrentDomain.DomainUnload+= new EventHandler(ADUnloading);
}

//This method is called when the AppDomain is about to unload.
public void ADUnloading(object s, EventArgs e)
{
     System.Environment.Exit(0);
}
				

???? ?????? 2

??????? ???? ???????? ?? ?????? ??? ?????? ??? ??????? ?????? ??? ??????? ????????? ??? ???? ???? ??? ????? ???? ???? ???????? ???????? ???? (??? AppDomain ?????). ??? ????? ?????? ??? ????????? ???????? ??? ???????? ???????? ????? ????????? "?????? ???????" (P/???????) ????? ?? IJW.

?? DLL ??? ???? ??????? ?? ??? "???? ?? ?????????" ?? ??? ??????? ???? ????? ????????? ???????? ?????? ????? ??????? P/??????? ???????? ????? ?? ???????:
using namespace System::Runtime::InteropServices; // For DllImportAttribute.

namespace ManagedLib
{
        //Managed delegate declaration.
	public __delegate int ManagedFuncDelg();
	public __gc class Class1
	{
		
	public:
		[DllImport("Win32.dll", EntryPoint="callback")]//Assumes that you have a DEF file for the exports.
		static int Mgdcallback(ManagedFuncDelg*);
                //This method is called from the unmanaged DLL.
		static int InternalMethod()
		{
			return 123;
		}

		static ManagedFuncDelg* pd = new ManagedFuncDelg(0, &ManagedLib::Class1::InternalMethod);

                //This method is called by the client application.
		int Func()
		{
			int ret = ManagedLib::Class1::Mgdcallback(ManagedLib::Class1::pd);
			return ret;
		}
	};
}
				

????? ??? ???? ??? ?????? ??? ?? DLL ??? ?????

?? ??? ?????????? ???? ???? ?? ???? ???? ?????? ?????? (??? ????? ??? ???? & # pragma) ??????? ?????? ??? ?????? ???? ??? ??????? ?? ??? ????? ???????? ?????? (DLL) ? ??? ?? ???? ?? ??? "???? ?? ?????????" ?? ??? ???????. ?????? ???? ????? ??????? ??? ??? ??????? ?????:

???? ?????? 1

????? ?????? ?????? ????? ???????? ??? ??????. ???? ?? ????? ??????? P/Invoke ?? ??? ????? ???????? ?????? (DLL) ? ????? ????? DLL ?????? ?? ????? ???? ??? ???? ????. ???? ??? ?????? ??????? ????? ?????? ???? ??? ??????? ????. ????? ???????? ???????? ??????? ???? ?? ??? ???? ??????: ?? //This
//This is the helper DLL that enables you to marshal the delegate.
//Helper.cpp.
//Helper DLL code.
extern "C" __declspec(dllexport) void* __stdcall FuncInUmDll(void* pv)
{
	return pv;
}
				
???? ???????? ???????? ???????? ?? ????? ?????? ?? ??? "?????? ?????" ?? C++ ??????? ???? ?????? Helper.dll ??????:
#using <mscorlib.dll>
using namespace System;
using namespace System::Runtime::InteropServices; // for DllImportAttribute

namespace ManagedLib
{
      //Forward declaration.
      __delegate int delg();
      int nativefunc(int(__stdcall*)());
      [System::Runtime::InteropServices::DllImport("helper.dll", EntryPoint="FuncInUmDll")] int FuncInUmDll(delg*);
      //Managed component.
      public __gc class Class1{
	public:
            static int InternalMethod()
            {
                 return 123;
            }

            //This method is called by the client application.
            int Func()
            {
                 delg* d= new delg(0, &Class1::InternalMethod);
                 int ret = nativefunc((int(__stdcall*)())FuncInUmDll(d));
                 return ret;
            }
      };


      #pragma unmanaged
     //Unmanaged function calling the managed delegate.
     int nativefunc(int(__stdcall*pf)())
     {
            return pf();
     }
}
				

???? ?????? 2

?????? ????? ?? MEC ++ ??????? ?? DLLs ?????, ????? ??? ???????? ???? ?? ??????? ??? ? ?????? ???? ????? ??? ?????? ??? ???? ??? ?? ?? ???????? P/??????? ??? ?? ???? ?? ???? ?????? 2 ????????? 1.

?????

???? Microsoft ?? ??? ??? ?? Microsoft ???????? ??????? ?? ????? ??? ???????.

??????? ????

???? ??????? ??????? ???? ??? ??? ??? ????? ????? ??????? ?????? ?? ?????? ?????? ????? AppDomains ?????? ??????? ???????? ?? ?????? ??? ?????? ??? ??????? ?????? ??? ??????? ???? ?????? ?????? MEC ++ ? IJW. ASP.NET ???? ??? ??? ??????. ?? ASP.NET ? ??????? ???? ???? ?? ???? ?????? ??? ????? ????? AppDomain ???? ?? ???? ?? ??? ?? ???? ???? ??????? ????? ??? ????? ????? ????? (??? ???? ??????? Machine.config).

????? ????? ????? ??????

?? ??? ??????? ???? ??? ??????? ASP.NET ???????? ???? MEC ++ ????? ??? ?????? ???? ???? ???? ???? ??? ???? ????? ?? ???? MEC ++. ?????? ?????? ???? ?????? ??? ??? ????????? ???????:
  • ???? ???? ?? ??????? ?? ??? DLL ??? ????????
  • ????? ??? ???? ?? ??? ????? ???????? ?????? (DLL)
???? ????????? ???????? ??? ???????? ?? ?? ????? ???????? ???? ?????? ???? ?? ?????? ?? ???? MEC ++.

?? ????? ????????? ??????? ??? ?????? ?? ? ??? ??????? ?????? ??? ???? ???? ?????? ? AppDomain ?????? ?? ????? DLL ????? ??????. ??? ???? ??? ???????? ??? ?????? ?? ???? ???? AppDomain ?????? ?????? ??????? ????????? ???????? ??????? ?? ??? ??????.
  • ????? ??? ???? ??? ????? ?????? ??? ????? DLLs ??????

    ??????? ???? DLL ??? ????? ???? ?? ?????? ?? MEC ++ ??????? ????? ????? ???????:
    • ???????? IJW
    • ???????? P/???????
    ?????? ????? ???????? ???????? ??????? ??? ???? DLL (Win32.dll) ????? ?????.
    //Win32.h.
    #ifdef WIN32_EXPORTS
    #define WIN32_API __declspec(dllexport)
    #else
    #define WIN32_API __declspec(dllimport)
    #endif
    
    //Declaration.
    typedef int (__stdcall *funcptr)(void);
    WIN32_API int __stdcall  callback(funcptr ptr);
    
    //Win32.cpp Implementation.
    //This method is called by the Managed C++ component either by using P/Invoke
    //or by using IJW.
    WIN32_API int __stdcall callback(funcptr ptr)
    {
    	int rtn= ptr();
    	return rtn;
    }
    					
    ???? ????? C++ ????? ?? ??????? ??? ??????? ???? IJW ?????? ??? Win32.lib ??? ???? ??? ?? ??? ??? ????? ????????. ????? ????? ????????? ???????? ?????? ????? ??????? ??????? ???? ?? ??????. &# pragma
    #pragma once
    #include "win32.h"
    #using <mscorlib.dll>
    using namespace System;
    
    namespace ManagedLib
    {
    
    	public __gc class Class1
    	{
    		
    	public:
    		static int InternalMethod()
    		{
    			return 123;
    		}
    
                    //This method is called by the client application.
    		int Func()
    		{
    			int ret = callback((funcptr)Class1::InternalMethod);
    			return ret;
    		}
    	};
    }
    					
  • ????? ??? ???? ??? ?????? ??? ?? DLL ??? ?????

    ?? ??? ?????????? ??? ??????? MEC ++ ????? ??? ???? (??? ????? ??? ???? & # pragma) ??????? ???????? ???? MEC ++ ?? ??? ????? ???????? ?????? (DLL) ? ??? ?? ???? ?? ????? ????????? ???????? ??????.
    #using <mscorlib.dll>
    using namespace System;
    namespace ManagedLib
    {
          //Forward declararion
          int nativefunc(int(__stdcall*)());
          //Managed component
          public __gc class Class1{
    
    	public:
    
                static int InternalMethod()
                {
                     return 123;
                }
                //This method is called by the client application.
                int Func()
                {
                     int ret = nativefunc((int(__stdcall*)())Class1::InternalMethod);
                     return ret;
                }
          };
    
          #pragma unmanaged
         //Unmanaged function calling the managed delegate.
         int nativefunc(int(__stdcall*pf)())
         {
                return pf();
         }
    }
    					

?????

????? ?? ?????????? ?? ?????? ????? ????? Network (MSDN) ?????? Microsoft ???????:
?????? ???????
http://msdn2.microsoft.com/en-us/library/cxk374d9(vs.71).aspx?frame=true

??? AppDomain
http://msdn2.microsoft.com/en-us/library/system.appdomain(vs.71).aspx

??? AppDomainUnloadedException
http://msdn.microsoft.com/en-us/library/system.appdomainunloadedexception(VS.71).aspx

?????? ??????? ?? C++ ???????
http://msdn2.microsoft.com/en-us/library/aa712574(vs.71).aspx

????? ??????? ??? ASP.NET
http://msdn.microsoft.com/en-us/library/aa719794.aspx

??? ??? ??????? ???????
http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/34604f82-9175-4d48-b5ea-1e11f19db5f3.mspx?mfr=true

???????

???? ???????: 309694 - ????? ??? ??????: 30/???? ??????/1428 - ??????: 4.7
????? ???
  • Microsoft Visual C++ .NET 2002 Standard Edition
  • Microsoft .NET Framework 1.0
????? ??????: 
kbmt kbbug kbijw kbmanaged kbpending KB309694 KbMtar
????? ????
???: ??? ????? ??? ?????? ???????? ?????? ????? ???? ????? ?????????? ????? ?? ????????? ?????? ????. ???? ???? ?????????? ???? ?? ???????? ???????? ?????? ????????? ????? ????????? ???????? ????? ???????? ?????? ?? ?????? ??? ?? ???????? ???????? ?? ????? ??????? ?????? ??? ??????? ?????? ??. ?????? ?? ???? ??? ??????? ???????? ????? ?? ???? ????? ?????? ??? ????? ??? ????? ??????? ?? ????? ?? ?????? ??? ??? ??????? ??????? ?? ????? ????? ????? ????? ?????. ?? ????? ???? ?????????? ??????? ??? ????? ?? ??????? ?? ????? ?????? ?? ??? ????? ?? ????? ??????? ?? ???????? ?? ??? ???????. ???? ???? ?????????? ???????? ??? ????? ?????? ??????? ??????
???? ??? ????? ??????? ?????? ??????????309694

????? ???????

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com