| re: serialization when using reflexion
Solution: Add a new assembly with data class.
--
Assembly A is using assembly B by reflexion.
Assembly A doesn't reference assembly B, and vice-versa.
Eventhough my class beeing serialized is only known and used by Assembly
B, by introducing an assembly C containing the class beeing serialized
it now works! (Assembly C is only referenced by assembly B)
Marc Falesse a écrit :[color=blue]
> Hello,
>
> My application needs to serialize a class, which was generated with
> xsd.exe from a XSD. It was working .NET 1.1 and it is working with .NET
> 2.0 very well.
> Now I need my assembly to be a plugin, and to be called by reflexion,
> but I get this Exception:
>
> Exception.Message:
> "There was an error generating the XML document."
>
> Exception.InnerException.Message:
> "Unable to cast object of type 'NMI.STARTi.EDI.Ingram.OrderRequest' to
> type 'NMI.STARTi.EDI.Ingram.OrderRequest'."
>
> The method I'm calling is static (I tried non-static as well) and the
> class being serialized is in the same assembly.
>
> There might be a problem with the Context, so I've tried different ways
> of invoking reflexion.
>
> Any ideas ? :(
>
> // Sérialize
> public partial class OrderRequest
> {
> public string ToXML()
> {
> XmlSerializer s = new XmlSerializer(typeof(OrderRequest));
> StringBuilder str = new StringBuilder();
> TextWriter w = new StringWriter(str);
> s.Serialize(w, this);
> w.Close();
> return str.ToString();
> }
> }
>
>
> // Using Reflexion
> public static T AppelStatic<T>(
> string assemblee,
> string classe,
> string methode,
> params object[] param)
> {
> if (!assemblee.ToLower().EndsWith(".dll"))
> assemblee += ".dll";
>
> string tmp;
> if (File.Exists(tmp = AppDomain.CurrentDomain.BaseDirectory +
> "bin\\" + assemblee))
> assemblee = tmp;
> else if (File.Exists(tmp = AppDomain.CurrentDomain.BaseDirectory +
> assemblee))
> assemblee = tmp;
> else
> throw new FileNotFoundException();
>
> Type t = Assembly.LoadFile(assemblee).GetType(classe, true, true);
>
> MethodInfo m = t.GetMethod(
> methode,
> BindingFlags.Public |
> BindingFlags.Static |
> BindingFlags.IgnoreCase |
> BindingFlags.InvokeMethod);
>
> object r = m.Invoke(null, param);
>
> return (T)r;
> }
>
>
>
> PS: I am using Visual Studio 2005 (final release)
>
>
> Many Thanks,
>
> Marc Falesse.
> NetMakers Ingénierie.
>[/color] |