Hi, My issues aren't with the returned serialisable classes - it's with the remote classes. Strangely, I can create an instance of my remote factory, but when the factory tries to return an instance of another MarshalByRef class, it fails with a "System.InvalidCastException: Return argument has an invalid type.".
Dino -----Original Message----- From: Discussion of advanced .NET topics. [mailto:[EMAIL PROTECTED] On Behalf Of Krebs Kristofer Sent: Wednesday, 28 February 2007 23:38 To: ADVANCED-DOTNET@DISCUSS.DEVELOP.COM Subject: Re: [ADVANCED-DOTNET] Alternatives to remoting Hi I had a similar problem like this and managed to solve this by implementing my own binder. How do you get hold of the object references that you are unable to cast? In my case I couldn't do this in a certain situation: [Serializable] class MyType { ... public object Clone() { MemoryStream ms = new MemoryStream(); BinaryFormatter fmt = new BinaryFormatter(); fmt.Serialize(ms, this); ms.Position = 0; return fmt.Deserialize(ms); } } In another assembly referencing the assembly containing MyType this call failed: MyType copy = (MyType)original.Clone(); // Unable to cast I found this very strange but the original was loaded from a different location. This was solved by using another binder than the default. public object Clone() { MemoryStream ms = new MemoryStream(); BinaryFormatter fmt = new BinaryFormatter(); fmt.Serialize(ms, this); --> fmt.Binder = new MyBinder(this.GetType().Assembly); ms.Position = 0; return fmt.Deserialize(ms); } /// <summary> /// Binder to handle serialization of self /// </summary> class MyBinder : SerializationBinder { Assembly _asm; public MyBinder(Assembly asm) { _asm = asm; } public override Type BindToType(string assemblyName, string typeName) { if (assemblyName == _asm.FullName) return _asm.GetType(typeName); else return Type.GetType(String.Format("{0}, {1}", typeName, assemblyName)); } } Basically my implementation of the binder tries to load the type from a specific assembly otherwise load it from the referenced assemblies. // Kristofer -----Original Message----- From: Discussion of advanced .NET topics. [mailto:[EMAIL PROTECTED] On Behalf Of Dean Cleaver Sent: den 27 februari 2007 21:33 To: ADVANCED-DOTNET@DISCUSS.DEVELOP.COM Subject: [ADVANCED-DOTNET] Alternatives to remoting Hi, I've been using Remoting on several projects with great success for several years now, however I've now struck a hurdle - one of my projects is an Outlook Addin, and it also loads as OCX controls into HTML pages in Outlook folders - these are each in separate AppDomains over which I have no control, and one uses shadow copy one doesn't, so they load the same files from different locations. This causes remoting to complain that it can't cast A to A, because it thinks they're different. Putting them in the GAC isn't really an option either, as this system is auto-updated over the web while running as a user. Otherwise, the GAC might have solved the problem. The obvious choice is WebServices, but some projects have 150+ classes in them that I call - I'd have to make 150+ web services, but also I'd have to add 150+ web references to the Business Services project - seems very messy to me. Another option is to create one massive web service with functions like Aload, ASave and BLoad etc that call the existing Data Access class functions, and return the same objects/values. Seems like it would get out of hand quickly - 150+ classes with 10+ methods each - that's a lot of functions in one web service. Are there any other options I have missed? Dino =================================== This list is hosted by DevelopMentor(r) http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com =================================== This list is hosted by DevelopMentor(r) http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com =================================== This list is hosted by DevelopMentor® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com