|
Woohooo! That eliminated the error message. Thank you very much! Now I just have to get past another one.
Jane
|
|
|
|
|
Hi..
i have a Class, that has 3 DataMembers, all three are Static...
whenever i try to Serialize her, the output XML is EMPTY!
Please do help,
Here is the Class code, and Xml Serializer code...
The Class
-------
using System;
using System.IO;
using System.Xml;
using System.Runtime.Serialization.Formatters.Binary;
using System.Xml.Serialization ;
namespace ShipurSherut
{
[Serializable]
public class AppSettings
{
public static String Merhav;
public static String Yeud;
public static String ServerAddress;
static AppSettings()
{
}
}
}
The Xml Serializer:
--------------
public static void ToXml(Object objToXml,string filePath,bool includeNameSpace)
{
StreamWriter stWriter=null;
XmlSerializer xmlSerializer;
try
{
xmlSerializer = new XmlSerializer(objToXml.GetType());
stWriter = new StreamWriter(filePath);
if (!includeNameSpace)
{
System.Xml.Serialization.XmlSerializerNamespaces xs= new XmlSerializerNamespaces();
xs.Add("","");//To remove namespace and any other inline information tag
xmlSerializer.Serialize(stWriter, objToXml,xs);
}
else
{
xmlSerializer.Serialize(stWriter, objToXml);
}
}
catch(Exception exception)
{
throw exception;
}
finally
{
if(stWriter!=null) stWriter.Close();
}
}
|
|
|
|
|
If you only have static fields, there is no data in the object, so there is nothing to serialize.
---
b { font-weight: normal; }
|
|
|
|
|
So, Maybe i missunderstood the whole meaning of Static.. i thought a claasic datamembers , let's me , save my data at a class, that don't need and instance in order for me to read the data... a sort of public class. that i can approach from every class in my project./
in that case , i wanted to take the data from my xml file( the application settings) and then use it in multiple classes, without havin the need to open instances of the same class , and double my data....
am i missing the propuse of the static class?
|
|
|
|
|
No, that is correct. The static members reside in the class. But you are serializing an object, not the class.
---
b { font-weight: normal; }
|
|
|
|
|
ok, How can i serialize the class?
|
|
|
|
|
You can't serialize a class, as a class can not be dynamically created.
One way to serialize the static information could be to put the fields in a separate class, and put a static instance of that class in the original class:
public class MyInfo {<br />
string info, moreInfo, excessInfo;<br />
}<br />
<br />
public class MyClass {<br />
static MyInfo info = new MyInfo();<br />
}
Then you can add serialization to the info class, and serialize the static instance.
---
b { font-weight: normal; }
|
|
|
|
|
Man, i can't find the words , to express my gratitude...
i'm programming alone, a messy project.
i got no experiance in c#, and i can't ask anyone i know for help, cause they don't prog... and if they are,, not c#...
anyhow, Thank you... it works FINE! , i did exactly what you told me...
Bye - Yosi!
|
|
|
|
|
Hi All
I am using javascript to catch the browser closing event as I have to delete few files if the user closes the browser directly without logging off.
But if the javascript is disabled in the browser of the user, then files will not get deleted.
Is their anyway I can catch the browser closing event in asp.net rather than javascript?
Thanks
|
|
|
|
|
check this link
http://www.codecomments.com/ASP_.NET_Caching/message670221.html
|
|
|
|
|
hi Albanian
I did check the link. My Page_Unload event is not invoked at all. Is their anyway I can invoke that.
Using javascript I am able to catch the browser closing but I need some way to do without that.
|
|
|
|
|
chinky singh wrote: Is their anyway I can catch the browser closing event in asp.net rather than javascript?
No. The server never knows when the browser window closes, so there is no server side event for that.
If you don't mind waiting for the session to time out, you can catch that event.
However, there is no completely safe method to catch a user going away. If the application thread is recycled, some sessions might be removed without timing out. You will be able to catch almost every user going away, but you should have some code to take care of the occasional one that you can't.
---
b { font-weight: normal; }
|
|
|
|
|
I will ask the question with a 2 step introduction... Please help me.
Step 1: I write an unmanaged DLL in C++. Here is the exported function:
SAMPLEDLL_API void StringAsOUT_AllocatedInDll( char ** szParam )<br />
{<br />
*szParam = new char [ 128 ];<br />
strcpy( *szParam, "Please free my memory after using me!" );<br />
}
Step 2: I write a C# managed EXE to use this DLL
class Imports<br />
{<br />
[DllImport("SampleDLL.dll")]<br />
public static extern void StringAsOUT_AllocatedInDll( ref int szParam );<br />
...<br />
}
...<br />
Imports impObj = new Imports();<br />
int iAddressOfANSIString = 0;<br />
impObj.StringAsOUT_AllocatedInDll( ref iAddressOfANSIString );<br />
string strOUTPUTFromUnmanagedDll = Marshal.PtrToStringAnsi( ( IntPtr ) iAddressOfANSIString );<br />
Console.WriteLine( "Value of strOUTPUTFromUnmanagedDll = {0}", strOUTPUTFromUnmanagedDll );<br />
...
Question: The code works. It does give console output "Value of strOUTPUTFromUnmanagedDll = Please free my memory after using me!"
But isn't there a memory leak? How do I free the memory allocated by new[] inside the unmanaged DLL? All the Marshal class helps artciles always refer to how to free an unmanaged memory block when it is allocated from .NET code. But here it is allocated by unamanaged code. If anybody can please help me with this, I will be grateful.
Thank you!
|
|
|
|
|
http://www.csharpfriends.com/Spec/index.aspx?specID=25.8.htm
|
|
|
|
|
Thanks Albanian. But that really does not answer my question - as you see the article describes how to free the memory only if it was allocated from the C# code.
Like this: You in C#: you allocate some memory in unmanaged heap, and then you free it anfter using it. That is what the article shows.
But my situation is different: I am calling an unmanaged DLL that allocates the memory and returns the pointer. I use it from C#. There is no corresponding call back to the unmanaged DLL that will free the memory. I will have to free it myself from C# after using it.
As I did not allocate it, I don't have the HGlobal Handle or anything - all I have is the address returned. No Marshal class function is helping me out!
Thanks again for seeing my post and replying - I have been waiting for 2 days (i had posted this 2 days ago also) - but nobosy seems to have an answer!
Koushik Biswas
|
|
|
|
|
I mean, simply put, my question becomes: is there a way to call delete[] from C#?
Koushik
|
|
|
|
|
lookup this
http://www.c-sharpcorner.com/Language/PointersInCSharpRVS.asp
|
|
|
|
|
I was trying to do the same for some time.
Eventualy I realized that the best method is to allocate memory in C# and send a referance of the memory array to the C++ mthod\function. You might have a probelm determining the size of the array needed but that is a different story.
Even if you get it to work, it would be very careless doing so.
Gilad.
|
|
|
|
|
Dear all,
Can any one explain me what is the difference between container control and normal control Since both are derived from a Control class I am not able to differenciate them.please help me to find out the given control is container control or not.
Have a nice day.
|
|
|
|
|
Control container is example Panel in which we can set controls such is button,textbox,label,datetimepicker, etc....
Control is single one - example : button
Control is single one - example : label
Control is single one - example : textbox
Control is single one - example : datetimepicker, etc....
|
|
|
|
|
thanks for your reference.
How can I identify that the control is container control or not, at runtime.
Contact him at: hasansheik@hotmail.com
hasansheik@yahoo.co.in
hasansheik@lycos.com
|
|
|
|
|
hasansheik wrote: How can I identify that the control is container control or not, at runtime.
Test the control against System.Windows.Forms.ContainerControl using the is operator:
System.Console.WriteLine(this is System.Windows.Forms.ContainerControl);
System.Console.WriteLine(label1 is System.Windows.Forms.ContainerControl); Where this is the form. The above two lines return true and false , respectively, since Form is derived from ContainerControl , and Label is not.
ContainerControl inherits from ScrollableControl , which you can read about here[^].
Share and enjoy.
Sean
|
|
|
|
|
Dear all,
can any one help me to find out the given control is container control or not.
Warm regards,
S. Mohamed hasan.
Have a nice day.
|
|
|
|
|
Hello i would like to create an excel file from my application that could include chart or images, is there any free component, or any other way to do it without using excel.interop(i want to run it even in a pc without excel installed)
D.M
|
|
|
|
|
Here's what you do:- Create an Excel Workbook with the type of content you want on each page
- Save the Entire Workbook as an HTML Page
- Look at how everything gets save and reproduce it with your project
I've had to do this more than once. Works like a charm.
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|