Re: Generics and their resulting class. Possible to obtain? by Nicholas
Nicholas
Tue Aug 14 12:59:11 CDT 2007
ThunderMusic,
If you are serializing a Dictionary<int, string> to a byte stream, then
you should be able to recreate that instance in any instance of an app that
requires a Dictionary<int, string>. There should be no errors here.
Can you recreate the example? I've done it here with that type, and
have no problems serializing/deserializing a dictionary like that and then
recreating the instance in another run of the app.
--
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com
"ThunderMusic" <NoSpAmdanlatathotmaildotcom@NoSpAm.com> wrote in message
news:eA2SGDo3HHA.4476@TK2MSFTNGP06.phx.gbl...
> hi,
>
> ok... maybe I explained it wrong... let's take Dictionary<int, string>.
> When I instanciate one of those, .NET generates on-the-fly a new class for
> Dictionary<int, string> (or maybe it's at compile time, but the problem
> stays the same for us because it's a web app, so it can be recompiled at
> any time). If I serialize it, it works fine. If I deserialize it within
> the same app instance, it works fine. If a new instance is started and I
> try to deserialize it, then I get an exception stating there is no
> constructor for Dictionary<int, string>.
>
> So, what I want to know is if it is possible to get the resulting class
> (The one .NET generates from Dictionary<int, string>) so we can take the
> code and put it in a file in our project so the class always stays the
> exact same class?
>
> btw, I know MS code is not bug free, but if we can build on something that
> was tested by thousands if not millions of users (developers), we go for
> it.
>
> Thanks
>
> ThunderMusic
>
>
> "raylopez99" <raylopez99@yahoo.com> wrote in message
> news:1187101870.493116.231080@k79g2000hse.googlegroups.com...
>> On Aug 14, 7:11 am, "ThunderMusic"
>> <NoSpAmdanlatathotmaildot...@NoSpAm.com> wrote:
>>> Hi,
>>> We need to serialize (binary) objects containing generic collections.
>>> The
>>> thing is, when we try to get the objects back (deserialize) with a
>>> different
>>> instance of the application, we receive an exception stating the
>>> constructor
>>> of the generic class does not exist.
>>
>> So there's your starting point. Do you have a constructor for the
>> generic class?
>>
>>> So Is there a way to obtain the
>>> resulting classes of the generics we use so we can add them as "normal"
>>> code
>>> in our app?
>>
>> What is "normal"?
>>
>>> We can develop our own starting from non-generic collections,
>>> but then we would have to develop our own methods and maintain them. The
>>> generics are already debuged and maintained by MS so we would like to
>>> generate them with the same generator the framework generates them if
>>> possible.
>>
>> Nothing is as it seems. MS code is not bug free. A while ago, a guy
>> had a problem here because he was using a structure rather than a
>> class--and precisely because of this, he had a problem (mixing
>> structures with classes is like mixing trucks with automobiles--they
>> don't really mix. Avoid structures).
>>
>>>
>>> So if I summarize what we want : We want to take the resulting class
>>> from a
>>> given generic and "copy-paste" the code and create a "user class" that
>>> we
>>> will add to our project.
>>>
>>> Is it possible?
>>
>> No. Not as you described it. It might help to know what interface
>> you're using.
>>
>> Good luck,
>>
>> RL
>>
>
>