"Common Language Runtime detected an invalid program." error

Hi All,

I encounter the following problem when using ANTS Performance Profiler 7.4 Professional.

I'm trying to profile a console application, developped using .NET 3.5. and VS2008.
The profiled application failed with an error :
Common Language Runtime detected an invalid program.

This application works fine when launched either standalone or under debugger.

Profiling works also if the debugging session is launched with options :
- Sample method-level timings.
- Method-level timings; only methods with source
- Method-level timings; all methods

But fails with the options :
- Line-level and method-level timings; only methods with source
- Line-level and method-level timings; all methods

Any help ?

Regards,
«1

Comments

  • Thanks for your post. We've not seen this message for a while from what I can tell. Are you definitely on the latest version?

    If so, can you first try profiling your application on another machine, just to eliminate something being corrupt on the first box?

    If that doesn't help, then it's likely that the line level option is hitting a security problem or similar, so trying with the profiler running elevated (right click - run as administrator) is a good first step, as is turning off your antivirus temporarily.

    If the problem persists then we'll most likely need to know more about your code and any 3rd party assemblies you may be using. You can contact us directly by mailing [email protected] quoting F0069401 in the subject.
    Systems Software Engineer

    Redgate Software

  • sfsf Posts: 16 Bronze 2
    Hi,

    I am experiencing the exact same issue. I tested with ANTS Profiler v4.last v5.last et v7.last, on two different machines, behavior is exactly the same.

    My project is WinForm based, .Net 2.0, built using VS 20102, I am under Win XP.

    What is really strange is that last time I profiled the same application (a few weeks ago on the same installation) I had no issue at all with my v5.last (which is my regular version). The source code was modified since then, of course, but we didn't add new library or made serious architecture modifications.

    More precisely, the code where the exception now happen every time has not been changed for ages, and apart from using generics, I don't see anything particular here. I am pretty sure the call stack was the same last time I successfully profiled.

    I tried to thing of what may have changed in my configuration, but I would tend to say nothing but automatic Windows Update stuff.

    Could it be that an update to .Net, for instance, causes this issue?

    Thanks in advance for your help, I need a way to profile my application with line details...
  • Hi,
    I guess it's feasible that a windows update /may/ have altered something - if you've not really changed the code much then it's definitely unusual as obviously the profiler hasn't change either.

    One thing to check; are you using the AllowPartiallyTrustedCallers attribute anywhere in your solution? This has been known to cause problems with line level timing.
    Systems Software Engineer

    Redgate Software

  • sfsf Posts: 16 Bronze 2
    Hi James,

    Thanks for the quick reply. We don't use AllowPartiallyTrustedCallers attribute at all.

    Well, I did one additional test: I restored an old project from an archive, dated September 24, 2012.

    At that time we were still using VS2005, and for sure I was then able to profile this project.

    I recompiled it (with VS2005) and tried to profile it with my good old ANTS v5 and guess what: I got the very same exception at the exact same place in the code (which indeed hasn't change)!

    So: same code, same ANTS, VS version ruled out.. I think a windows update might be the root cause. I am now at .NET: 2.0.50727.3643

    What should I do? Give you my project is of course not possible and creating a test project I can share may take some time...

    Any idea?
  • I guess the first thing is to look through your list of recent windows updates that were applied to see if anything looks relevant (security fixes, updates to .NET)
    I believe it's possible to uninstall updates but that's all a bit trial-and-error unless there aren't many in between now and when it last worked...
    Systems Software Engineer

    Redgate Software

  • sfsf Posts: 16 Bronze 2
    Well, of course that's the thing to do... I just hoped you'll have some good idea to save me from this time consuming task ;-)

    Anyway, I found the nasty update: it is named: KB2742596 and it's the before last .NET Framework 2.0 Service Pack 2 critical update. I installed it around January 18, 2013.

    To figure this out I first removed the 2 last updates of this kind (the last one was installed this week): everything went right (not even had to rebuild my solution): no exception during profiling. I reinstalled KB2742596: crash.

    So, now at least I can work, but I have the feeling that this situation is not very stable: should I refuse any critical update from now on? Doesn't sound good.

    Do you have any comment?
  • sfsf Posts: 16 Bronze 2
    Hi again,

    Is Red Gate planning to address this issue?
  • Apologies - I was out of the office on Friday, however some of our dev team have attempted to reproduce the problem by testing on machines with/without the applicable patch. Although it seems to be causing problems for other people (unrelated to our profilers) such as here.

    I'm guessing that the problem is down to a combination of that patch and your particular application- are you able to supply us your app or alternatively something simple that demonstrates the same problem?
    Systems Software Engineer

    Redgate Software

  • sfsf Posts: 16 Bronze 2
    Thank you.

    I am trying to narrow down the code that actually trigger the issue, but I did not succeed so far.

    It is related to constructing an object that has a generic parameters, but I guess that the type actually used is relevant...

    I'll keep you up to date.
  • I'm having the exact same issue and I don't have the Windows Update installed. I have gone through the same steps as sf, but still have the same problem.

    My set up is a little different:
    Visual Studio 2008 (been on VS 2008 since 2008 :wink:)
    .NET 2.0.50727.5420
    Win 7 x64
    Profiler 7.4

    Has there been any progress on resolving this?
  • James BJames B Posts: 1,124 Silver 4
    Josh- If you don't have the relevant windows update, you may well be experiencing a different issue. There's a whole host of potential causes for an application crashing. Assuming you've checked over all the options here it's likely to be an application-specific problem and we'd really need some sort of reproduction here to investigate further.
    Systems Software Engineer

    Redgate Software

  • I have the same problem in a public constructor with a generic type

    Top of Stack Trace looks like this
    [InvalidProgramException: Common Language Runtime detected an invalid program.]
    Aspidistra.Ecommerce.CircuitBreaker`1..ctor() in c:\Builds\23\Shopfront\Shopfront Framework\src\Shopfront\Source\ECommerce\Source\Aspidistra.Ecommerce\CircuitBreaker\CircuitBreaker.cs:40 Aspidistra.Ecommerce.Sage1000.CalculatingCachedPricingScheme.GetData(String[] stockCodes, String accountCode, ISession session, IAccountCustomer& info, SortedDictionary`2& stockItemData, SortedDictionary`2& priceList, SortedDictionary`2& specialPriceList, SortedDictionary`2& discounts, SortedDictionary`2& priceListDiscounts) +252



    Code Looks like this
    public class CircuitBreaker<T>
        {
            private static Dictionary<Type, ExternalResourceStatus> resources;
            private static ILog log = LogManager.GetLogger("Aspidistra.Ecommerce.CircuitBreaker");
    
            static CircuitBreaker()
            {
                resources = new Dictionary<Type, ExternalResourceStatus>();
            }
    
            private int maxConsecutiveFailures = 5;
            private TimeSpan lockDuration = TimeSpan.FromMinutes(1);
    
            public CircuitBreaker()
            {
                lock (resources)
                {
                    if (!resources.ContainsKey(typeof(T)))
                    {
                        resources.Add(typeof(T), new ExternalResourceStatus());
    
                        log.DebugFormat("Circuit breaker started tracking '{0}'.", typeof(T));
                    }
                }
            }
    
    etc
    
    }
    
  • Vs 2010
    .Net 3.5 - Cannot switch to 4.0 yet because of various libraries

    Problem exists if IIS or WEb Dev Server used.

    Really need to sort this out as I need to profile this app :(
  • sfsf Posts: 16 Bronze 2
    Hi pdorey,

    Thank you very much!

    Thanks to your code snippet I have been able to reproduce my issue.

    The tiny VS2010 project to be downloaded here: https://www.dropbox.com/s/6hj5h49zap6why7/TestProfilerCrash.zip exhibits exactly what I am facing with my main big project I cannot share:

    1) Start profiling the application
    2) Click [crash] button

    3a) If KB2742596 is installed the application will crash 100% of the time with ANTS 4 and 5

    3b) if KB2742596 is NOT installed, everything is fine

    James: hopefully you now have something reproducible and could start looking at the issue and fix it.

    Thanks in advance,

    Best regards,

    Sylvain
  • Sorry I've missed the previous updates on this, but I'll grab the repro now and test it out, thanks guys!

    *EDIT*

    - I do get the crash; but I don't have the relevant KB installed (probably as I'm on Windows 8) but either way we can hopefully work out the trigger.
    Systems Software Engineer

    Redgate Software

  • The full list of KB's relating to the patches are here - this may explain why some users don't have the one originally listed?

    pdorey- I notice in that same page a potential workaround for the original vulnerability the KB resolves when the problem relates to web-applications. May be worth you checking over that to see if it helps? Obviously it won't make any difference with the winforms version.
    Systems Software Engineer

    Redgate Software

  • James BJames B Posts: 1,124 Silver 4
    I've logged an internal bug ref. PP-3010 relating to this issue. Confirmed that removing the 3 updates listed for Windows 8 on the KB page stops the crash occurring.
    Systems Software Engineer

    Redgate Software

  • sfsf Posts: 16 Bronze 2
    Hi James,

    Just wondering whether you made some progress during those last 2 weeks.

    Thanks.
  • James BJames B Posts: 1,124 Silver 4
    The team have taken a look at it, and it's currently slated to be fixed in 8.1. It's too complex to be resolved in the initial release of 8.0 (due in the next couple of weeks) as that hit code-freeze recently for final bug-checking and documentation etc.
    After 8.0 there'll be an 8.1 to tackle anything that comes up from wider usage of the initial release, and this issue is to be looked at then.
    Systems Software Engineer

    Redgate Software

  • sfsf Posts: 16 Bronze 2
    Hello James,

    Thank you for the update. Of course I think you understand that this does not exactly solve my issue :wink:

    What are the short and long term solutions that could work for me?

    1) Short term: should I ask my team to remove all updates back to a working state and refuse any new until 8.1 is out?
    Or do you have a workaround? Such as a way to rewrite code, a patch or something?

    2) Long term: I think I understand that my only option will be to purchase licenses for 8.1, am I right? Or are you planning to update previous versions too?
  • James BJames B Posts: 1,124 Silver 4
    I'd say in the interim you'd need to remove the updates. I spent a while trying to work out if you could change something specific in your code to get around it but no luck (or just don't use line-level timing of course, it was only that mode that seemed to trigger it).

    It's very unlikely that any change to the profiler would be made in previous versions, so you'd need to update to version 8, yes.
    Systems Software Engineer

    Redgate Software

  • sfsf Posts: 16 Bronze 2
    Hi James,

    I noticed you released ANTS 8.0, congratulation!

    Could you let me know the road-map for 8.1? I would like to know when you plan to release it and whether it will contain a fix for our issue.

    Thank you.
  • Hi,
    Currently this issue is indeed slated to be fixed in 8.1 - I don't have a precise lead time on 8.1 but it's in the order of a few weeks rather than a few months.
    Unless anything disasterous happens, I'd hope this is indeed fixed soon.
    Systems Software Engineer

    Redgate Software

  • Any update on the timeline for fixing this? I desperately need line-level timings (and it's not an option for me to remove Windows updates). Thanks.
  • James BJames B Posts: 1,124 Silver 4
    I'm afraid we're still investigating precisely how to fix this in the tool - the IL that gets rewritten apparently doesn't look in any way "wrong" but investigations are ongoing.

    A little more information was discovered today though - it seems the problem can be triggered by something as simple as an empty try/catch block in the constructor for a generic. Other causes are using, lock or foreach statements.

    Another workaround asides from turning off line-level may be to move the constructor code into it's own method, and call this from within the constructor. It seems in some scenarios that is enough to stop the problem happening.
    Systems Software Engineer

    Redgate Software

  • sfsf Posts: 16 Bronze 2
    Hi there,

    I am sorry to insist, but: when do you plan to release something that fixes this bug?

    Thank you in advance.

    Regards.
  • James BJames B Posts: 1,124 Silver 4
    Have you updated to the latest build via Help > Check for Updates? The specific scenario we reproduced should be fixed in the latest version.

    If you're still seeing it happen then you're probably running into something slightly different and we'd need a code-sample to investigate.
    Systems Software Engineer

    Redgate Software

  • sfsf Posts: 16 Bronze 2
    Hi James,

    Thank you, your latest build seems to be robust against this issue, this is good!

    Thanks a lot.
  • James BJames B Posts: 1,124 Silver 4
    Glad to hear that's helping!
    Systems Software Engineer

    Redgate Software

  • sfsf Posts: 16 Bronze 2
    Hi James,

    I spent some time evaluating your latest release (8.2).

    While it doesn't crash anymore with our code and all latest .Net updates, we are unfortunately not going to upgrade from 4/5 to 8.2.

    The reason is that is it incredibly slow to operate: while the performance decrease of the application under test seems to be slightly better than with 4/5, the 8.2 release is almost unusable: it takes ages to expand one line, or even to get the first method tree after a range has been selected.

    And overall the Method Tree UI seems to be so "asynchronous" that its hard to understand what's happening: for instance: I select a range and wait for the tree to display.
    Then I select another range: I can see that something is happening since CPU usage goes up, but there is no visual feedback on the tree. So I am confused about which range this current tree corresponds to. After some time, the tree is suddenly refreshed. Needless to say that if I am not patient enough and select another range before refreshing, or try to expand a line, or select another thread, things get worse and worse.

    Our computers are not super fast, ok, but we never had these kind of issues with 4 or 5: the UI is responsive and the time for getting the whole tree after selecting a range is reasonable.

    I have to say I am disappointed by this: I was expecting some great improvements when comparing 8 to 4, but it's not the case: the usability is so bad that I don't want to spend more time exploring potentially new great features.

    I am sorry for this bad comment. But we are not going to upgrade our versions as long as global performances of the UI are not improved.

    This means that in order to solve the crash issue, I spent some time rewriting all code parts that are crashing version 4/5, based on your May 16 comment, so thanks a lot for providing these insight.

    Again, sorry for this bad comment. We all love ANTS Profiler concept and reliability but I don't know what happened in between version 5 and 8 to render it unusable on our machines... Hopefully you are aware of this issue and will fix it at some points.

    Best regards.
Sign In or Register to comment.