Bad class token
JudahGabriel
Posts: 17
Hi folks
First let me say that all the developers here love ANTS Profiler. Saves us a ton of time measuring performance. Really easy to use. Great product.
I hit an interesting error while profiling our .NET 2.0 desktop app under ANTS Performance Profiler 2.6 build 62. I have a piece of code that basically is something like:
where myObject.Associations is a generic IList of a custom type called Entry. List is obviously System.Collections.Generic.List. Running this code outside the profiler works fine. However, running it under the profiler, I'm receiving the following error:
Any ideas?
First let me say that all the developers here love ANTS Profiler. Saves us a ton of time measuring performance. Really easy to use. Great product.
I hit an interesting error while profiling our .NET 2.0 desktop app under ANTS Performance Profiler 2.6 build 62. I have a piece of code that basically is something like:
List<Entry> associationsAlphabetical = new List<Entry>(myObject.Associations);
where myObject.Associations is a generic IList of a custom type called Entry. List is obviously System.Collections.Generic.List. Running this code outside the profiler works fine. However, running it under the profiler, I'm receiving the following error:
5/26/2006 2:18:20 PM. Bad class token.
Stack trace is
at MyCompany.MyCollection`1.CopyTo(T[] array, Int32 arrayIndex)
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
Any ideas?
Comments
Thanks a lot for your comments. I suppose that the first thing to ask would be whether or not you're using some kind of code obfuscator? It looks like either these strange accented characters are being added by some sort of code obfuscation or something is going wrong as ANTS Profiler is instrumenting the code.
This sounds very much like a bug that is happening during the instrumentation of your generic class. If possible, could you create a simple C# test app that mimics the same behaviour? If the same crash happens, could you mail your sample to support@redgate.com?
Many thanks,
Tom
Red Gate Software
In other words, the IL uses that particular character as a way to denote a generic type.
Tom, I'll see what I can do about getting you a repro case. If I get some free time, I'll give it a try in a testing project.
I have knocked up a quick sample that seems to cover all of the features that you describe. It does not cause any problems for ANTS Profiler 2.6. I would be really interested if you could create a small sample for us as we undoubtedly have a subtle bug with some of our handling of generic lists.
Thanks,
Tom Harris
Red Gate Software
I'm getting this same error upon starting my app under the profiler. Here's the error info & stack trace:
As you can see, this happened in the Algorithms.ConvertToArray method. That method is a simple method that converts any generic IEnumerable to an array. Here's the code snippet for that method:
Algorithms.Count is a method that simply counts the number of items in a generic IEnumerable by doing a foreach over the elements, incrementing an integer each iteration.
So this time the error happened when converting a generic IEnumerable to an array. It previously occurred (see the first post above) when converting a generic IList to an array. It seems the profiler is having a hard time on this.
Judging by the pieces of code that cause the BadImageFormatException, this seems almost certainly due to copying a generic IEnumerable to an array.
Also, in both places, the error was thrown while on a background thread. So it may have something to do with multiple threads running. Hard to say for sure.
Again, the key seems to be copying a generic IEnumerable to an array: this time it happens in my custom code that copies an IEnumerable to an array, previously the error happened in the .NET framework's List<T>.CopyTo method.
Version 2.7 fixes this problem. Thanks!
I'm glad that we've sorted this out for you!
I've looked into where the BadImageFormatException is getting thrown, and I've found it's being thrown in the same place: in a call to the ConvertToArray method.
If I delete the pdb files for my application prior to profiling, it works. Of course, no methods are then instrumented, so that's hardly a work-around.
Since I cannot, at this time, send you the application causing the problem, and since I can't seem to get a reproducible test case going, is there some way you guys could give me a special build with some verbose logging to help track down the problem? I'd really like to solve this one. It'd be in the best interest of both myself and Red Gate to have this problem solved.
p.s. this bug is still occurring in 2.7.1 -- this has been plaguing us for months, so I'd love to have it fixed! Thanks.
When running the above project under the ants profiler, click the big button, and the error will be thrown.
Bad class token :?
I'm evalueting ants profiler right now, bud we can't profile our application.
This exception is throw at startup
Are you seeing this on version 2 or version 3 of ANTS Profiler? If you're on V2, I suggest upgrading, as this will probably fix it.
Regards,
Robert
Red Gate