|
I'm just curious why you're serializing the ArrayList to a MemoryStream to bet the byte[] instead of just serializing the whole shabang?
In any case, it I would venture a guess that for some strange reason, the BasicClass Type is not the same. Remember that a Type consists of the fully-qualified class name (i.e., includes the namespace), the assembly, the version, the culture and public key token). One cause of this is that perhaps you're using automatic versioning with your assembly, so that the old and new BasicClass Types differ by version. If that's true - there's your problem.
There's two ways to solve this: don't use automatic version (so little control and real pain in the arse with larger solutions, especially when you use late-binding like for plug-ins and what-not) or derive your own SerializationBinder and override BindToType . You can make this implementation generic so that the version number is basically ignored, as I did here:
public override Type BindToType(string assemblyName, string typeName)
{
string name = assemblyName.Substring(0, assemblyName.IndexOf(','));
Type t = Type.GetType(typeName + ", " + name);
return t;
}
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Heath Stewart wrote:
I'm just curious why you're serializing the ArrayList to a MemoryStream to bet the byte[] instead of just serializing the whole shabang?
What do you mean?
Heath Stewart wrote:
In any case, it I would venture a guess that for some strange reason, the BasicClass Type is not the same. Remember that a Type consists of the fully-qualified class name (i.e., includes the namespace), the assembly, the version, the culture and public key token). One cause of this is that perhaps you're using automatic versioning with your assembly, so that the old and new BasicClass Types differ by version. If that's true - there's your problem.
I though that was the problem myself (I had the same issure in the past) so I disabled the automatic versioning, wiped clear any objects stored in the DB, and started again, to see if it was the issue but it didn't make any difference at all.
Regards,
Brian Dela
http://www.briandela.com IE 6 required. http://www.briandela.com/pictures Now with a pictures section http://www.briandela.com/rss/newsrss.xml RSS Feed
|
|
|
|
|
Brian Delahunty wrote:
What do you mean?
Why don't you just serialize the entire object graph? Serialize your class's members, include the ArrayList . The runtime serialization framework will serialize the ArrayList , which will serialize BasicClass . Then you just take all that and save it in the DB.
Brian Delahunty wrote:
I though that was the problem myself (I had the same issure in the past) so I disabled the automatic versioning, wiped clear any objects stored in the DB, and started again, to see if it was the issue but it didn't make any difference at all.
The InvalidCastException you're getting indicates that the classes are indeed not the same. I would check with the debugger to find out the full Type of the object and compare with what it should be.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Heath Stewart wrote:
Why don't you just serialize the entire object graph?
Ah, K. Nah.. just want the arraylist. I don't need to serialise anything else in that class so I don't see the point.
I go tthe problem fixed. Was to do with the fact that, now I think this fixed it, one version of the assembly was signed and the other wasn't even though they both had the same version number. I think that's what it was. I done a load messng with it but it worked in the end.
Regards,
Brian Dela
http://www.briandela.com IE 6 required. http://www.briandela.com/pictures Now with a pictures section http://www.briandela.com/rss/newsrss.xml RSS Feed
|
|
|
|
|
The version number doesn't matter so long as the version does change between Types. The fact that one assembly wasn't signed could be a problem, although you should've gotten an error or at least a warning. A signed assembly cannot use an unsigned assembly, though the reverse is possible.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
|
Haven't in a long time. Just really don't have the time.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Anyone can please help me find a sample 'C' code for decreasing connect timeout.
|
|
|
|
|
You should try the Visual C++[^] forum. This is the C# forum, where C# is a language that targets the Common Language Runtime (CLR - part of the .NET Framework).
There's also always google[^].
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
when i run two client programs in the same pc, i got a problem, because the two program need to read one same bitmap file, when one read that, another can not ,so can you tell me how can i realize the file sharing;
|
|
|
|
|
See the FileStream class in the .NET Framework SDK. You can open a FileStream on the bitmap with a shared ability to read the file:
FileStream file = null;
try
{
file = new FileStream("test.bmp", FileMode.Open, FileAccess.Read,
FileShare.Read);
using (Bitmap bmp = new Bitmap(file))
{
}
}
catch (Exception ex)
{
Console.Error.WriteLine(ex.Message);
}
finally
{
if (file != null) file.Close();
}
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I have one problem: I have a enum of lexeme, to examle "try","hi","not". Please help to make a regular expression string, what find in text data lexem's.
|
|
|
|
|
If you're trying to perform lexigraphical parsing, regular expressions are not the way to go. Regular patterns are for pattern matching where a pattern is known. Linguistics is far too complex for such simple (in comparison) pattern patching.
There is plenty of material on lexicography on the Internet. I suggest you google[^].
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks,
|
|
|
|
|
Hello all. First time posting here. I am quite new to C# and was wondering how to create the Options dialog form that is used in the VS.Net IDE. The one where the TreeView is on the left and the different controls are on the right. I have a simple application I am developing and would like to incorporate this style into my app. I have not had a chance to do a thorough search of all the posts or articles yet, but what I have searched, I have not found anything on this topic.
Any help is greatly appreciated.
Thanks again!!
|
|
|
|
|
There are several articles here on CodeProject that describe such a UI, like A designable PropertyTree for VS.NET[^]. You could search for others if you like. Just use the search box toward the top of the page (right under "Bob" and The Code Project logo).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks a lot, Heath! I appreciate your time. In the future I will do a more thorough search.
|
|
|
|
|
The reality is that most of the dialogs in the VS IDE are actually DHTML dialogs.
|
|
|
|
|
Is there a way to access the Statusbar (defined in the main window frmMain) from a Class (SubClass) which is called from frmMain?
eg:
in SubClass something like:
frmMain.statusbar="Hello";
Thanks!
Ariadne
|
|
|
|
|
There are several possibilties to do this.
1. You could pass the StatusBar as a parameter to the method where you need access.
2. If you need access to the StatusBar in several methods of your subclass, you could pass the StatusBar to the constructor of your subclass and store it internally.
Hope this helps a bit
|
|
|
|
|
If you declare the StatusBar field as public or internal (or protected internal), you can also cast a control's Parent form to MainForm (or whatever the class name is, not the instance name) and access the StatusBar :
MainForm form = Parent as MainForm;
if (form != null)
form.statusBar.PerformStep(); Also, it's not a "subclass", but a child class. A subclass is a class that derives from another class. A child class is a class that is a child member of another class.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
That's I'm looking for!
but what do you mean with controls Parent form?
The Statusbar is in my Main window class frmMain.
So I think I have to do something like
frmMain form = Parent as frmMain;
but then 'Parent' is unknown.
Ariadne
|
|
|
|
|
Parent is a property inheritted from Control . Any class that derives from Control inherits the Parent property, but this could be your frmMain (which, BTW, is a terrible name for a class - see Naming Guidelnes[^] in the .NET Framework SDK*), a Panel , or any container. The as keyword in C# basically performs an exception-handled cast so that it just returns null instead of throwing an InvalidCastException .
* Keeping with naming conventions within a framework or API (be it .NET, Java, MFC, etc.) is important. It fosters better development within that framework or API, among other things.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I think, i have a tiny annotation to Heaths posting.
Use a public or internal (or protected internal) Property to make your Statusbar field accessible. This allows further restriction of accessibility, for example you could make it read only.
|
|
|
|
|
Ariadne wrote:
Is there a way to access the Statusbar (defined in the main window frmMain) from a Class (SubClass) which is called from frmMain?
Hi,
I would not access the status bar object that is defined in the main window from a design perspective. Your sub-class should not really know about the status bar in the parent window. Such kind of dependency is almost always a very bad idea.
If you need to update the status bar from your control, maybe a better idey would be to use windows events.
Pankaj
Without struggle, there is no progress
|
|
|
|