Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. delegate and AppDomains

delegate and AppDomains

Scheduled Pinned Locked Moved C#
questionjson
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    VizOne
    wrote on last edited by
    #1

    Hi! I have an application with two AppDomains (say A and B) where an object X that lives in AppDomain A is passed to AppDomain B where a method subscribes for an event of object X. This means that when object X fires its event, the delegate is called over AppDomain boundaries. This works well as long as the method the event-delegate points to (in AppDomain B) is public. If the method is anything but public (e.g. internal, private or protected) I get an SerializationException saying that it the serialization does not serialize delegates pointing to non-public members. I find this strange and annoying as I don't want to make the method in question public. Any suggestions? Thanks in advance Regards, Andre Loker

    H 1 Reply Last reply
    0
    • V VizOne

      Hi! I have an application with two AppDomains (say A and B) where an object X that lives in AppDomain A is passed to AppDomain B where a method subscribes for an event of object X. This means that when object X fires its event, the delegate is called over AppDomain boundaries. This works well as long as the method the event-delegate points to (in AppDomain B) is public. If the method is anything but public (e.g. internal, private or protected) I get an SerializationException saying that it the serialization does not serialize delegates pointing to non-public members. I find this strange and annoying as I don't want to make the method in question public. Any suggestions? Thanks in advance Regards, Andre Loker

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      While it may be annoying, it certainly isn't strange. When crossing application boundaries (including distinct AppDomains), .NET Remoting marshals the call to another context, similar in concept (regarding this discussion) to your code calling another class's code. Depending on derivation and location, the method must be public in order to call it. If you absolutely don't want to make it public, there is a way although it is difficult. You can extend RealProxy and the ProxyAttribute (with which you attribute your class that defines the handler). The RealProxy derivative can catch method calls (as well as other types), which you can use to override the default behavior so that the delegate is serialized. It's tricky, and if you're not too familiar with .NET Remoting I suggest you pick up a book like "Microsoft .NET Remoting" from MS Press[^] or "Advanced .NET Remoting" from Ingo Rammer[^].

      Microsoft MVP, Visual C# My Articles

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups