|
Again, I gave a solution that doesn't require changing SOAP: create a new library that contains the Type in question and use the Type out of that library in both assemblies that you mentioned earlier. That way both previously mentioned assemblies are independent of each other but share a common Type which both can serialize(/deserialize). This is an easy solution.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Heath,
Thanks for your replies! I finally managed to make it work by reflecting all the properties of my class into a dataset and exporting the dataset to xml. This is powerful enough for my needs.
I have encapsulated everything pretty well and it works like a charm now!
Thanks again!
Carl
|
|
|
|
|
So now you take the most inefficient method for serializing an object? Seriously, it's not a hard solution and this is a typically problem that modular programming is meant to solve. Just put the Type in a different assembly that both the first and second assemblies reference. This is a proper solution and what libraries are meant to do.
You can do it the way you want, but it's terribly inefficient.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Imagine that there are already some serialized objects and I want to change the namespace for an application. How can I do it? Is there a way to do that? I do not know how to exclude the namespace information while serializing or deserializing. Does anyone knows if it is also a subject in binary serialization.
|
|
|
|
|
It would have to, otherwise how would deserialization know which object to create to hold the following data?
This is not unfounded. Even in COM serialization (for instance, in compound documents format liks Word) the CLSID is stored for embedded objects so that they can be reconstituted, then they are handed various interfaces and perform their own persistence based on what interfaces they implement (and if the contianer application supports that persistence interface, like IPersistStorage ).
You could have a conversion program to upgrade your serialized data object, either by manipulating the data stream itself or using the Type in your old assembly with a similar Type in your new assembly (the common assembly) and deserialize the old Type, clone the data to the new Type, and serialize that.
Next time, you should be careful to design your assemblies in such a way that common functionality and types are in a common library, rather than duplicating such functionality and types in two different assemblies. As you can see, this is especially a problem when remoting.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
I found the solution and it solves lots of problems.
You are right. How would deserialization know which object to create to hold the data. So there must be a way to tell the deserialization which object to create. And there is such a way.
While deserializing it is trying to create the object in the serialized data. But I want to create my new object. So I wrote my special binder for my object.
public class SpecialBinder :
System.Runtime.Serialization.SerializationBinder {
public override Type BindToType(string assemblyName, string typeName)
{
MyObject obj=new MyObject();
return obj.GetType();
}
I binded my new binder object for deserialization. So I told the deserialization to create my new object. It may whether be under a new name space or even in a new assembly.
soapFormatter.Binder=new MyBinder();
MyObject obj=(MyObject)formatter.Deserialize(myStream);
What if there are multiple objects that are marked as serialized in the serialized object. At least now I wrote the solution. It should return all the classes that are serialized in the main serialized object.
public override Type BindToType(string assemblyName, string typeName)
{
MyObject1 obj1=new MyObject1();
MyObject2 obj2=new MyObject2();
MyObject3 obj3=new MyObject3();
if (typeName.IndexOf("MyObject1")>0){
return obj1.GetType();
}
if (typeName.IndexOf("MyObject2")>0){
return obj2.GetType();
}
if (typeName.IndexOf("MyObject3")>0){
return obj3.GetType();
}
return null;
}
This approach works in both binary and soap serialization.
I will try to write a generic approach. Then I can share it with you.
I know it is not a good idea to do such things but in my case I have to do that.
|
|
|
|
|
Hmm, I didn't know about the serialization binder. Very interesting.
And speaking of interesting serialization things, you should check out the ISerializationSurrogate . It won't help you, but it may come in handy for other things. Just thought I'd mention it.
One thing, though, I wouldn't return null from BindToType . Instead, you could return Type.GetType(string.Format("{0}, {1}", typeName, assemblyName) , or else nested objects or other objects won't be (de)serialized (unless returning null tells the serializer to use the actual type, but it's not documented and I don't feel like digging through the IL to find it! ).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
I have a fairly simple C# app with tooltips on various controls. When I hide the form or minimize it, and then restore it... the tooltips stop working.
I've just gone to the extent of trying to remove and reset all of the tooltips in the form's StyleChanged and Activated events... but that didn't even work.
I've checked the Active property of the tooltip object, and it is always set to true.
Any ideas? This is really annoying!
Thanks,
Todd
|
|
|
|
|
Is this with the ToolTip provider in the .NET BCL?
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Hopefully this is the right place to post this question. I am new to C# and am learning while developing some internal tools.
I have created a form which contains a Crystal Report Viewer on the form. I am then attaching a ReportClass object to it to display the report. This works as expected and my report is displayed.
ReportClass reportClass = new TasksReport();
reportClass.SetDataSource(dataSet);
crystalReportViewer.ReportSource = reportClass;
However, it takes some time (approx. 10-15 seconds) to process a DataSet which contains 4 related tables.
What I want to know is, is there a callback method or a event that I can use to display a "Progress Windows" or other on the screen while the report is being generated?
Thanks,
Trevor
|
|
|
|
|
The only event on ReportDocument is InitReport which fires when the report definition is loaded. I also didn't notice any private or internal methods or properties you could leverage through reflection when looking at the IL for that class.
At least make sure you show a wait cursor. A good way to do this is to save the current cursor and make sure that that cursor is restored - even in case of a failure:
Cursor old = Cursor.Current;
try
{
Cursor.Current = Cursors.WaitCursor;
}
finally
{
Cursor.Current = old;
old.Dispose();
} I know it's not what you want, but it at least informs the user that something's going on (which is part of the Windows UI guidelines anyway).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Wow, heath you're doing a good job of answering questions.
If anyone can help me out then here is what i have. I have an browser control. I use mshtml to access the htmldocument and then the htmlbody of the doc. After setting the innerHTML of the body I cannot get any of the scripts to run.
|
|
|
|
|
Is the original script (if any) in the body, or are you adding a script block to the body? If you're adding a script, you have to trigger an even that will cause the script to run. Basically, there's two ways that scripts are executed:- When a document is being read, any script that is in the document scope (not in a function or referenced in a handler) is run asynchronously to loading (basically, executed as it is read). This is commonly used for some initialization or write a string to the document in place of the script.
- As an event handler. This is either by assigning a function to a handler, or specifying a function in an element event attribute (like onload, onclick, etc.).
So, when you "inject" script into the body, you need to either invoke it (you can use IHTMLDocument.scripts among other ways) or raise an event on an element (there are several ways to do this). This will call the event handler function. As far as the first method of executing a script I mentioned, it won't work because the document is already loaded (and that method is quickly dying with better DHTML support).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
The script is part of the html string I pass to the WebBrowser control. When I open the file normaly with IE it works fine, but when I pass it to the WebBrowser control using the interfaces provided by mshtml none of the scripts work.
This is a weird one. I don't know. If someone can help me that would be great.
|
|
|
|
|
That's what I just got done saying: there are only two ways to invoke a script. Since the document isn't loaded, you can invoke an in-line script that is only executed while loading along with the rest of the document (which is why it works if you simply load the document with the script already in it). The only other way is through an event. Please read my first answer again. Your answer is there. We do a similar thing at work and it works fine.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Re: Reflection question
leppie 12:51 17 Nov '03
> I would think so, although i havent really looked at it explicitly. Generally there will still be a similar overhead as with delegates which is genrally 8 - 10 times slower than a normal non-virtual call. For maximum speed I recommend using an interface.
Dear Leppie, Sorry to post it late, I had to re-post this piece of our thread to remind you of the topic.
Can you please tell me what you mean by 'interface' here? is it related to run-time type access ??
Thank you
---
limit nSun = God
n → ∞
|
|
|
|
|
Basically:
You define a small assembly with some interfaces
eg.
public interface IFoo
{
int Bar();
string Name {get;}
}
Now in the loading assembly , you implement these interfaces, say class ABC : IFoo .
In the loader assembly, you use reflection to find the types in the loading assembly that implements IFoo , which in this case will be ABC . But we dont care what ABC does, only IFoo . So the ABC gets instantiated as an IFoo instance. Now withing your loader assembly, you simply call the interface.
It is a bit more work though, but it will be faster.
leppie::AllocCPArticle("Zee blog"); Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.
|
|
|
|
|
This is just a large "attaboy" to Heath. It seems like every time I'm about to attempt an answer at a question here in the C# board, Heath has beat me to it. I'm firmly convinced he's really an AI plugged into both the MSDN library and CodeProject.
Keep it up, Heath.
Jeremy Kimball
|
|
|
|
|
|
Heath Stewart wrote:
knowing exactly where to look for things (or how to research things I don't remember / know)
I can't emphasize the above enough to those who are getting into or planning on getting into the coding (or really, ANY field). It is not what you know. It is how fast you can learn it.
Jeremy K.
(just for the helluvit
GAT/E/CS d- s:-- a- C++++$ !U P+ L+ !E W+++$ N++ o? K- w+++$ O- M-- V PS+ PE++ Y+ PGP
t 5 X+ R+ tv+ b++++ DI++++ D++ G e++ h--- r++ x**
|
|
|
|
|
I agree, Heath is the man! Not only does he answer most questions, but he provides clear and thorough explanations.
Kudos to you Heath!
Regards,
Alvaro
He who laughs last, thinks slowest.
|
|
|
|
|
He's definitely been helping lots of people and doing a fine job at it.
I try to answer a question here or there when it's something I know off the top of my head and I happen to be looking, but he seems to be more like a lifeguard watching the water .
I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.
-David St. Hubbins
|
|
|
|
|
|
Nah, not an AI. Just a smart guy with a decent neural jack plugged in to MSDN and CodeProject!
Way to go, Heath. I rest well at night knowing that you're protecting the good programmers of Gotham City. You're all business.
Regards,
Jeff Varszegi
|
|
|
|
|
he makes fun of me alot...
cause i'm dumb.
/\ |_ E X E GG
|
|
|
|