|
The type has to be serializable. Read the documentation[^] for the SerializableAttribute class, as well as Serializing Objects[^] in the .NET Framework SDK.
Also note that the SerializableAttribute is not, by default, inheritted like some other attributes.
If you assigned a Control or Control -derivative to the Tag property, for example, it would not serialize despite the fact that its indirect base class MarshalByRefObject is marked as serializable because the SerializableAttribute is not inheritted. In your case with intrinsics and arrays, they are serializable. The class declaration (keeping in mind than any array you declare extends System.Array ) in the .NET Framework SDK which tell you which classes are marked as serializable.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Thanks for your reply, Heath!
I had flagged the class as [Serializable] , of course, but didn't write it in the sample code, sorry.
What you describe is more or less what I thought about serialization so far.
But this doesn't explain the behaviour I get (or perhaps I'm just too dense to see it):
Class without the Dummy property and an int assigned to Tag serializes OK.
Class without the Dummy property and an int[] assigned to Tag throws exception.
Class with the Dummy property and an int assigned to Tag serializes OK.
Class with the Dummy property and an int[] assigned to Tag serializes OK.
I'd assume that Tag wouldn't get serialized at all, because object isn't serializable by default.
But obviously XmlSerializer does serialize the Tag property.
And whether this serialization succeeds or fails is depending on other attributes/properties of the same class. That's what strikes me odd...
Still puzzled,
mav
|
|
|
|
|
Assume that I have a treeview with few node, I would like to select the node, press F2 or right click on that node, choose "Rename", and a textbox will appear to let me change the text of that node (include validtion if needed, number only for example), end accept changes when I press enter...
Show me the Idea for this problem
Thankx!
|
|
|
|
|
Here is the idea for "How to rename a tree node on key press (F2) and via a right-click menu":
Controls added: button1, treeView1, contextMenu1, menuItem1...
- Use the button to add nodes to the tree
- Add the corresponding events for the following..
<br />
private void RenameNode()<br />
{<br />
if (this.treeView1.SelectedNode != null)<br />
{<br />
this.treeView1.LabelEdit = true;<br />
this.treeView1.SelectedNode.BeginEdit();<br />
}<br />
}<br />
<br />
private void treeView1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)<br />
{<br />
if (e.KeyCode == Keys.F2){RenameNode();}<br />
}<br />
<br />
private void menuItem1_Click(object sender, System.EventArgs e)<br />
{<br />
RenameNode();<br />
}<br />
<br />
private void treeView1_AfterLabelEdit(object sender, System.Windows.Forms.NodeLabelEditEventArgs e)<br />
{<br />
this.treeView1.LabelEdit = false;<br />
}<br />
<br />
private void treeView1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)<br />
{<br />
this.menuItem1.Enabled = (this.treeView1.SelectedNode != null);<br />
}<br />
<br />
private void button1_Click(object sender, System.EventArgs e)<br />
{<br />
this.treeView1.Nodes.Add(new TreeNode("text here..."));<br />
}<br />
Hope this helps. Cheers
Radgar
"Imagination is more important than knowledge." - Albert Einstein
|
|
|
|
|
And you have the AfterLabelEdit [^] event fired by the TreeView control where you can validate the new text, and cancel it if necessary.
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
Nice input Luis.
Radgar
"Imagination is more important than knowledge." - Albert Einstein
|
|
|
|
|
Hi,
I'm trying to use the Microsoft.Web.Services2.Messaging.
ISoapFormatter
but I receive this error:
System.Xml.XmlException: Reference to undeclared parameter entity, 'meetingmaker'.
at System.Xml.XmlLoader.ExpandEntityReference(XmlEntityReference eref)
at System.Xml.XmlEntityReference.SetParent(XmlNode node)
at System.Xml.XmlNode.AppendChild(XmlNode newChild)
at System.Xml.XmlLoader.LoadAttributeChildren(XmlNode parent)
at System.Xml.XmlLoader.LoadAttributeNode()
at System.Xml.XmlLoader.LoadCurrentNode()
at System.Xml.XmlLoader.LoadElementNode()
at System.Xml.XmlLoader.LoadCurrentNode()
at System.Xml.XmlLoader.LoadChildren(XmlNode parent)
at System.Xml.XmlLoader.LoadElementNode()
at System.Xml.XmlLoader.LoadCurrentNode()
at System.Xml.XmlLoader.LoadChildren(XmlNode parent)
at System.Xml.XmlLoader.LoadElementNode()
at System.Xml.XmlLoader.LoadCurrentNode()
at System.Xml.XmlLoader.LoadChildren(XmlNode parent)
at System.Xml.XmlLoader.LoadElementNode()
at System.Xml.XmlLoader.LoadCurrentNode()
at System.Xml.XmlLoader.LoadDocSequence(XmlDocument parentDoc)
at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace)
at System.Xml.XmlDocument.Load(XmlReader reader)
at Microsoft.Web.Services2.SoapEnvelope.Load(Stream stream)
at Microsoft.Web.Services2.Messaging.SoapPlainFormatter.Microsoft.Web.Services2.Messaging.ISoapFormatter.Deserialize(Stream stream)
at WebSemantica.SoapSmtp.Mailbox.EndReceive(IAsyncResult result) in c:\wsf-projeto+final-julio\wsf-projeto final\websemantica\zutil-soapsmtp\mailbox.cs:line 308
----------------------------------------------------------
the code I'm using is (line 308 is the last line):
UTF8Encoding encoding = new UTF8Encoding();
SimpleMailMessage m = messagesArray[i];
ISoapFormatter formatter = new SoapPlainFormatter();
MemoryStream stream = new MemoryStream( encoding.GetBytes( m.TextDataString
) );
stream.Position = 0;
envelopes[i] = formatter.Deserialize( stream );
----------------------------------------------------------
if I print the xml (the "m.TextDataString") the result is:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE rdf:RDF [
<!ENTITY meetingmaker "http://websemantica.puc-rio.br/2004/06/meetingmaker/meetingmaker#">
<!ENTITY ical "http://www.w3.org/2002/12/cal/ical#">
<!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#">
<!ENTITY xsd "http://www.w3.org/2001/XMLSchema#">
]>
<soap:Envelope xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/03/addressing" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Header><wsa:Action>InvokeCoordinator</wsa:Action><wsa:MessageID>uuid:d905eba6-7ed8-420d-a297-b8625751f63c</wsa:MessageID><wsa:To>urn:websemanticaproxy</wsa:To><wsse:Security><wsu:Timestamp wsu:Id="Timestamp-71318c38-b4e8-46a5-af91-72348be37458"><wsu:Created>2005-02-27T00:12:47Z</wsu:Created><wsu:Expires>2005-02-27T00:17:47Z</wsu:Expires></wsu:Timestamp></wsse:Security></soap:Header><soap:Body><string xmlns="http://tempuri.org/">
<rdf:RDF
xmlns:meetingmaker="&meetingmaker;"
xmlns:ical="&ical;"
xmlns:rdf="&rdf;"
xmlns:rdfs="&rdfs;"
xmlns:xsd="&xsd;"
>
<meetingmaker:MeetingMaker rdf:ID="meetingmaker_id">
<meetingmaker:criteria rdf:datatype="&xsd;string">majority</meetingmaker:criteria>
<meetingmaker:algorithm rdf:datatype="&xsd;string">parallel</meetingmaker:algorithm>
<meetingmaker:uid rdf:datatype="&xsd;string">julio@ntime.com.br-02-26-2005 09:12:45</meetingmaker:uid>
<meetingmaker:vevent>
<ical:Vevent rdf:ID="vevent_id">
<ical:location rdf:datatype="&xsd;string">Puc</ical:location>
<ical:summary rdf:datatype="&xsd;string">Apresentacao de Trabalho</ical:summary>
<ical:dtstart rdf:datatype="&xsd;datetime">12-10-2004 10:00:00</ical:dtstart>
<ical:dtend rdf:datatype="&xsd;datetime">12-10-2004 11:00:00</ical:dtend>
<ical:contact rdf:datatype="&xsd;string">julio@ntime.com.br</ical:contact>
<ical:attende>
<rdf:Bag rdf:ID="vevent_ateende">
<rdf:li rdf:datatype="&xsd;string">kid@teccomm.les.inf.puc-rio.br</rdf:li><rdf:li rdf:datatype="&xsd;string">fred.kid@gmail.com</rdf:li><rdf:li rdf:datatype="&xsd;string">fsilva@inf.puc-rio.br</rdf:li>
</rdf:Bag>
</ical:attende>
</ical:Vevent>
</meetingmaker:vevent>
</meetingmaker:MeetingMaker>
</rdf:RDF></string></soap:Body></soap:Envelope>
(whitch is a valid XML, at least the Internet explorer open it...)
|
|
|
|
|
How was this XML generated in the first place? I suspect that if you change the order of the entities whichever you put first will be what's reported in the exception.
Please post a snippet of your code that you're using to generate the XML (SOAP) to hopefully give us a better idea of what could be wrong.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I can get a collection of system variables, and the collection of controls my form has in it. But, is there a method to get the collection of class variables, and possibly local variables to a function? This is for error-handling purposes, so as much information about my runtime that I can get, the better. This is a windows app, not asp. Thanks!
|
|
|
|
|
DougW48 wrote:
This is for error-handling purposes, so as much information about my runtime that I can get, the better.
It sounds like you are trying to break encapsulation which would really muddy and complicate the design of your application.
If an unexpected error condition arises you should throw an exception. If you need to you should create an exception class and design it so that it can be loaded with the error information so that the error handler (the catch block) can see the necessary information. However you should think carefully about whether you actually need the information or if it is just a quick solution now that will muddle things in the future.
Cada uno es artifice de su ventura
WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and Forums
|
|
|
|
|
It is possible to get values of class level variables using reflection, but I don't think it is possible to write generic code to get values of local variables.
Regards
Senthil
My Blog
|
|
|
|
|
How do I make a service that will not appear in the process list when it is done?
Specifically, I want to have an invisible service that would restrict all traffic on a computer. And no, this is not being done with malicious intent, but it does have to be invisible for other reasons.
Cheers,
Jim
|
|
|
|
|
|
You can hide processes from task manager but as far as I know you cannot hide a service from the services list.
Radgar
"Imagination is more important than knowledge." - Albert Einstein
|
|
|
|
|
|
That might be a way to do it and also svchost.exe I guess. I'm talking about "hiding" of course. I never needed it but a friend of mine was able to do it in C++ (I remember using some APIs) But what I know is, it is not legal because you'll have to reconfigure some system settings and the user won't be able to see it in the list so won't have the chance to end the app... Also, another way is registering the app as a service so it won't be in the process list but will be visible to advanced users in the services. If I remember right, it was something like this "RegisterServiceProcess lib "kernel32" (lngProcessID As Long) As Long" via WScript..
Radgar
"Imagination is more important than knowledge." - Albert Einstein
|
|
|
|
|
Colin Angus Mackay wrote:
The only way I could think of was with dllhost
Well , Colin , I'd be pleased if you tell me how you can hide it in this way.
Mazy
"One who dives deep gets the pearls,the burning desire for realization brings the goal nearer." - Babuji
|
|
|
|
|
|
hi all, am new to C# programming and i got a little problem
am having some text boxes in my form, and i want the mouse cursor to move automatically to the next textBox when the user inputs data in the preceding textBox. Just like when you enter the WinXP serial, u don't have to click 'TAB' to move to next TextBox.
thnx for ur help.
|
|
|
|
|
You can subscribe to the KeyPress event and check if the textbox has got the required number of characters. If it has, you can move focus to the next textbox. Something like
public void KeyPress_textBox1(...)
{
if (textBox1.TextLength == 5)
{
textBox2.SetFocus();
}
}
Regards
Senthil
My Blog
|
|
|
|
|
thnx for ur help,
one more thing, could I determine which data type could be entered in the text box, i.e. if the user entered "floating" no. for example it doesn't move the cursor. The user should enter "integer" for the cursor to move to the nexr text box.
|
|
|
|
|
You can use the Parse method on the Int32 class. Something like
<br />
...<br />
if (textBox1.Length == 5)<br />
try<br />
{<br />
Int32.Parse(textBox.Text);<br />
textBox2.Focus();<br />
}<br />
catch(Exception)
{<br />
}<br />
}<br />
Regards
Senthil
My Blog
|
|
|
|
|
Hello,
I'm writing an application that has to have a de/compressing algorithm used to store data. The algorithm I want to use is the LZNT and its functions are exported in NtDll.Dll as far as an unofficial documentation says. I was able to find the 3 functions' syntax, but I can't get them to work. Here they are (DLLImport info stripped):
public static extern void RtlCompressBuffer(
ulong CompressionFormat,
void *SourceBuffer,
ulong SourceBufferLength,
out IntPtr DestinationBuffer,
ulong *DestinationBufferLength,
ulong Unknown,
out ulong *pDestinationSize,
void *WorkspaceBuffer );
public static extern IntPtr RtlDecompressBuffer(
out IntPtr DestinationBuffer,
ulong DestinationBufferLength,
IntPtr SourceBuffer,
ulong SourceBufferLength,
ulong *pDestinationSize );
public static extern IntPtr RtlGetCompressionWorkSpaceSize(
ulong CompressionFormat,
out ulong *pNeededBufferSize,
out ulong *pUnknown );
Please correct me if I'm wrong with them, and I'd like to see any sample code which I can use for manipulating data.
Thank you in advance, and best regards,
Stan
P.S. here is the code I tried
Stream fs = new FileStream("input.exe", FileMode.Open); //input.exe is a test file
byte[] DataIn = new byte[fs.Length];
fs.Read(DataIn, 0, (int)fs.Length);
fs.Close();
IntPtr p_DataOut;
ulong *pDS;
byte* bt = stackalloc byte[DataIn.Length];
fixed(byte *p_DataIn = DataIn)
{
RtlCompressBuffer(0x0002 /*LZNT*/, p_DataIn, (ulong)DataIn.Length, out p_DataOut, (ulong*)DataIn.Length, 0x1000, out pDS, bt);
}
I get a NullReferenceException when executing RtlCompressBuffer, but as far as I saw, none of the parameters is null, except the ones with 'out' modifiers
|
|
|
|
|
Do NOT use pointers in managed code (unsafe code). There is no reason to use this, though there are acceptable reasons for performance like when manipulating pixels.
out ulong is already serving the role of a pointer, too. out ulong* with an unsafe context would actually be more like unsigned long** in native code.
You should read Marshaling Data with Platform Invoke[^] in the .NET Framework SDK to gain a better understanding of how native types translate to managed types. You can also visit http://pinvoke.net[^] for signatures to many common APIs.
You should also refrain from using undocumented APIs because they can be changed without warning, not to mention that they are not officially documented by Microsoft. There are better ways to gain compression in .NET, including class libraries that implement compression without resorting to P/Invoke, which means your applications that use such libraries are more likely to be portable to other platforms.
One popular compression library is SharpZipLib[^] but you can search for many more.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
how can I change the column order in DataGrid,the dataGrid isnt showing coumns in order i specifed argument in my Class Constructor,currenly it shows column in following order:
UserField,SiteName,ConnStr,cID,ipAddr
though cID is supposed to come first
i using ArrayList as a datasource for DataGrid
i am adding objects in array by doing this:
this.arrPref.Add(new cPreferences(intgr1,str3,str1,str2,str4));
where cPreference class is defined like this:
public class cPreferences
{
protected int cid=0;
protected string site_name="";
protected string connection="";
protected string user_field="";
protected string ip_addr="";
public cPreferences(int c_id,string usrfld,string sname,string cs,string ipAdrr)
{
cid=c_id;
site_name=sname;
connection=cs;
user_field=usrfld;
ip_addr=ipAdrr;
}
//Set or Get Property of CID
public int cID
{
get
{
return cid;
}
set
{
cid=value;
}
}
//set-get the Property of Site Name
public string SiteName
{
get
{
return site_name;
}
set
{
site_name=value;
}
}
//set-get property of Connection String
public string ConnStr
{
get
{
return connection;
}
set
{
connection=value;
}
}
//set-get property of UserField
public string UserField
{
get
{
return user_field;
}
set
{
user_field=value;
}
}
//set-get property of Ip Address
public string IPAddr
{
get
{
return ip_addr;
}
set
{
ip_addr=value;
}
}
}
how can I change this order?
Thanks
|
|
|
|
|