Friday 15 April 2011

c# - Same code acts differently on different machines - what might be the cause ? (CLR version issue ?) -


I fixed a problem debugging, where our program crashed on the production server, but never on development machines.

I have made this small program, with which I can reproduce the issue:

  using the system; Using System.Collections.Generic; Using System.Linq; Namespace runtimebug {class program {static zero main (string [] args) {var coll = new collection {{"" test, new data ()}, {"test2", new data ()}}; Var datacuesen = coll.Cast & lt; Data & gt; (). ToList (); Console.WriteLine (dataSequence.Count); }} Category Archive: Dictionary & lt; String, Data & gt ;, IEnumerable & lt; Data & gt; {The public new INMM & lt; Data & gt; GetEnumerator () {value in value v (value v) {yield returns} v; }} Class data {}}  

while printing on my machine, this code prints "2". While running on the production server, it fails with the following exceptions:

  Unchecked exception: System. UnknownCast exception: Unable to remove type 'object'. System.Collections.Generic.KeyValuePair `2 [System. To type string, runtime bug.Data 'RunTimeBug.Data' on System.Linq.Enumerable & lt; CastIterator & gt; D__b0`1.MoveNext () on system Colllections.Generic.List`1 .. on the system (IEnumerable `1 archive) system. In LINQ.Enumerable.ToList [TSource] (IEnumerable `1 source) RunTimeBug.Program.Main (string [] args)  

On these machines I can only find the difference, that is Version 2.0.50727.4927 on CLR runtime machines, where it works, and on version 2.0.50727.1433 machines where it does not work.

As far as I can tell, the cast extension method gets the wrong version of IEnumerable on older machines, but "right" on a new machine.

Can anyone explain why I see this? What has changed in the 2 CLR runtime versions, due to which can it be?

Please note, I have already set up, and I know that the collection class in the above code is poor design because it implements 2 different IEnumerable found in our product "in the wild" , So I really want to know the exact reason.

I think Jason has mentioned the fix mentioned in that article in which your code will be later Have to work on release. I do not have access to the Pre-SP1 version of Enumerable. Cost is a bit difficult to guess.

One thing is for sure: Once this code creates an enumerable table. The catastator () is not guaranteed to work in your case. It sets an iterator to convert IEnumerable to IEnumerable & lt;> and is the GetEnumerator () to initialize the itater block to iter block. It can only make a dictionary call. The gate annotator (), does not make the keyValuePair casting that data will fail if this IEnumerable return fails, because the exception tells you.

The current version of Enumerable.Cast () tries to turn on IEnumerable & lt;> and the works that the creator () is not used.


No comments:

Post a Comment