WCF serialization issue when moving existing class properties to newly created base class |
Using the example above, I overloaded the property "B" in the derived class
and had it refer to the Base class (I'm working in VB, sorry):
#region "This shenanigans prevents breaking the contract when moving some
properties to the base class.
<DataMember()> Public Overloads Property B() As String
Get
Return MyBase.B
End Get
Set(value As String)
MyBase.B = value
End Set
End Property
#End Region
This way my base class methods can still operate on B. If we ever get
around to implementing wcf versioning, or have some other need to change
the contract, I can strip out that overload in the derived class and
everything should still just work.
-JG
|
QWT designer plugin is inaccesable via QtCreator built-in designer |
The reason might be on the compatibility of your QTCreator with the the
ACTUAL QT framework you built QWT against.
The "Qt 5.1.1 for Windows 64-bit (VS 2012, OpenGL, 522 MB)" package
provided in QT-Project.org/Download has the QT libraries built against
MSVCR110 (C++ 2012) 64 bits where as the actual QTCreator.exe is built
against MSCVR100 (C++ 2010). That's why the QWT plugin load successfully
form the stand-alone QT Designer that comes in the QT framework, but not on
the QT creator that comes in the Tools/ directory. To check this, load the
QTCreator executable in Dependency Walker and you'll see.
My recommendation is that you download the source code of QT, build it with
your compiler and then compile the QWT using the same compiler. A bit
tedious but at least you'll be sure that your
|
Qt Designer: Changing the base class of a window |
To change the base class you could only change the : public QMainWindow to
: public QWidget (or vice-versa) in the header-file and of course also the
*.cpp.
Basically all three are QWidgets, each with special functionality or for
specific purposes. As far as I know the QMainWindow has toolbars, menubars
and docks, a QDialog will always be shown as a seperate window (e.g.
blocking, non-blocking, etc.) and the QWidget itself is the base-class.
I.e. QPushButton, QCombobox are derived from QWidget too. In my opinion it
would be better to use only one QMainWindow since it should be a central
point of interaction/navigation for the user
EDIT:
I forgot to mention that also the UI-file has to be changed, i.e. by using
a text-editor, change the line (4th row I think)
<widget class="QMainWind
|
How do you change the namspace of a vb.net form with a VS designer partial class? |
You can modify the namespace in the designer file e.g. Form1.Designer.cs.
As long as you do not change the code within the Windows Form Designer
generated code region, you should be fine.
Another option is to create another folder in your solution. After adding
a form to the new folder, its namespace will automatically have the name of
the folder appended to it.
|
Shown handler in Form's base class in the way of designer |
Some events are fired in the designer as well, it is what gives the
Winforms designer its wysiwyg ability. Notably Paint, Shown is also fired,
etcetera. The DesignMode property is provided to allow you to tell whether
your event handler is running at design-time. Fix:
void BaseClass_Shown(object sender, EventArgs e) {
if (!this.DesignMode) {
Close();
MessageBox.Show("This cannot be opened.");
}
}
Do note the flaw in your approach, this event also fires for a derived
form. You might be helping too much.
|
JFrame class convert to a NetBeans Designer support JFrame class |
First of all, Eclipse does have a Swing UI Designer Tool indeed. It is call
WindowBuilder Pro and you can update your Eclipse to include it easily. The
manual is here.
WindowBuilder Pro is very stable and runs on any platform Eclipse supports.
It may not be as well integrated to Eclipse, as Matisse GUI builder is in
Netbeans, but you can do your development without any problems and
limitations with both.
You can do almost anything with both plug-ins. Both are flexible and
expandable if you learn how to work with them.
Conversions of Swing applications between Eclipse and Netbeans are not very
easy. You have to select one environment and stick to it.
GUI builders do not substitute basic Swing knowledge. It is always best for
beginners to write their Swing code, using a regular editor
|
Serialization of class attributes? |
if it is about the type of your class here is an example:
[XmlIncludeAttribute(typeof(ConcreteFooOne))]
[XmlIncludeAttribute(typeof(ConcreteFooTwo))]
[XmlIncludeAttribute(typeof(ConcreteFooThree))]
[XmlRoot(ElementName = "FooData", Namespace = "http://foo.bar")]
public abstract partial class AbstractFoo
{
// Some abstract props etc.
}
[XmlRoot(ElementName = "FooData", Namespace = "http://foo.bar")]
public class ConcreteFooOne : AbstractFoo
{
public int MyProp { get; set; }
}
[XmlRoot(ElementName = "FooData", Namespace = "http://foo.bar")]
public class ConcreteFooTwo : AbstractFoo
{
}
[XmlRoot(ElementName = "FooData", Namespace = "http://foo.bar")]
public class ConcreteFooThree : AbstractFoo
{
}
class Program
{
static void Main(stri
|
Passing a Class for object serialization to xml |
I might be better to avoid attempting to pass the class at all. I can
achieve the same affect by passing the IBindingFactory and adding a bit of
code to the caller.
The result would end up like this.
protected static String SerializeObject( IBindingFactory lBindingFactory,
Object request)
{
String message = null;
try
{
IMarshallingContext lContext = lBindingFactory.
createMarshallingContext();
ByteArrayOutputStream lOutputStream = new ByteArrayOutputStream();
lContext.marshalDocument(request, "UTF-8", null,
lOutputStream);
message = new String(lOutputStream.toByteArray(), "UTF-8");
}
catch (JiBXException lEx)
{
throw new RuntimeException("Problems generating XML, " +
"underlying probl
|
Java Serialization for Extended Class |
Since super class doesn't implement Serializable contents of the super
class wont get serialized. Only the contents of the subclass would get
serialized. When you deserialize the default constructor of the superclass
would get executed and the fields of the superclass initialized as if you
invoked the default constructor.
Following example illustrates this.
public class SerializationTest {
public static class Base {
private String name;
public Base() {
this.name = "johnDow";
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
public static class Sub extends Base implements Serializable {
private static final long serialVersio
|
Class serialization and namespace (xmlns) |
Try this option in OnWriteHeaderContents method
writer.WriteStartElement("saml", "Assertion",
"urn:oasis:names:tc:SAML:2.0:assertion");
writer.WriteString("Value");
writer.WriteEndElement();
|
Read From XML File into C# Class Using Serialization |
You don't need to explicitly declare the properties. Just make sure the
names match. The only non-default portion is the [XmlArrayItem("Map")]
attribute you will need to use the different name for the map array.
You can, however, use differing names as I have for the COM_Property and
WEB_Property by specifying the XmlElementAttribute.
class Program
{
static void Main(string[] args)
{
string testData = @"<?xml version=""1.0""?>
<PropertiesMapping>
<Property>
<WEB_Class>InfoRequest</WEB_Class>
<COM_Class>CInfoReq</COM_Class>
<Mappings>
<Map>
<WEB_Property>theId</WEB_Property>
<COM_Property>TheID</COM_Property>
&l
|
Boost::serialization and boost::mpi to broadcast derived class via base class pointer |
I was thankfully able to answer my own question (I think.) Boost doesn't
handle through-base-pointer serialization properly when combined with
boost::mpi::packed_skeleton_iarchive. The solution is then to use a
different kind of archive, e.g. text_iarchive/text_oarchive, instead.
For example, to broadcast:
std::ostringstream oss;
boost::archive::text_oarchive oa(oss);
oa << value;
std::string s = oss.str();
boost::mpi::broadcast(comm, s, root);
And to receive:
std::string s;
boost::mpi::broadcast(comm, s, root);
std::istringstream iss(s);
boost::archive::text_iarchive ia(iss);
ia >> value;
|
Implementing iNotifyPropertyChanged for a simple Person class crashes VisualStudio XAML designer |
You implemented the class improperly. You need a backing field:
private string firstName;
public string FirstName
{
get { return this.firstName; }
set
{
if(this.firstName != value)
{
this.firstName = value; // Set field
OnPropertyChanged("FirstName");
}
}
}
Right now, your getter is getting itself, and the setter sets the property
itself, both of which will cause a StackOverflowException.
|
How to achieve dynamic partial XML class serialization in .Net? |
The code below may solve your problem.
We create a serializable class called MemberList, that contains an array of
MemberCodes. After your list of member codes is populated during runtime,
we convert it to an array and serialize it into XML. The results will be
saved to a file called "test.xml" in your debug folder.
XML Output
<?xml version="1.0" encoding="utf-8"?>
<MemberList xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Members>
<Member>Field1</Member>
<Member>Field2</Member>
<Member>Field3</Member>
<Member>Field2</Member>
<Member>Field1</Member>
<Member>field4</Member>
</Mem
|
How to exclude class fields from serialization by XmlElement name? |
Have you encountered the [XmlIgnore] attribute? Adding it to members of
your class will exclude them from serialization.
So, for example, you can replace [XmlElement("Surname")] with [XmlIgnore],
and then your serialized agent will look like this:
<Agent>
<Name>John Doe</Name>
</Agent>
Alternately, if all you really want is just <Name>John
Doe</Name>, you could write a wrapper class:
[XmlRoot("Name")]
public class NameElement
{
[XmlText]
public string Name { get; set; }
}
* EDIT *
While it's possible to generate such wrappers at runtime, it's difficult,
inefficient, and not very practical.
To do so, I guess you could reflectively examine your object and find the
properties you want (root.GetType().GetProperties().Where(p => /* yo
|
Protobuff.NET - different serialization of a abstract base class |
Add, to the base-class:
[ProtoInclude(1, typeof(ClassB))]
Basically, as with XmlSerializer (see: [XmlInclude]) and
DataContractSerializer (see: [KnownType]) - the serializer needs to know
about sub-classes in advance. The easiest way to do this is with
attributes, but it can also be specified at runtime if you prefer.
Note the 1 here is just any key (preferably a small number - they encode
more efficiently) that doesn't conflict with other keys in ClassA (so: I
couldn't use 2 because A is 2 in ClassA1). Keys only need to be unique
within the single class (not between different classes, even in
inheritance).
|
Windows Phone XAML Designer Error |
Already a bug reported for this to Microsoft. Look at here.
However re-installation did trick for most of them. Make sure you follow
these steps as reported here for re-installing VS2012 back.
Try this if it helps(Source) -
I too had this problem. I was able to fix it by adding
<loadFromRemoteSources enabled="true"/> to xdesproc.exe.config (as
Marco stated) and devenv.exe.config. Both files are in C:Program
Files (x86)Microsoft Visual Studio 11.0Common7IDE.
|
Error when opening designer on inherited form |
You can clearly see from the stack trace that your base form's Load event
handler is running and throwing an exception. This is normal, events in
the base form like Load and Paint run at design time as well. It provides
the WYSIWYG designer view. This however goes poorly if that code can only
work properly at runtime.
The Control.DesignMode property was meant to provide you with a way to
check if the code in the the class is operating at design time.
Unfortunately it is not available in CF so a different approach is needed.
The magic incantation looks like this:
private void frmBase_Load(object sender, EventArgs e) {
if (this.Site == null || !this.Site.DesignMode) {
// Not in design mode, okay to do dangerous stuff...
this.UpdateOnline();
|
ASP.NET Designer.xx generates 'already contains a definition for' control error |
It sounds like something is trying to add duplicates of your controls to
the designer file. VS updates the designer file on every edit you make
which is why it happens as soon as you edit the aspx or ascx files. One
thing you can do is when the error is thrown, open your designer.cs file
and check--my bet is that you will see duplicate declarations. If this is
the case, it is probably a bug in whatever library you are using--though I
couldn't know for sure without some more information. Delete the duplicates
and you should be able to build again. As far as keeping it from happening
again, we need to see what is being generated in the designer file.
|
Boost serialization over dereferenced base class pointer |
I met the same problem with you! So I looked over the doc of
boost,which give a way to solve the problem,I can define a class D to
manage the derive objects,and use the ar.register_typeto diff the a b c
class,just like this:
class base {
...
};
class derived_one : public base {
...
};
class derived_two : public base {
...
};
main(){
...
base *b;
...
ar & b;
}
When saving b what kind of object should be saved? When loading b what kind
of object should be created? Should it be an object of class derived_one,
derived_two, or maybe base?
It turns out that the kind of object serialized depends upon whether the
base class (base in this case) is polymophic or not. If base is not
polymorphic, that is if it has no virtual functions, then an object o
|
Lost attributes in serialization List<> inherited class |
If you change the class it will serialize the name field too.
public class cIntList
{
public string Name{ get; set; }
[XmlElement("")]
public List<IntData> IntList{ get; set; }
public cIntList()
{
Name = "Name";
IntList = new List<IntData>();
IntList.Add(new IntData() { Value = 1 });
IntList.Add(new IntData() { Value = 2 });
}
}
You can change or remove the XmlElement attribute depending on your desired
xml.
|
Serialization of derived class trips Boost assertion |
You probably don't mean to use polymorphic_xml_archive (see docs).
Notably, polymorphic archives have to do with the interface of the
archives, nothing with the entities you're serializing for (they can always
be polymorphic).
If you use xml_archive instead, the problem vanishes.
|
WPF Designer throws error when string resources are used in code behind |
Let it throw error, just check whether your are able to complie and run,
the Make the assembly In Solution C as exe and try to run it. Because with
Visual studio 10.0.4, i have see that exception many times, but if it is
complied it doesn't give any compiler error, just try to compile and run it
|
Cannot create an instance of "[user control]" error in designer |
First, instead of pack://siteoforigin:,,,/arrow2.png need to write your
actual URI and to make sure that the file exists in the project as a
resource, like this (MSDN):
pack://application:,,,/arrow1.png
Secondly, trigger style for the label lblRun, will not work because you set
this Foreground value locally, in WPF have a list of value precedence
(MSDN), that the local value of a higher priority than the trigger style:
<Label x:Name="lblRun" Foreground="#FF2EAADC" FontSize="20" ... />
Try to remove it Foreground local value and use Style setter:
<Label x:Name="lblRun" Content="Run" HorizontalAlignment="Right"
Margin="0,88,35,0" VerticalAlignment="Top" FontSize="20">
<Label.Style>
<Style TargetType="{x:Type Label}">
<Setter Property=
|
Reuse Previous Serialization in File with System.Xml.Serialization |
I think, you can improve performance using chaining an XmlReader/XmlWriter.
Try looking this article
http://msdn.microsoft.com/en-us/library/aa302289.aspx
|
Build a Custom Serialization as String in System.Xml.Serialization |
You can implement the IXmlSerializable interface, so the Info1 and Info2
properties are serialized the way <Info>Info1:Info2</Info>:
public class OtherInfo: IXmlSerializable
{
public string Info1 { get; set; }
public string Info2 { get; set; }
public System.Xml.Schema.XmlSchema GetSchema()
{
return null;
}
public void ReadXml(System.Xml.XmlReader reader)
{
var content = reader.ReadElementContentAsString();
if (String.IsNullOrWhiteSpace(content))
return;
var infos = content.Split(':');
if (infos.Length < 2)
return;
this.Info1 = infos[0];
this.Info2 = infos[1];
}
public void WriteXml(System.Xml.XmlWriter writer)
{
writer.WriteString(String.Form
|
Best way to store serialization related info between serialization and deserialization |
You can use Json.Net
var settings = new JsonSerializerSettings() {
TypeNameHandling = TypeNameHandling.All };
var json = JsonConvert.SerializeObject(obj, settings);
var newObj = JsonConvert.DeserializeObject<SomeType>(json, settings);
|
Is it possible to serialize transient field of the class using my custom serialization or using Externalization? |
The answer is yes if you are using the custom serializaton. When we do
custom serialization by overriding the writeObject method, you take control
of the serialization and can do whatever you want. So you can also assign
or use a value of a transient field and can also marshall it along with
other class attributes.
|
JSON/XML serialization: Ignore/include some fields from the base class |
You should use a DTO that is specific for your current action and then copy
the data from the DTO to the actual object you want to use.
Benefits of this is you can define validation that are specific to this
action and you'll have no attributes on the business object. You can use
different validation rules per action for each new DTO and still use the
same business object.
If you don't want to write the mapping code to map from the DTO to the
business object you can use AutoMapper.
Example code:
public enum ColourType
{
Flat,
Metallic
}
public class Car
{
public void Repaint(int red, int green, int blue, ColourType colourType)
{
// TODO: Add some validation logic and business logic.
}
}
public class RepainInMetallicModel
{
[Required]
[Range(0, 100)]
public int Red
|
serialize class object that contain secret data - serialization with encryption |
A: if you want to be lazy, just GZip it - it compresses the data to make it
so you can only read it by first un-GZiping it.
B: Encrypt the data. This requires you have a password to read it. This is
also harder to implement.
Feel free to ask for clarification on how to use either of these options.
|
Boost serialization with shared_ptr without implementing serialize() function in pointed class |
The reason i want to use a shared_pointer is to avoid defining this
function for some of my complex classes.
In my opinion, this is a wrong reason to use shared pointers. Using shared
pointers is good, but the reason is that it does memory management for you,
so that you do not have to call delete yourself. In some (rare) cases,
using smart pointers may not be the best solution and you would prefer to
do memory management yourself. This is the most important criteria to
decide to use smart pointers or not, serialization being a side
benefit/trouble comes after.
Anyway:
I am not an expert in the boost::archive framework, but it seems
serializing to the class Archive is more subtle than just printing the
value, since it also uses a "version" in case you want to change how you
seriali
|
Serialize whole instance with child instances (class serialization) and save to file |
I personally prefer json. If you're using json.NET this will be as simple
as;
string json = JsonConvert.SerializeObject(MyObject);
or to compact it;
File.WriteAllText("./myfile", JsonConvert.SerializeObject(MyObject));
Then to deserialize you would just do;
MyObject obj =
JsonConvert.DeserializeObject<MyObject>(File.ReadAllText("./myfile"));
EDIT: In response to the exception, you want to use this overload which
allows you to change the serilization settings;
JsonConvert.SerializeObject(ResultGroups,
new JsonSerializerSettings()
{
ReferenceLoopHandling =
ReferenceLoopHandling.Ignore
});
|
Unsolvable (as of yet) serialization error |
Without seeing any of the code, it's difficult to troubleshoot. However,
we had something similar that was caused because the DataContractSerializer
expected a specific type (as defined in the service interface), but was
instead getting an EntityFramework proxy type.
We decided to use the Data Transfer Object pattern to resolve this. We
created base classes that were simple data transfer objects. EF-aware
classes inherit from these and add persistence-related logic.
These DTO objects implement ICloneable (or something similar) which allows
us to easily create data transfer copies of the Entity Framework proxy
classes before sending objects to the serializer at the service level.
It may also be possible to resolve this by creating a custom serializer
that has knowledge of Entity Frame
|
Serialization Cryptography Error |
Crypto is somewhat complex. First get the crypto working, just the crypto.
Start with a piece of text: "I wandered lonely as an armadillo." Use your
code to encrypt and decrypt that text, forgetting about the serialization.
When that is working correctly then, and only then, use your working crypto
code to encrypt/decrypt the serialized object.
Have you successfully serialized/deserialized your object without any
encryption?
On a brief glance, you need to set padding to PKCS#7 (aka PKCS#5). Your
PaddingMode.None may be what is causing the problem. Without padding your
final block may not be being processed correctly. Obviously you need to
use the same padding for both encryption and decryption.
|
Silverlight 5 Xml Serialization Error |
Create a parameterless constructor for the entity types that you are trying
to serialize. i.e.
Public Sub New()
End Sub
You might need to place this in a Partial class in another file.
|
Why does Serialization process require access to a no argument constructor of the first non serializable super class? |
What is the premise behind the third point above?
So that the non-Serializable base classes can be initialized to a known
state that can be controlled to some extent by the programmer. It's just a
design decision.
|
Boost Serialization compile error |
You need to add -lboost_serialization to you linker command.
It is a long time since I used netbeans but as far as I can remember it was
something like Build->Linker->Libraries.
You don't need to add -l I think netbeans does this for you.
|
DevExpress and SimpleMvvmToolkit - Serialization error |
Thanks to great help of the Simple MVVM Toolkit community I found out that
the solution was simple.
In Simple MVVM Toolkit, A viewmodel needs to be serializable because it
gets cloned. This is to easily roll-back data when an action is canceled.
The reason my viewmodel could not be cloned whas because its "model"
property was missing a default (parameter-less) constructor.
There's no need to decorate the viewmodel and its properties with
[DataContract] or [DataMember].
I hope this helps others.
|
T4 PowerShell Array Serialization Error |
I tried this a long time ago but it did not work :(
I solved it anyway since I noticed that you can pass an array of string
into the T4-template.
Since you can pass in a array of strings I built comma-separated strings
with the information for each object... Then I did a split(",") inside of
the T4-template getting the data back...
Example
#Get regular properties
$properties = @()(Get-ProjectType $ModelType).Children |
Where-Object{$_.Kind -eq 4 -and $_.Type.TypeKind -ne 1 } | ForEach{
$p = "$($_.Name),$($_.Type.AsString)";
$properties = $properties + $p
}
Then I just pass the $properties array as a regular parameter (the fourth
parameter)...
Add-ProjectItemViaTemplate $outputPath -Template ViewModel `
-Model @{
Namespace = $namespace;
DataType = [MarshalByRefObject]$foundModelT
|
VS 2010 Designer error when passing arguments to custom's control main function |
This sounds like a designer issue to me. Just do;
Re-build your current solution
Restart Visual Studio
As an alternative, you can create seperate assembly dll for custom
controls.
|