|
View:
New views
9 Messages
—
Rating Filter:
Alert me
|
|
|
Array and IEnumerableHello everyone, I'm brand new on this forum.
I'm porting a C# application to mono 1.9 (I'm testing on MacOSX10.5) and I got some issues. This one occurs during an XML serialization. I've managed to solve some XML serialization issues by myself before, but I'm not getting this error, which I suspsect is a bug of the VM: -------- Begining of the error -------- Fleets.Redefis.Hardware.RDP.XML.RDPL.LUTRDPModule[] doesn't implement interface System.Collections.Generic.IEnumerable<Fleets.Redefis.Hardware.RDP.XML.IXMLModule> ** ERROR **: file mini-trampolines.c: line 42 (mono_convert_imt_slot_to_vtable_slot): should not be reached aborting... Stacktrace: [...] ../../working_dir/launchSimu.sh: line 19: 66088 Abort trap -------- Enf of the error -------- To sum-up, I've a class LUTRDPModule thath implement interface IXMLModule class LUTRFPModule : IXMLModule { [...] } And an array of LUTRDPModule LUTModule modules Which I cast into a Collection (ICollection<IXMLModule>)modules It looks like array in Mono are not enumerable, tough they are in .NET. And the ** ERROR ** looks like a bug in the VM. Am I wrong ? Thank you very much Antoine. |
|
|
Re: Array and IEnumerableI'm answering to myself since I think one could find it ineresting.
The cause of the problem was that the interface was not implemented. You'd say I'm stupid BUT that was tricky. Here is the context: I had two interfaces: public interface Interface1 {} public interface Interface2 {} And the following class: public class MyClass : Interface1, Interface2 {} In which only only Interface1 was implemented: I forgot the second one. And it used to compile. So a few minute ago I decided to remove Interface1 : public class MyClass : Interface2 {} and the the compiler told me that I forgot to implement some (in fact all) functions of Interface2. The amazing part is that both MS and Mono compiler did not detect the problem, and until I did not call those functions, no exeption was raised. And casting to Interface2 with .NET was not problem while it raised an exception (in fact it sorta crashed) under Mono. Any experience related to that ? Antoine
|
|
|
Re: Array and IEnumerableI'm running Mono 2.4 on Windows and am getting a similar error - is there any solution to this bug ? System.Array.InternalEnumerator<System.String[]> doesn't imple ment interface System.Collections.Generic.IEnumerator<System.Array> ** ERROR:mini-trampolines.c:67:mono_convert_imt_slot_to_vtable_slot: code should no t be reached This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information. cheers, Elise
|
|
|
Re: Array and IEnumerableHi,
I think your issue is due to another huge difference between Mono and .NET which leads to this kind of error. Here is an example: Let us consider "Human" and "Child" so that "Child" is derived from "Human": class Child : Human {} If now you create the List of type List<Child> children; In .NET, "children" will also implement the type "List<Human>": children is List<Child> >>> true children is List<Human> >>> true But in Mono it will not be the case: children is List<Child> >>> true children is List<Human> >>> false The only way to fix it would be to use some "#if MONO" / "#else" / "#endif"... In your case "Human" would be "System.Array" "Child" would be "System.String[]" "List" would be "System.Array.InternalEnumerator" Does it answer to you question ? If somebody from the mono programming could read this post and fix the issue... (and by the way thank you for the great pieace of software that Mono is)
|
|
|
Re: Array and IEnumerableOn Tue, Jun 30, 2009 at 10:30 PM, Yopmaster<trouve.antoine@...> wrote:
> I think your issue is due to another huge difference between Mono and .NET > which leads to this kind of error. Here is an example: > > Let us consider "Human" and "Child" so that "Child" is derived from "Human": > > class Child : Human {} > > If now you create the List of type > > List<Child> children; > > In .NET, "children" will also implement the type "List<Human>": > > children is List<Child> > >>> true > children is List<Human> > >>> true This is incorrect. List<Subclass> cannot be cast to List<Superclass> on .NET. Some examples like this can be solved by generic covariance/contravariance in .NET 4.0. See http://themonkeysgrinder.blogspot.com/2009/02/c-4-is-now.html for some explanations. However, since System.Generic.Collections.List<T> both accepts and returns objects of type T, I don't believe it could be made variant. -- Michael Hutchinson http://mjhutchinson.com _______________________________________________ Mono-devel-list mailing list Mono-devel-list@... http://lists.ximian.com/mailman/listinfo/mono-devel-list |
|
|
Re: Array and IEnumerableOn 平成 21/07/01, at 13:26, Michael Hutchinson wrote:
> On Tue, Jun 30, 2009 at 10:30 PM, Yopmaster<trouve.antoine@...> > wrote: >> I think your issue is due to another huge difference between Mono >> and .NET >> which leads to this kind of error. Here is an example: >> >> Let us consider "Human" and "Child" so that "Child" is derived from >> "Human": >> >> class Child : Human {} >> >> If now you create the List of type >> >> List<Child> children; >> >> In .NET, "children" will also implement the type "List<Human>": >> >> children is List<Child> >> >>> true >> children is List<Human> >> >>> true > > This is incorrect. List<Subclass> cannot be cast to List<Superclass> > on .NET. > > Some examples like this can be solved by generic > covariance/contravariance in .NET 4.0. See > http://themonkeysgrinder.blogspot.com/2009/02/c-4-is-now.html for some > explanations. However, since System.Generic.Collections.List<T> both > accepts and returns objects of type T, I don't believe it could be > made variant. > > -- > Michael Hutchinson > http://mjhutchinson.com Ho, you're right. I think this behaviour has changed since .NET 2.0. I've just checked and one of my old project do not compile anymore. ... or I might have missed something. Thank you for your link about covariance/contravariance, seems interesting... _______________________________________________ Mono-devel-list mailing list Mono-devel-list@... http://lists.ximian.com/mailman/listinfo/mono-devel-list |
|
|
Re: Array and IEnumerableOn 平成 21/07/01, at 13:55, Trouve Antoine wrote: > On å¹³æ 21/07/01, at 13:26, Michael Hutchinson wrote: > >> On Tue, Jun 30, 2009 at 10:30 PM, Yopmaster<trouve.antoine@...> >> wrote: >>> I think your issue is due to another huge difference between Mono >>> and .NET >>> which leads to this kind of error. Here is an example: >>> >>> Let us consider "Human" and "Child" so that "Child" is derived >>> from "Human": >>> >>> class Child : Human {} >>> >>> If now you create the List of type >>> >>> List<Child> children; >>> >>> In .NET, "children" will also implement the type "List<Human>": >>> >>> children is List<Child> >>> >>> true >>> children is List<Human> >>> >>> true >> >> This is incorrect. List<Subclass> cannot be cast to >> List<Superclass> on .NET. >> >> Some examples like this can be solved by generic >> covariance/contravariance in .NET 4.0. See >> http://themonkeysgrinder.blogspot.com/2009/02/c-4-is-now.html for >> some >> explanations. However, since System.Generic.Collections.List<T> both >> accepts and returns objects of type T, I don't believe it could be >> made variant. >> >> -- >> Michael Hutchinson >> http://mjhutchinson.com > > Ho, you're right. I think this behaviour has changed since .NET 2.0. > I've just checked and one of my old project do not compile anymore. > ... or I might have missed something. the case I use my old interfaces (e.g. IList instead of List) It the point explained in your link as "variance" right ? By the way I remember it was not supported by Mono 1.3 or something. I tested and it works with gmcs 2.4 (and 1.9 since I've just tested). > Thank you for your link about covariance/contravariance, seems > interesting... _______________________________________________ Mono-devel-list mailing list Mono-devel-list@... http://lists.ximian.com/mailman/listinfo/mono-devel-list |
|
|
Re: Array and IEnumerableOn Wed, Jul 1, 2009 at 1:13 AM, Trouve Antoine<trouve.antoine@...> wrote:
>>> This is incorrect. List<Subclass> cannot be cast to List<Superclass> on >>> .NET. >>> >>> Some examples like this can be solved by generic >>> covariance/contravariance in .NET 4.0. See >>> http://themonkeysgrinder.blogspot.com/2009/02/c-4-is-now.html for some >>> explanations. However, since System.Generic.Collections.List<T> both >>> accepts and returns objects of type T, I don't believe it could be >>> made variant. >> >> Ho, you're right. I think this behaviour has changed since .NET 2.0. >> I've just checked and one of my old project do not compile anymore. >> ... or I might have missed something. > > I have missed something and written too fast: this projects works in the > case I use my old interfaces (e.g. IList instead of List) > It the point explained in your link as "variance" right ? By the way I > remember it was not supported by Mono 1.3 or something. > I tested and it works with gmcs 2.4 (and 1.9 since I've just tested). What I said is true for "normal" (nonvariant) generic types. However, arrays aren't really generic types. They are treated "specially" by the runtime, so that they can be cast to IList<T> / ICollection<T> / IEnumerable<T>, where T is the array element type or any supertype. Presumably your problem was a bug in this feature, in an older version of Mono. This is demonstrated by the following sample. using System; using System.Collections.Generic; class Program { class A {} class B : A {} static void Main (string[] args) { B[] foo = new B[0]; Console.WriteLine (foo is IList<B>); // true Console.WriteLine (foo is IList<A>); // true List<B> bar = new List<B> (); Console.WriteLine (bar is IList<B>); // true Console.WriteLine (bar is IList<A>); // FALSE } } Covariance and contravariance are interesting because they make this kind of casting possible for generic types. They're in .NET 4.0, which is not yet released, and hence are not yet supported by Mono either. There are plenty of explanations on the web, so I won't got into details here. -- Michael Hutchinson http://mjhutchinson.com _______________________________________________ Mono-devel-list mailing list Mono-devel-list@... http://lists.ximian.com/mailman/listinfo/mono-devel-list |
|
|
Re: Array and IEnumerableOn Tue, Jun 30, 2009 at 12:45 PM, Elise Langham<i-ellang@...> wrote:
> > I'm running Mono 2.4 on Windows and am getting a similar error - is there > any solution to this bug ? > System.Array.InternalEnumerator<System.String[]> doesn't imple > ment interface System.Collections.Generic.IEnumerator<System.Array> > ** > ERROR:mini-trampolines.c:67:mono_convert_imt_slot_to_vtable_slot: code > should no > t be reached Can you please construct a minimal test case to reproduce this error and file a bug against the runtime? -- Michael Hutchinson http://mjhutchinson.com _______________________________________________ Mono-devel-list mailing list Mono-devel-list@... http://lists.ximian.com/mailman/listinfo/mono-devel-list |
| Free embeddable forum powered by Nabble | Forum Help |