"Common Language Runtime detected an invalid program." error

Code profiling for .NET developers.

"Common Language Runtime detected an invalid program." error

Postby SGayet » Thu Feb 07, 2013 1:06 pm

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,
SGayet
 
Posts: 1
Joined: Thu Feb 07, 2013 12:53 pm

Postby james.billings » Fri Feb 08, 2013 2:53 pm

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 support@red-gate.com quoting F0069401 in the subject.
james.billings
 
Posts: 1146
Joined: Wed Jun 16, 2010 11:10 am
Location: My desk.

same issue here, never happen before on same similar code

Postby sf » Thu Feb 14, 2013 1:16 pm

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...
sf
 
Posts: 12
Joined: Thu Feb 14, 2013 1:03 pm

Postby james.billings » Thu Feb 14, 2013 1:22 pm

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.
james.billings
 
Posts: 1146
Joined: Wed Jun 16, 2010 11:10 am
Location: My desk.

Postby sf » Thu Feb 14, 2013 2:50 pm

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?
sf
 
Posts: 12
Joined: Thu Feb 14, 2013 1:03 pm

Postby james.billings » Thu Feb 14, 2013 2:57 pm

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...
james.billings
 
Posts: 1146
Joined: Wed Jun 16, 2010 11:10 am
Location: My desk.

Postby sf » Thu Feb 14, 2013 6:00 pm

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?
sf
 
Posts: 12
Joined: Thu Feb 14, 2013 1:03 pm

Postby sf » Mon Feb 18, 2013 11:37 am

Hi again,

Is Red Gate planning to address this issue?
sf
 
Posts: 12
Joined: Thu Feb 14, 2013 1:03 pm

Postby james.billings » Mon Feb 18, 2013 1:46 pm

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?
james.billings
 
Posts: 1146
Joined: Wed Jun 16, 2010 11:10 am
Location: My desk.

Postby sf » Tue Feb 19, 2013 1:43 pm

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.
sf
 
Posts: 12
Joined: Thu Feb 14, 2013 1:03 pm

Postby joshminnie » Wed Mar 06, 2013 5:39 pm

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?
joshminnie
 
Posts: 1
Joined: Wed Mar 06, 2013 5:30 pm

Postby james.billings » Wed Mar 13, 2013 6:48 pm

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.
james.billings
 
Posts: 1146
Joined: Wed Jun 16, 2010 11:10 am
Location: My desk.

Same Problem with Web App

Postby pdorey » Mon Mar 18, 2013 5:19 pm

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

Code: Select all
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

}
pdorey
 
Posts: 2
Joined: Mon Mar 18, 2013 5:12 pm

More Details

Postby pdorey » Mon Mar 18, 2013 5:31 pm

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 :(
pdorey
 
Posts: 2
Joined: Mon Mar 18, 2013 5:12 pm

Postby sf » Tue Mar 19, 2013 5:02 pm

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
sf
 
Posts: 12
Joined: Thu Feb 14, 2013 1:03 pm

Next

Return to ANTS Performance Profiler 7

Who is online

Users browsing this forum: No registered users and 0 guests