views:

59

answers:

1

This is a very frustrating and bizarre issue and I would appreciate any advice on how to resolve it.

I have an object with a private variable:

private DateTime _maturityDate = DateTime.MaxValue;

It has a corresponding property:

public DateTime MaturityDate { get; set; }

I have a method which updates the data in the database called UpdateInstrumentBase(). The property is set from a DateTimePicker control on a Windows form. It is set via code, not via data binding:

((Instrument)instrumentBS.DataSource).MaturityDate = dateTimePicker9.Value;

This correctly sets the value:

(I can't post images so you will have to trust me that it does)

However - and this is the truly bizarre problem - when you step INSIDE the object, this is what the property is set to. Even trying to output it in the immediate window or by using a console.writeline results in the following:

? _maturityDate {System.DateTime} Date: Cannot evaluate expression because a thread is stopped at a point where garbage collection is impossible, possibly because the code is optimized.

I've tried passing the date value in as a string, then converting to DateTime as a workaround but any access to ANY DateTime property or variable - not just this one - inside this object results in this error. I've searched high and low but I'm not even sure if this error message is relevant or useful.

I'm using .NET Framework 3.5 SP1 in Visual Studio 2008 version 9.0.21022.8 if that's relevant.

I'm stumped. The object is quite complex so I'm hesitant to post the entire thing, but if anyone has any ideas I will post the relevant code.

Huge and gracious thanks in advance!

+1  A: 

This is not a bug in your code. What's happening here is the C# debugger is attempting to evaluate an expression and is getting back a return value of CORDBG_E_ILLEGAL_AT_GC_UNSAFE_POINT or CORDBG_E_ILLEGAL_IN_OPTIMIZED_CODE from the CLR. These are error codes that indicate it's not possible to evaluate an expression in the current context and has little to do with the actual user code.

Mike Stall has a good breakdown on these messages and why they occurr that may be worth a read.

Unfortunately though there is little you can do to work around this problem. Unless the issue is you are debugging optimized, in which case turning off optimizations will fix the problem.

JaredPar
Aha. Now that I know that "funceval is evil", it seems clearer.
Matt Hocker
@Matt, funceval is not pure evil. It's like a well meaning friend who just inevitably screws up a situation over and over again ;)
JaredPar