FIX: LNK2020 Error Message When a Function Is Called to Retrieve a Delegate to Be Hooked onto an Event (323307)



The information in this article applies to:

  • Microsoft Visual C++ .NET (2002)

This article was previously published under Q323307

SYMPTOMS

When you compile code similar to the sample code in the "Steps to Reproduce the Behavior" section, you may receive the following error message:
LINK : error LNK2020: unresolved token (0A000003) DomainUnload
LINK : fatal error LNK1120: 1 unresolved externals

RESOLUTION

To work around the problem, use the following sample code:
AppDomain::CurrentDomain->DomainUnload += (unloader->GetHandler());
				

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article. This bug was corrected in Microsoft Visual C++ .NET (2003).

MORE INFORMATION

Steps to Reproduce the Behavior

The linker error occurs only under the following conditions:
  • When you use a function call to retrieve a delegate to be hooked onto an event.

    -and-
  • The event uses advanced syntax and is not implemented by using delegates.
To reproduce the problem, run the following code sample:
//test.cpp
// Compiler Option: cl /clr /LD /FAs test.cpp

#using <mscorlib.dll>
using namespace System;

__gc private class Unloader
{
public:
  void handler(Object *sender,EventArgs *args)
  {
  }
  Unloader()
  {
  }
  EventHandler *GetHandler()
  {
     return new EventHandler(this,handler);
  }
};

__gc public class User
{
public:
  User()
  {
    Unloader * unloader = new Unloader();
    AppDomain::CurrentDomain->DomainUnload += unloader->GetHandler();
  }
};
				

Modification Type:MajorLast Reviewed:4/11/2003
Keywords:kbfix kbbug kberrmsg kbManaged kbpending KB323307