I'm loading a plugin assembly using Activator.Creat eInstanceFrom, and
inside this assembly is a settings class which gets serialized to XML.
The general code flow is as follows:
ObjectHandle pluginHandle = Activator.Creat eInstanceFrom(a ssemblyName,
type);
object plugin = pluginHandle.Un wrap();
....
// Settings is from the plugin Assembly loaded by the Activator
XmlSerializer x = new XmlSerializer(t ypeof(Settings) );
x.Serialize(set tingsFile, _settings);
// blows up here with this exception:
System.InvalidO perationExcepti on: There was an error generating the
XML document. ---System.InvalidC astException: Unable to cast object
of type '*.Settings' to type '*.Settings'.
at
Microsoft.Xml.S erialization.Ge neratedAssembly .XmlSerializati onWriterSetting s.Write3_Settin gs(Object
o)
Which is confusing considering the types are identical. However, when
I add the following XML to App.Config, the error goes away:
<system.diagnos tics>
<switches>
<add name="XmlSerial ization.Compila tion" value="4" />
</switches>
</system.diagnost ics>
What am I missing w.r.t. Activator.Creat eInstanceFrom and
XmlSerializer?
Thanks. 2 5099
On Apr 9, 10:53 am, christopher.wat f...@gmail.com wrote:
I'm loading a plugin assembly using Activator.Creat eInstanceFrom, and
inside this assembly is a settings class which gets serialized to XML.
The general code flow is as follows:
ObjectHandle pluginHandle = Activator.Creat eInstanceFrom(a ssemblyName,
type);
object plugin = pluginHandle.Un wrap();
...
// Settings is from the plugin Assembly loaded by the Activator
XmlSerializer x = new XmlSerializer(t ypeof(Settings) );
x.Serialize(set tingsFile, _settings);
// blows up here with this exception:
System.InvalidO perationExcepti on: There was an error generating the
XML document. ---System.InvalidC astException: Unable to cast object
of type '*.Settings' to type '*.Settings'.
at
Microsoft.Xml.S erialization.Ge neratedAssembly .XmlSerializati onWriterSetting s.Write3_Settin gs(Object
o)
Which is confusing considering the types are identical. However, when
I add the following XML to App.Config, the error goes away:
<system.diagnos tics>
<switches>
<add name="XmlSerial ization.Compila tion" value="4" />
</switches>
</system.diagnost ics>
What am I missing w.r.t. Activator.Creat eInstanceFrom and
XmlSerializer?
Thanks.
Moreover, *any* type from a loaded assembly (Assembly.Load,
Assembly.LoadFi le, Assembly.LoadFr om, Activator.Creat eInstanceFrom)
fails to be serialized/deserialized.
Assembly asm = Assembly.LoadFr om(Path.GetFull Path(assemblyNa me));
object plugin = asm.CreateInsta nce(type);
((IPlugin)plugi n).WriteSetting s(textWriter);
....
public class XmlTest { public string Hello = "Hello World!"; }
public void WriteSettings(T extWriter settingsWriter)
{
XmlSerializer x = new XmlSerializer(t ypeof(XmlTest)) ;
x.Serialize(set tingsWriter, new XmlTest());
}
Once again, if I use the diagnostic switches, everything works fine.
On Apr 9, 11:26 am, christopher.wat f...@gmail.com wrote:
On Apr 9, 10:53 am, christopher.wat f...@gmail.com wrote:
I'm loading a plugin assembly using Activator.Creat eInstanceFrom, and
inside this assembly is a settings class which gets serialized to XML.
The general code flow is as follows:
ObjectHandle pluginHandle = Activator.Creat eInstanceFrom(a ssemblyName,
type);
object plugin = pluginHandle.Un wrap();
...
// Settings is from the plugin Assembly loaded by the Activator
XmlSerializer x = new XmlSerializer(t ypeof(Settings) );
x.Serialize(set tingsFile, _settings);
// blows up here with this exception:
System.InvalidO perationExcepti on: There was an error generating the
XML document. ---System.InvalidC astException: Unable to cast object
of type '*.Settings' to type '*.Settings'.
at
Microsoft.Xml.S erialization.Ge neratedAssembly .XmlSerializati onWriterSetting s.Write3_Settin gs(Object
o)
Which is confusing considering the types are identical. However, when
I add the following XML to App.Config, the error goes away:
<system.diagnos tics>
<switches>
<add name="XmlSerial ization.Compila tion" value="4" />
</switches>
</system.diagnost ics>
What am I missing w.r.t. Activator.Creat eInstanceFrom and
XmlSerializer?
Thanks.
Moreover, *any* type from a loaded assembly (Assembly.Load,
Assembly.LoadFi le, Assembly.LoadFr om, Activator.Creat eInstanceFrom)
fails to be serialized/deserialized.
Assembly asm = Assembly.LoadFr om(Path.GetFull Path(assemblyNa me));
object plugin = asm.CreateInsta nce(type);
((IPlugin)plugi n).WriteSetting s(textWriter);
...
public class XmlTest { public string Hello = "Hello World!"; }
public void WriteSettings(T extWriter settingsWriter)
{
XmlSerializer x = new XmlSerializer(t ypeof(XmlTest)) ;
x.Serialize(set tingsWriter, new XmlTest());
}
Once again, if I use the diagnostic switches, everything works fine.
I have found a solution which, while not perfect, works. The assembly
seemingly cannot be loaded from outside the ApplicationBase or
CodeBase or PrivateBinPath. Moving the plugin DLL's to a path
underneath the working directory solved things.
DOES NOT WORK:
\MyExecutable\b in\Debug\MyExec utable.exe
\MyPlugin\bin\D ebug\MyPlugin.d ll
WORKS:
\MyExecutable\b in\Debug\MyExec utable.exe
\MyExecutable\b in\Debug\Plugin s\MyPlugin.dll
However, I'm not entirely sure why the XmlSerializer fails to see
Assemblies loaded from elsewhere. Especially when the diagnostic
switches make it work! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Johan Appelgren |
last post by:
Hi,
I'm trying to serialize a class hierarchy using
System.Xml.Serialization.XmlSerializer from a class that is loaded as a Com
object. But it fails with a InvalidCastException. I don't know what I'm
doing wrong and it seems even the most simple cases fail. I tried with a
simple class that looks like this
public class Class1
{
|
by: aladdinm1 |
last post by:
Hi All,
I have an annoying trouble with binary serialization. I have a windows
forms application which works like a server and keeps sending data to its
clients. The data is serialized before being sent using BinaryFormatter and a
serializable object. When using a windows forms application as a client,
everything works just fine and deserialized data can be received intact. When
the client application is is embedded in Internet Explorer (I...
|
by: Chris Aitchison |
last post by:
Hello,
I am attempting to have a class that I have written serialize so that it can
be both passed as a parameter or return value for a webservice, and also be
serialized to disk using the XmlSerializer.
When this class is decalred as a return value for a WebMethod in an XML
WebService I receive the following exception:
System.IO.FileNotFoundException: File or assembly name rexz5r1o.dll, or one
|
by: Magnus Lindhe |
last post by:
Hello,
I'm trying to deserialize an XML document into a objects with the
XmlSerializer which works fine in my NUnit test suit but fails with a
TypeLoadException in the server. The difference between the server and
the NUnit test suit is that the server will load the assembly
(Flux.Grease.Services.dll) as a plugin in its own AppDomain whereas
the NUnit test suit reference the assembly in the usual way.
The code that performs the...
|
by: Keith Bannister |
last post by:
I'm new to .net so here goes.
I'm tying to deserialize a class that is associated with an XML
schema.
I created the C# class with xsd.exe as below:
xsd.exe /c /n:somenamespace properties.xsd
this creates properties.cs
| |
by: SJD |
last post by:
I've just read Christoph Schittko's article on XmlSerializer:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnxmlnet/html/trblshtxsd.asp
. . . and very informative it is too.
I, too, am getting nasty FileNotFound exceptions. I've read, and
digested the article, and I think I've found a bug -- it's difficult to
track, though it does happen often.
|
by: BuddyWork |
last post by:
Hello,
When running the following line of code
XmlSerializer serializer = new XmlSerializer(typeof
(MyXmlTestClass));
I get the following exception message.
An unhandled exception of
|
by: Philipp Sumi |
last post by:
Hi all
I have a strange situation with a VS.net Add-In that uses the
XmlSerializer class for deserialization. In the code below, I pass a
given type to the serializer class. However, the type of the object that
is returned by the serializer is a different one so I can't get a
reference to it (casts fail).
//get the type -> same problem with typeof(...)
|
by: cd~ |
last post by:
I can provide a test app, the news server won't allow me to post the files
because they are too large (93KB and 1.2KB)
I downloaded the ESRI ArcXml schema and generated the classes from the
schema using xsd.exe, which took a while because xsd doesn't handle
recursive elements very well (StackOverFlow exception during generation).
Now that I have the classes I am trying to serialize them to an xml document
to send to ArcIMS to generate...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |