|
IFormatter myFormatter = new Formatters.Binary.BinaryFormatter();
---
It's amazing to see how much work some people will go through just to avoid a little bit of work.
|
|
|
|
|
Hi Guffa! Thanks for replying. I've already done this. It don't seem to work. This is the code.
void WriteBinary(String FileName, DataSet ds)
{
ds.RemotingFormat = SerializationFormat.Binary;
IFormatter myFormatter = new Formatters.Binary.BinaryFormatter();
Stream myStream = new FileStream(FileName, FileMode.Create);
myFormatter.Serialize(myFormatter, ds);
}
These are the errors
Error 1 The type or namespace name 'Formatters' could not be found (are you missing a using directive or an assembly reference?) d:\Nitin\Serialization1\Serialization1\Serialization1\Form1.cs 58 42 Serialization1
Error 2 The best overloaded method match for 'System.Runtime.Serialization.IFormatter.Serialize(System.IO.Stream, object)' has some invalid arguments d:\Nitin\Serialization1\Serialization1\Serialization1\Form1.cs 60 13 Serialization1
Error 3 Argument '1': cannot convert from 'System.Runtime.Serialization.IFormatter' to 'System.IO.Stream' d:\Nitin\Serialization1\Serialization1\Serialization1\Form1.cs 60 35 Serialization1
Thanks
Don't Quit
|
|
|
|
|
Nitin1981 wrote: Error 1 The type or namespace name 'Formatters' could not be found (are you missing a using directive or an assembly reference?
I see. Specifying namespaces works a bit different in VB and C#. Specify the full namespace:
IFormatter myFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
Nitin1981 wrote: Error 3 Argument '1': cannot convert from 'System.Runtime.Serialization.IFormatter' to 'System.IO.Stream'
Why have you put the formatter there? In the VB code it's the stream.
---
It's amazing to see how much work some people will go through just to avoid a little bit of work.
|
|
|
|
|
Hi Guffa, I got it to work. Ya I did make a mistake.
1. Even after importing necessary namespace fully qualified namespace has to be specified in c sharp so is it a bug in Csharp.?
2. Another thing how do you arrive at the conclusion by trial & error or is there some other way.
Thanks for your assistance.
Don't Quit
|
|
|
|
|
Nitin1981 wrote: 1. Even after importing necessary namespace fully qualified namespace has to be specified in c sharp so is it a bug in Csharp.?
No, it's not a bug. C# is just a little stricter about separating namespaces from class names than VB. When you import a namespace in C# you have to specify the complete namespace, while in VB you can import part of the namespace and specify the rest of the namespace in the code. If you specify the complete namespace, you can use the BinaryFormatter class name in the code without the namespace:
using System.Runtime.Serialization.Formatters.Binary;
Nitin1981 wrote: 2. Another thing how do you arrive at the conclusion by trial & error or is there some other way.
What conclusion?
---
It's amazing to see how much work some people will go through just to avoid a little bit of work.
|
|
|
|
|
Hi I mean the difference between the syntax in c# and vb.net (for example in this case)
Thanks!
Don't Quit
|
|
|
|
|
You mean how I translate the code from VB to C#?
Basically I read the code and make sure that I understand what it does, then I write code that does the same thing. In .NET you have the advantage of the shared framework, which means that the classes used are the same and work the same.
---
It's amazing to see how much work some people will go through just to avoid a little bit of work.
|
|
|
|
|
No I mean first (in your first reply of this question) you also guessed that code should be like this
IFormatter myFormatter = new Formatters.Binary.BinaryFormatter();
Which was also the case with me. But later you came to the conclusion we need to specify full path in c#.I think now I'm clear enough.
Thanks a lot
Don't Quit
|
|
|
|
|
Specifying the full namespace is a way that always work, regardless of what namespaces you have imported (provided of course that you have a reference to the dll containing the class). Once it works, you can start looking into writing the using statement that imports that specific namespace.
I don't develop anything in VB.NET, that's why I didn't remember the difference in how namespaces are used from the start.
---
It's amazing to see how much work some people will go through just to avoid a little bit of work.
|
|
|
|
|
Ok Got it! Thanks for your expert opinion and I will try to implement them myself.
Thanks once again
Don't Quit
|
|
|
|
|
Hi all,
How I can know that when my form is obscured by another window and name of that wimdow during run time?
Thanks,
Muharrem
|
|
|
|
|
Hello everybody,
I have to copy and delete a file by using a ftp path (ftp://xxx.xxx.x.x/mydirectory).
Is there a possibility in .Net1.1 without using a ftp-server?
Thank's for youre time!
Martin
|
|
|
|
|
There is no direct FTP functionality in .NET1.1. As this is simply socket programming, you can roll your own or use something like this:
http://www.codeproject.com/cs/internet/ftplib.asp[^]
the last thing I want to see is some pasty-faced geek with skin so pale that it's almost translucent trying to bump parts with a partner - John Simmons / outlaw programmer
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
|
|
|
Hi All,
Can anyone please tell me hoe to set the value to a custom exception object?
If so, pls give a code snippet?
thanks in advance
Regards
babu
|
|
|
|
|
What value?
You can create an Exception object with any message you like:
new ApplicationException("Nu sket det sig rejält, må jag säga.")
You can also create specific Exception objects for different kinds of errors. Some examples:
new ArgumentNullException("path", "The path argument may not be null.")<br />
new NullReferenceException("The operation resulted in a null reference.")<br />
new IndexOutOfRangeException("The position has to be in the range 0 to 9.")<br />
---
It's amazing to see how much work some people will go through just to avoid a little bit of work.
|
|
|
|
|
but for this i've to set the value to the property in the class as follows.
this.Message = "msg"; or exception.Message="msg";
how to set that??
|
|
|
|
|
Set the message property of the exception in the constructor.
|
|
|
|
|
yes. as you said i put the message property in constructor. even thne it shows the error i've mentioned in prev message.
babu
|
|
|
|
|
babutkchn wrote: as you said i put the message property in constructor. even thne it shows the error i've mentioned in prev message
Did you call it right:
public MyException : ApplicationException<br />
{<br />
public MyException(string message) : base (message)<br />
{<br />
}<br />
}
|
|
|
|
|
|
Then the exception should have the message that is passed in to the constructor. Which is as it should be.
|
|
|
|
|
I explained how you do that in the other thread. If you didn't create mutiple threads about the same thing, the confusion would be less.
---
It's amazing to see how much work some people will go through just to avoid a little bit of work.
|
|
|
|