|
If I try to duplicate what you have:
Dictionary<int, MemoryStream> dictionary = new Dictionary<int, MemoryStream>();
var classObject = new ClassObject("hello");
int id = 666;
dictionary.Add(id, new MemoryStream());
var retriveObject = dictionary[id] as ClassObject;
}
public class ClassObject : MemoryStream
{
public ClassObject(string s) { }
} I don't get an error - I do get a null value, but that's what I expect.
So how is my code different from yours?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
hmmm, honestly I didn't know how to reply to this. It bothers me for a while.
I apology, but are you serious with that code snippet or you just give me a sarcastic reply?
P.S.
I didn't post the the whole code on may sample to make the post short.
|
|
|
|
|
No - I'm serious - I've just combined your code snippets into something that will compile and run to try and run down why you get the error in code that shouldn't give it. Obviously, I can't see code you haven't given us so I have to assume a minimum that gets it to compile - but I don;t expect it to match yours. It's there so you can explain where yours differs and to let me create a "closer" version for testing here.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Got it.
But i just decide to remove the parameter and just expose the property setter of one of its member, because it also introduce other code problem.
btw, thanks
|
|
|
|
|
You're welcome!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I'm positive you just need to add a parameterless constructor, EVEN if you don't intend to use it. You could always mark it internal too. I have to assume you're using an xml serializer because in my experience, this has always happened when an object lacked a parameterless constructor. I also have to assume that when you added a constructor with parameters, you removed the parameterless one. Can't do that...as a sidenote, it would be helpful to have explained how exactly you serialize the object for others to better understand your issue.
So basically, it should look like this:
[Serializable]
public class ClassObject : MemoryStream
{
internal ClassObject() { }
public ClassObject(string s) { }
}
|
|
|
|
|
Thanks, yeah it seems to work this way. But marking it internal will give the same error. Actually I use XtraReport a third party component it has SaveLayout and FromStream member.
But i just decide to remove the constructor parameter and just pass the value through a property.
P.S.
Whooo my ISP giving me crap right now.
|
|
|
|
|
In C#, I have a form contain controls. I want to save form to XML file, then load it from XML file.
Please tell me how to do.
Thank all!
|
|
|
|
|
|
Serializing a WinForm Control is difficult. Here are some resources on CP: [^], [^], [^].
Also, there is a new serializer here on CodeProject created by Christophe Bertrand that is the only serializer I know that can serialize most WinForm Controls: [^]. Note: since, to my knowledge, not every type of WinForm Control has been tested, this is a hypothesis: there may be a Type of WinForm Control, or UserControl, which may not be serializable.
«There is a spectrum, from "clearly desirable behaviour," to "possibly dodgy behavior that still makes some sense," to "clearly undesirable behavior." We try to make the latter into warnings or, better, errors. But stuff that is in the middle category you don’t want to restrict unless there is a clear way to work around it.» Eric Lippert, May 14, 2008
|
|
|
|
|
Say I want to use the Windows built-in speech synthesizer. In Visual Studio I have to right-click references and click add reference, add in System.Speech and THEN I can include a using System.Speech.Synthesis... This means that adding System.Speech as a reference is actually doing something that's allowing me to reference the class I want.
My question is, what is it doing and how can I do it manually? I've been toying with Visual Studio Developer Console and manually compiling .cs files with csc as shown on this page[^]
How could I compile a file that uses external resources? Thanks.
|
|
|
|
|
|
TheOnlyRealTodd wrote: n Visual Studio I have to right-click references and click add reference Which creates a .csproj file that, among other stuff, contains the references.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
You can use
csc Program.cs /r:SpeechSynthesizer.dll /out:YourOutputExeName.exe
1. Here Program.cs is the file to be compiled
2. /r:SpeechSynthesizer.dll is the dll in same directory
3. YourOutputExeName.exe is the name of the output exe
For more details refer this thread: http://www.csharpnet.net/article/building-csharp-applications
|
|
|
|
|
Hi,
I'd like to know if it's possible to pass memory stream between C# windows.
Thanks
|
|
|
|
|
A memory stream is an object, so yes. However you need to define what you mean by c# windows. I have never heard of a c# window!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
If the question you are asking is, can you share streams between two C# applications, there are various techniques. You could self-host WCF, or you could create something like a named-pipe or TCP connection. You could even create a memory-mapped file[^].
This space for rent
|
|
|
|
|
The requirement is to pass the data as a memory stream between two different C# applications.
This is the code to send stream. But it doesn't really work.
using (MemoryStream ms = GetMemoryStream())
{
int hWnd = FindWindow(null, "Receive");
int dataSize = Convert.ToInt32(ms.Length);
COPYDATASTRUCT cds;
cds.dwData = 0;
cds.lpData = Marshal.AllocCoTaskMem(dataSize);
cds.cbData = dataSize;
SendMessage(hWnd, WM_COPYDATA, 0, ref cds);
Marshal.FreeCoTaskMem(cds.lpData);
}
modified 17-Jul-16 20:18pm.
|
|
|
|
|
You will have to be more specific than "it doesn't really work". That tells us nothing useful about what issues you are seeing. What happens if you debug the application? Does it find the window? Is your structure created properly? Why do you have to use such a cumbersome method for passing data? A simple TCP connection would be enough.
This space for rent
|
|
|
|
|
Well, the requirement is memory stream. That is, the Receiving application has to get the data as a memory stream.
I get an error is at
int dataSize = Convert.ToInt32(ms.Length);
and the error is "Cannot access a closed Stream."
modified 18-Jul-16 19:17pm.
|
|
|
|
|
This did work!
MemoryStream ms = new MemoryStream();
using (ms = GetMemoryStream())
{
ms = new MemoryStream(ms.ToArray());
COPYDATASTRUCT cds;
cds.dwData = 0;
cds.lpData = IntPtr.Zero;
cds.cbData = 0;
try
{
ms.Flush();
ms.Position = 0;
int hWnd = FindWindow(null, "Receive");
int dataSize = Convert.ToInt32(ms.Length);
cds.dwData = 0;
cds.lpData = Marshal.AllocCoTaskMem(dataSize);
cds.cbData = dataSize;
SendMessage(hWnd, WM_COPYDATA, 0, ref cds);
}
finally
{
Marshal.FreeCoTaskMem(cds.lpData);
ms.Close();
}
}
But I think I'm not passing the memory stream to the other application. I declared the dwData as Memory Stream. Am I doing right?
|
|
|
|
|
I got it to work with the help of this website.
https://github.com/jimschubert/wixedit/blob/master/src/Helpers/CopyDataMessenger.cs
to jim
Thanks all for your help.
Thanks
|
|
|
|
|
HI,
I want to know what is Lifo and Fifo,as i search in net but i didn't get the answer clearly???
Can any one explain it with simple example???
Thanks...
|
|
|
|
|
LIFO - last in first out
FIFO - first in first out or fly in fly out (mining employees do this in remote sites)
Never underestimate the power of human stupidity
RAH
|
|
|
|
|