|
I have done some modification for your code -
[KnownType(typeof (FaktaBok))]
[KnownType(typeof (BarnBok))]
[KnownType(typeof (SportBok))]
[DataContractAttribute()]
public class Book
{
[DataMember]
public int IsBn = 0;
[DataMember]
public string Titel = null;
[DataMember]
public string Author;
[DataMember]
public int Price;
[DataMember]
public String IsType = null;
}
public void SerializerTestMethod()
{
List<Book> books = new List<Book>
{
new Book()
{
Author = "author1",
IsBn = 1,
IsType = "istype1",
Price = 10,
Titel = "booktitle1"
},
new Book()
{
Author = "author2",
IsBn = 2,
IsType = "istype2",
Price = 20,
Titel = "booktitle2"
}
};
string writeTo = @"FilePath";
DataContractSerializer xs2 = new DataContractSerializer(typeof (List<Book>));
using (Stream s2 = File.Create(writeTo))
{
xs2.WriteObject(s2, books);
}
List<Book> outBook = null;
if (File.Exists(writeTo))
{
using (Stream s2 = File.OpenRead(writeTo))
{
outBook = (List<Book>) xs2.ReadObject(s2);
}
}
} }
}
|
|
|
|
|
Well, the reason I didn´t even get an error was because the Form_Load didn´t fire.
But now that I fixed that I get "unable to serilalize" due to elements not being closed or something like that.
The application is a library and customers can lend books.
What I do is save a list of books in a customer objekt so you know what books the customer borrowed.
What exactly is your code doing?
|
|
|
|
|
As per the subject, problem using DataContractSerializer, I have updated your contract with public properties. And the DataContract is getting serialized.
|
|
|
|
|
The only thing I can see you have changed is that you made the SerializerTestMethod.
Did you change anything else?
|
|
|
|
|
When using DataContract it is advisible to use Public properties instead of protected.
That is my other change ... Following is the serialized datacontract with sample data.
<ArrayOfBook xmlns="http://schemas.datacontract.org/2004/07/TestSampApp" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Book>
<Author>author1</Author>
<IsBn>1</IsBn>
<IsType>istype1</IsType>
<Price>10</Price>
<Titel>booktitle1</Titel>
</Book>
<Book>
<Author>author2</Author>
<IsBn>2</IsBn>
<IsType>istype2</IsType>
<Price>20</Price>
<Titel>booktitle2</Titel>
</Book>
</ArrayOfBook>
|
|
|
|
|
|
Hi guys,
I have the above error, it errors on the first line of my code:
HtmlDocument doc = (HtmlDocument)Enquiry_Sourcing_Netcomponents.Document;
doc.GetElementById("Session_Username").SetAttribute("value", "XXXXX");
doc.GetElementById("Session_Password").SetAttribute("value", "XXXXX");
doc.GetElementById("").InvokeMember("click");
HtmlElementCollection theElementCollection = doc.GetElementsByTagName("input");
HtmlElementCollection elems = doc.GetElementsByTagName("input");
foreach (HtmlElement elem in theElementCollection)
{
String nameStr = elem.GetAttribute("name");
if (nameStr != null && nameStr.Length != 0)
{
String contentStr = elem.GetAttribute("content");
System.Windows.MessageBox.Show("Document: " + Enquiry_Sourcing_Netcomponents.ToString() + "\nDescription: " + contentStr);
}
}
Any ideas?
|
|
|
|
|
Member 8811089 wrote: Any ideas? Yes, you cannot cast an object type to a dissimilar one - it does not work. So whatever class Enquiry_Sourcing_Netcomponents.Document is (mshtml.HTMLDocumentClass ), it is not the same as a System.Windows.Forms.HtmlDocument type.
Veni, vidi, abiit domum
|
|
|
|
|
What exactly is "Enquiry_Sourcing_Netcomponents.Document" ?
Why do you think it is convertible to Type HtmlDocument ?
Is HtmlDocument in this case the same thing as mshtml.HTMLDocument ?
Google CEO, Erich Schmidt: "I keep asking for a product called Serendipity. This product would have access to everything ever written or recorded, know everything the user ever worked on and saved to his or her personal hard drive, and know a whole lot about the user's tastes, friends and predilections." 2004, USA Today interview
|
|
|
|
|
Enquiry_Sourcing_Netcomponents is the name of the browser control in the project
|
|
|
|
|
You are probably using the "Microsoft Web Browser" control added to the toolbox from the "COM" tab when selecting Toolbox items.
Use the "WebBrowser" control from the toolbox located under the "All Windows Forms" node in the toolbox.
|
|
|
|
|
Hi TnTinMn,
I suggest you move your thoughtful reply to the top-level of this thread; I think you might have given the OP the answer to their problem; perhaps, since your reply has been inserted as a reply "underneath" my response, the OP might miss it.
bill
Google CEO, Erich Schmidt: "I keep asking for a product called Serendipity. This product would have access to everything ever written or recorded, know everything the user ever worked on and saved to his or her personal hard drive, and know a whole lot about the user's tastes, friends and predilections." 2004, USA Today interview
|
|
|
|
|
Bill,
As I replied to the OP's reply to your question, I think he/she/whatever should have been notified.
Whether or not my suggestion is the solution, I have a strong feeling that that knowledge will be like the old Tootsie Pop commercial -- "the world may never know."
Thanks for the concern.
|
|
|
|
|
Hi all,
I have a probably simple question:
I like to make a simple PGN player program with a (sizeable) chessboard UI. I have already programmed a PGN parser to parse besides moves and tags also comments and recurcive notation/variations.
My questions are:
1. What 'simple' chessboard interface (UI) is capable of accepting moves in standard PGN format to replay a game
2. I do not need a chess engine, it is purely for replaying of games
3. I use C# as programming language and have found several examples of programs that either have not the UI that I can use or they can't import complex PGN files
4. I also need to be able to use the program without Internet
I know of the existence of Winboard (which is C++) but it seems as overkill for my needs.
I have had a look at Sharpchess, SrcChess and PGNViewer for now.
Do you have any suggestions where to start?
Thanks in advance,
Francis
|
|
|
|
|
You could start with Chess Program in C#[^] for ideas.
However, request you not to plagurise this article.
|
|
|
|
|
i write this code :
when i debuged , in line 5 i see this error : "Exception of type 'System.OutOfMemoryException' was thrown."
do u know what should i do?
1- HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWriter);
2- DataGrid DataGrd = new DataGrid();
3- DataGrd.DataSource = dsGrid;
4- DataGrd.DataBind();
5- DataGrd.RenderControl(htmlWrite);
|
|
|
|
|
|
Quote: hi guys
i have this code which call an application into my picturebox
it works fine in vb 6 but when i converted to c# i got thi error
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
and when i trace the code its still in my form handle >>why it didn't go through all window handles??
i tthink my error is in the return of EnumChildProc function ,,,the return value or it calling in EnumChildwindow
here is the code hope sombody help me
<blockquote class="FQ"><div class="FQA">Quote:</div>using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace call_another_exe
{
public partial class Form1 : Form
{
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("user32.dll", SetLastError = true)]
static extern bool PostMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount);
[DllImport("user32.dll", SetLastError = false)]
static extern IntPtr GetDesktopWindow();
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool EnumChildWindows(IntPtr hwndParent, IntPtr lpEnumFunc, int lParam);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
[DllImport("user32.dll", ExactSpelling = true, CharSet = CharSet.Auto)]
public static extern IntPtr GetParent(IntPtr hWnd);
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
[DllImport("user32.dll", SetLastError=true)]
private static extern bool ShowWindow(IntPtr hwnd, int nCmdShow);
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
static extern int GetWindowTextLength(IntPtr hWnd);
private const string gcClassnameNotePad = "WindowsForms10.Window.8.app.0.33c0d9d";
public static int CC;
public int CurrentCount;
private const int SW_NORMAL = 1;
private const int SW_MAXMIZE = 3;
private const int SW_MINIMIZE = 6;
private const uint WM_DESTROY = 0x0002;
private const int WM_CLOSE = 0x0010;
public IntPtr EnumChildProc(IntPtr hwnd)
{
StringBuilder sSave;
StringBuilder lpClassName ;
long RetVal;
sSave = new StringBuilder("",GetWindowTextLength(hwnd) + 1);
GetWindowText(hwnd, sSave,sSave.Capacity);
if (sSave.ToString().Contains("ProgDVB"))
{
lpClassName = new StringBuilder(256);
RetVal = GetClassName(hwnd, lpClassName, 256);
if (lpClassName.ToString(0,Convert.ToInt16(RetVal)).Equals("WindowsForms10.Window.8.app.0.33c0d9d"))
{
CurrentCount = CurrentCount + 1;
SetParent(hwnd, this.pictureBox1.Handle);
if (hwnd != this.pictureBox1.Handle)
{
ShowWindow(hwnd, SW_MAXMIZE);
}
}
}
IntPtr y;
y = new IntPtr(1);
return y;
}
public IntPtr EnumChildCount(IntPtr hwnd, IntPtr lparam)
{
StringBuilder sSave;
StringBuilder lpClassName ;
long RetVal;
sSave = new StringBuilder(GetWindowTextLength(hwnd) + 1);
GetWindowText( hwnd, sSave, sSave.Length);
sSave.ToString(0,sSave.Length );
if (sSave.ToString().Contains("ProgDVB"))
{
lpClassName = new StringBuilder(256);
RetVal = GetClassName(hwnd, lpClassName, 256);
if (lpClassName.Remove(lpClassName.Length, Convert.ToInt16(RetVal)).Equals("WindowsForms10.Window.8.app.0.33c0d9d"))
{
if (lpClassName.ToString(0,Convert.ToInt16(RetVal)).Equals("WindowsForms10.Window.8.app.0.33c0d9d"))
{
CC = CC + 1;
}
}
}
IntPtr y;
y = new IntPtr(1);
return y;
}
public IntPtr EnumChildCloseup(IntPtr hwnd, IntPtr lparam)
{
StringBuilder sSave;
StringBuilder lpClassName;
long RetVal;
sSave = new StringBuilder(GetWindowTextLength(hwnd) + 1);
GetWindowText(hwnd, sSave, sSave.Length);
sSave.ToString(0,sSave.Length);
if (sSave.ToString().Contains("ProgDVB"))
{
lpClassName = new StringBuilder(256);
RetVal = GetClassName(hwnd, lpClassName, 256);
if (lpClassName.Remove(lpClassName.Length, Convert.ToInt16(RetVal)).Equals("WindowsForms10.Window.8.app.0.33c0d9d"))
{
PostMessage(hwnd, WM_DESTROY, 0, 0);
}
}
IntPtr y;
y = new IntPtr(1);
return y;
}
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show(GetDesktopWindow().ToString());
EnumChildWindows(GetDesktopWindow(), EnumChildProc(Handle), 0);
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
EnumChildWindows(GetDesktopWindow(), EnumChildCloseup(Handle, IntPtr.Zero), 0);
}
}
}
</blockquote>
i appreciate your great help
thank you
|
|
|
|
|
eng.iris wrote: i tthink my error is in the return of EnumChildProc function Compare it to the implementation here[^].
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
i solved it
i tried delegates and it works fine
thanks alot
|
|
|
|
|
I am trying to use a winform user control in an .aspx page. I could do it successfully without any issue. But now when I am trying to use an external .dll inside this user control then it is throwing me an error – “That assembly does not allow partially trusted callers”. But I could use this same user control inside a winform without any error. How could I make my web application a fully trusted to an external .dll? Kindly help.
|
|
|
|
|
|
does any body know how can read and write the hard disk sector with c# not assemblly?
thanks
|
|
|
|
|
PInvoke.net\[^] has API wrappers that may allow you to do this.
You can also explore this[^] article which would help you achieve this task.
|
|
|
|
|
|