I have a solution “First” which consists of few projects. One of the projects references the other projects’s dlls. I add them via browsing to a specific location.
When I start another solution “Second” with one simple windows app, I add reference to “First” and to two of “First”‘s projects, which extend one from another. I add the references via code from “First”.
Now, in “First”, I have this line of code:
OneProject hello = OneProjectList[OneProjectList.Count - 1];
StringWriter sw = new StringWriter();
XmlSerializer serializer=new XmlSerializer(hello.GetType(),new Type[]{typeof(OneProject)});
serializer.Serialize(sw, hello);
The project crashes on the last line. The exception says {“[A]Something.X cannot be cast to [B]Something.X.
Type A originates from ‘Something, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null’ in the context ‘LoadFrom’ at location ‘goodLocation’.
Type B originates from ‘EL_CL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null’ in the context ‘LoadNeither’ at location
‘C:\Users\John\AppData\Local\Microsoft\VisualStudio\8.0\ProjectAssemblies\p3www12k01\EL_CL.dll’.”}
In the Output window in VS, I have: ‘devenv.exe’ (Managed): Loaded ‘C:\Users\John\AppData\Local\Microsoft\VisualStudio\8.0\ProjectAssemblies\p3www12k01\Something.dll’, No symbols loaded.
Why is this assembly getting loaded? That line in the Output window is shown while serializer.Serialize(sw, hello);, and right after that the program crashes.
Note that Something = hello.GetType().
Does it work if you take out the extra Type array from your XmlSerializer constructor?