Click here to Skip to main content
15,894,017 members
Home / Discussions / C#
   

C#

 
GeneralRe: how can i enable back newToolStripMenuItem to true Pin
crisjala11-Mar-10 20:37
crisjala11-Mar-10 20:37 
GeneralRe: how can i enable back newToolStripMenuItem to true Pin
DaveyM6912-Mar-10 3:51
professionalDaveyM6912-Mar-10 3:51 
QuestionCatch Asynchronous Exception? Pin
Matthew Klein11-Mar-10 9:42
Matthew Klein11-Mar-10 9:42 
AnswerRe: Catch Asynchronous Exception? Pin
AspDotNetDev11-Mar-10 13:36
protectorAspDotNetDev11-Mar-10 13:36 
AnswerRe: Catch Asynchronous Exception? Pin
Luc Pattyn11-Mar-10 13:46
sitebuilderLuc Pattyn11-Mar-10 13:46 
GeneralRe: Catch Asynchronous Exception? Pin
Matthew Klein11-Mar-10 14:18
Matthew Klein11-Mar-10 14:18 
GeneralRe: Catch Asynchronous Exception? Pin
Luc Pattyn11-Mar-10 14:33
sitebuilderLuc Pattyn11-Mar-10 14:33 
QuestionRemoting & Events ("Exception has been thrown by the target of an invocation.”) Pin
bluescreen7611-Mar-10 8:41
bluescreen7611-Mar-10 8:41 
Hi,
I have been struggling with receiving events from a server to a client (using .NET remoting) for quite a long time now but I keep receiving the following message on client side (“Exception has been thrown by the target of an invocation.”). This message is received as the server is trying to call the event handler while the event handler exists in the client and since the client assembly is not available on the side of the server, this message comes.
Any idea?

Server Class library
-----------------------------
public delegate void MyDel();
 
    public class ServerClass : MarshalByRefObject
    {
        public event MyDel myEvent;
 
        public void StartServer (bool shouldFireEvent)
        {
            TcpServerChannel tsc;
            BinaryServerFormatterSinkProvider provider = new BinaryServerFormatterSinkProvider();
            provider.TypeFilterLevel = TypeFilterLevel.Full;
            IDictionary di = new Hashtable();
            di["port"] = 8085;
            di["bindTo"] = "172.19.35.191";
            tsc = new TcpServerChannel(di, provider);
            ChannelServices.RegisterChannel(tsc, false);
            RemotingConfiguration.RegisterWellKnownServiceType(typeof(ServerClass), "myURI", WellKnownObjectMode.Singleton);
 
            if (shouldFireEvent)
            {
                while (true)
                {
                    myEvent();
                    Thread.Sleep(1000);
                }
            }
        }
    }



Server GUI
-----------------------------
class ServerGui
    {
        static void Main(string[] args)
        {
            ServerClass server = new ServerClass();
            server.myEvent += new MyDel(ReceivedEventFromServerHandler); //lets register to event
            server.StartServer(true);
            Console.WriteLine("server is running. press enter to quit");
            Console.ReadKey();
        }

        static void ReceivedEventFromServerHandler()
        {
            Console.WriteLine("I am the server GUI. Got a message from the server");
        }
    }


Client
--------------

class ClientClass
    {
        static void Main(string[] args)
        {
            ServerClass server = (ServerClass)Activator.GetObject(typeof(ServerClass), "tcp://172.19.35.191:8085/myURI");
            server.myEvent += new MyDel(server_myEvent); //HERE IT CRASHES
            while (true)
            {
                Thread.Sleep(1000);
            }
        }
 
        static void server_myEvent()
        {
            Console.WriteLine("I am the client. Got a message from the server over the network");
        }
    }

AnswerRemoting & Events ("Exception has been thrown by the target of an invocation.”) - urgent! Pin
bluescreen7616-Mar-10 4:18
bluescreen7616-Mar-10 4:18 
QuestionOutlook addin integration problem with Outlook 2007 Pin
mosh_3311-Mar-10 6:52
mosh_3311-Mar-10 6:52 
QuestionSwitch versus an array of delegates Pin
PIEBALDconsult11-Mar-10 5:36
mvePIEBALDconsult11-Mar-10 5:36 
AnswerRe: Switch versus an array of delegates Pin
Saksida Bojan11-Mar-10 5:43
Saksida Bojan11-Mar-10 5:43 
AnswerRe: Switch versus an array of delegates Pin
Keith Barrow11-Mar-10 5:54
professionalKeith Barrow11-Mar-10 5:54 
GeneralRe: Switch versus an array of delegates Pin
PIEBALDconsult11-Mar-10 6:45
mvePIEBALDconsult11-Mar-10 6:45 
AnswerRe: Switch versus an array of delegates Pin
harold aptroot11-Mar-10 6:00
harold aptroot11-Mar-10 6:00 
GeneralRe: Switch versus an array of delegates Pin
PIEBALDconsult11-Mar-10 6:53
mvePIEBALDconsult11-Mar-10 6:53 
GeneralRe: Switch versus an array of delegates Pin
harold aptroot11-Mar-10 8:23
harold aptroot11-Mar-10 8:23 
GeneralRe: Switch versus an array of delegates Pin
PIEBALDconsult11-Mar-10 10:12
mvePIEBALDconsult11-Mar-10 10:12 
GeneralRe: Switch versus an array of delegates Pin
harold aptroot11-Mar-10 10:44
harold aptroot11-Mar-10 10:44 
AnswerRe: Switch versus an array of delegates Pin
Luc Pattyn11-Mar-10 6:04
sitebuilderLuc Pattyn11-Mar-10 6:04 
GeneralRe: Switch versus an array of delegates Pin
Dave Kreskowiak11-Mar-10 6:38
mveDave Kreskowiak11-Mar-10 6:38 
GeneralRe: Switch versus an array of delegates Pin
Luc Pattyn11-Mar-10 6:58
sitebuilderLuc Pattyn11-Mar-10 6:58 
GeneralRe: Switch versus an array of delegates Pin
DaveyM6911-Mar-10 7:56
professionalDaveyM6911-Mar-10 7:56 
GeneralRe: Switch versus an array of delegates Pin
PIEBALDconsult11-Mar-10 8:03
mvePIEBALDconsult11-Mar-10 8:03 
GeneralRe: Switch versus an array of delegates Pin
Dave Kreskowiak11-Mar-10 9:11
mveDave Kreskowiak11-Mar-10 9:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.