|
I would suspect that the issue is more that something in your class is not serializable. Is there an InnerException that you can inspect? That will contain more information.
|
|
|
|
|
Inner exception
{"Type 'System.Data.Objects.ObjectSet`1[[entityMapExample.tableA, entityMapExample, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' in Assembly 'System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable."}
Data
{System.Collections.ListDictionaryInternal}
StackTrace
at System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers(RuntimeType type)
at System.Runtime.Serialization.FormatterServices.GetSerializableMembers(Type type, StreamingContext context)
at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemberInfo()
at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder)
at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.Serialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder)
at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck)
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck)
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph)
at entityMapExample.Program.Main() in C:\C#projetcs\entityMapExample\entityMapExample\Program.cs:line 39
and here is my class:
[EdmEntityTypeAttribute(NamespaceName="ModelStart", Name="tableA")]
[Serializable()]
[DataContractAttribute(IsReference=true)]
public partial class tableA : EntityObject
{
#region Factory Method
public static tableA CreatetableA(global::System.Int32 id, global::System.String name)
{
tableA tableA = new tableA();
tableA.Id = id;
tableA.Name = name;
return tableA;
}
#endregion
#region Primitive Properties
[EdmScalarPropertyAttribute(EntityKeyProperty=true, IsNullable=false)]
[DataMemberAttribute()]
public global::System.Int32 Id
{
get
{
return _Id;
}
set
{
if (_Id != value)
{
OnIdChanging(value);
ReportPropertyChanging("Id");
_Id = StructuralObject.SetValidValue(value);
ReportPropertyChanged("Id");
OnIdChanged();
}
}
}
private global::System.Int32 _Id;
partial void OnIdChanging(global::System.Int32 value);
partial void OnIdChanged();
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
[DataMemberAttribute()]
public global::System.String Name
{
get
{
return _Name;
}
set
{
OnNameChanging(value);
ReportPropertyChanging("Name");
_Name = StructuralObject.SetValidValue(value, false);
ReportPropertyChanged("Name");
OnNameChanged();
}
}
private global::System.String _Name;
partial void OnNameChanging(global::System.String value);
partial void OnNameChanged();
#endregion
}
|
|
|
|
|
I think BinarySerialization does not work with EntityObject. You can try to use XmlSerialization. ord you try to Use POCO (Not derived from EntityObject) for BinarySerialization.
|
|
|
|
|
I want to serialize as XML.
the problem is it does not serialize references.
(other tables with foreign keys).
I am wondering if I create an addition property in my Entity class to take all references and GET it as an Array or List; mark it as [DataMemberAttribute()]; it will serialize
The only problem is when deserializing I have to manuly reload the collection into the Reference (foreign key).
Which solution do you think is easear to serialize objects togheter with references?
|
|
|
|
|
I was able to serialize also with references in this way:
but still I dont understand why when using a DataContractSerializer I am able to serialize also the references since it is mark as xmlIgnore
[XmlIgnoreAttribute()]
[SoapIgnoreAttribute()]
[DataMemberAttribute()]
[EdmRelationshipNavigationPropertyAttribute("ModelStart", "PlayerHobbie", "Hobbie")]
public EntityCollection<Hobbie> Hobbies
{
let's see when deserializing ...
using (ModelStartContainer model= new ModelStartContainer())
{
try
{
var queryable = model.Players.Include("Hobbies").ToList();
using (XmlWriter writer = XmlWriter.Create(@"c:\Serialize\conTemp.xml"))
{
DataContractSerializer serializer = new DataContractSerializer(queryable.GetType());
serializer.WriteObject(writer, queryable);
}
}
catch (EntitySqlException ex)
{
throw new ApplicationException("The object query failed", ex);
}
catch (EntityCommandExecutionException ex)
{
throw new ApplicationException("The object query failed", ex);
}
catch (SerializationException ex)
{
throw new ApplicationException("The object graph could not be serialized", ex);
}
}
|
|
|
|
|
What are you trying to do? You already have a persistent storage of the objects with all the foreign key lookups and so on: the database! Resolving references doesn't make sense without sending the entire data store, or at least a large part of it, at which point you might as well give the other client access to the data model directly.
The actual problem here, I think, is that the ObjectSet which is the type on the data context property is not serialisable. You may have to pull the tableA objects out into a List<tableA> and serialise that.
|
|
|
|
|
|
Dear all,
I have the C# windows form program which will export the Sales POS Receipts in PDF. But I find that due to fonts problem, the chinese and english words that make it not aligned for each line.
But I heard that there is a solution that will make the char length be the same for each letters in pixels by assigning full-width to chinese and half-width to english words.
Which library I can use for handling pixels length when exporting to PDF???
|
|
|
|
|
As far as I know the only way to do this is to use fixed width fonts such as Courier New, Terminal etc in English. I'm not sure whether there is a similar font for Chinese characters.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
|
Hello every1, i'm doing some program on C#. I want to make so that some loop is running while button is pressed, if it is released loop ends. However on VS 2010 when i use Form1_MouseDown event inside loop is executed only once.
DL
|
|
|
|
|
Inside your MouseDown event:
1. Capture the mouse
2. Begin your repetitive operation
3. Handle the MouseUp event to stop the operation and release the mouse
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
The problem with this "general recommendation" is that it will fail if there is an "open-ended loop," like a while loop, with no halting condition, in the MouseDown event. ... And the programmer somehow expects the MouseUp event to terminate the Loop.
They will then find that the no-halt loop never relinquishes control, and MouseUp will not be called. And your application is "off to Disneyland."
See my answer below for three strategies to handle this scenario.
best, Bill
"The first principle is that you must not fool yourself, and you are the easiest person to fool." Richard Feynman
|
|
|
|
|
The MouseDown event is fired when you press the mouse button in, so it will only be fired once for every time you press the mouse. The corresponding event you need to hook into is the MouseUp event.
|
|
|
|
|
Best solution would be to capture the mouse down event, start a thread that loops while listening for a boolean that will become false by the time the mouse up event is fired.
hope that helps.
Δημιουργία websites, web εφαρμογών και εφαρμογών ηλεκτρονικού υπολογιστή. http://www.remiakstudio.gr
|
|
|
|
|
+5 Yes, a threaded option will work: would be interesting if you would say something about how the thread will update the boolean which will be running in (theoretically) a main form's gui environment.
best, Bill
"The first principle is that you must not fool yourself, and you are the easiest person to fool." Richard Feynman
modified 10-Feb-12 1:48am.
|
|
|
|
|
static bool mousedown ?
Set to true in mousdown event which also launches the thread with the loop init, set to false on mouseup event, loop ends and thread stops.
That's how I would do it.
V.
|
|
|
|
|
For example: a while loop running in a MouseDown EventHandler ... with no terminating condition ... is going to run "forever." The MouseUp EventHandler is never going to be called: and you lose control of your Application.
There are three strategies that could work here to avoid this "pitfall."
By the way, the same issues described here would apply in the case of using a specific key press to trigger a non-halting loop.
The technical reason for the "pitfall" is that an unterminated loop launched in a MouseDown EventHandler is going to block the thread ... in this case the main thread, which happens to be your application.
1. Raven has mentioned the threading option already: hope he'll flesh it out with some code. It will work !
2. Quick and nasty: create a WinForm project: note: this example will undoubtedly spawn a series of responses/sermons on the "utter evil" of using "Application.DoEvents," but I already hang garlic on my computer to avoid being attacked by its meme, myself
a. add a Button named "button1" : hook up the MouseDown and the MouseUp EventHandlers to the Button as shown below:
b. add this code:
private bool IsMouseDown = false;
private int tick = 0;
private void button1_MouseDown(object sender, MouseEventArgs e)
{
IsMouseDown = true;
while (IsMouseDown)
{
tick++;
Application.DoEvents();
}
}
private void button1_MouseUp(object sender, MouseEventArgs e)
{
IsMouseDown = false;
Console.WriteLine(String.Format(&quot;ticks = {0}&quot;, tick));
}
3. Use a Timer : activate the Timer in the MouseDown EventHandler; de-activate in the Mouse-Up EventHandler. Put the code to be done in the loop (assuming it has no built-in halt checking) inside the Timer's Tick EventHandler.
"The first principle is that you must not fool yourself, and you are the easiest person to fool." Richard Feynman
modified 10-Feb-12 2:43am.
|
|
|
|
|
|
Do not do 2 unless there's really no alternative. 3 is a far better non-threaded approach.
|
|
|
|
|
5'd for solution number 3, because that's how I'd do it.
|
|
|
|
|
If this is for something UI related, I'd start a timer instead of a new thread. That avoids the various synchronisation issues and is good enough for UI updates.
The other question is: can you do whatever you're trying to do on mouse move? Dragging things around is a common scenario that you can do without a loop/timer.
|
|
|
|
|
Hi,
is it possible to replace the "Application / Form" Icon, when minimized to TaskBar (not Tray), during runtime with a picturebox ?
I want a mouseover, get the color from cursor and put the current color "in the icon". Mousecursor moves, Taskbar (Icon/P-Box) color changes.
Greetings from Cold Germany,
T0M
|
|
|
|
|
What is shown in the taskbar is one of the icons belonging to your application, there is no PictureBox involved here. You can switch icons any time you like, I'm not sure how fast Windows will pick it up though.
And then you must be careful, an ICO file typically contains icons at several sizes; which icon from your ICO file is being shown on the taskbar may well depend on the Windows version you use and maybe also some Windows settings (e.g. since Vista, Windows can stack together the icons of similar processes; since Win7 Windows can show a progress bar on top of the app's taskbar button).
I'm afraid you will need to experiment a lot.
Luc Pattyn [My Articles] Nil Volentibus Arduum
Fed up by FireFox memory leaks I switched to Opera and now CP doesn't perform its paste magic, so links will not be offered. Sorry.
|
|
|
|
|
Not with a picture box as far as I'm aware. As Luc has correctly stated, what you see is an icon from your application.
You could maybe create an icon of the solid colour you want dynamically in memory and assign that...? Untested but may work.
|
|
|
|