DateTime issue - the value is available outside the object, but not inside

This is a very unpleasant and bizarre problem, and I would appreciate any advice on how to fix it.

I have an object with a private variable:

private DateTime _maturityDate = DateTime.MaxValue; 

It has the corresponding property:

 public DateTime MaturityDate { get; set; } 

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

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

This sets the value correctly:

(I cannot send images, so you have to trust me that it is)

However - and this is a really strange problem - when you insert an INSIDE object, this property is set. Even trying to display it in the nearest window or using console.writeline, you will get the following:

? _maturityDate {System.DateTime} Date: The expression cannot be evaluated because the thread stopped at the point where garbage collection is not possible, possibly because the code is optimized.

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

I am using the .NET Framework 3.5 SP1 in Visual Studio 2008 version 9.0.21022.8, if necessary.

I'm at a dead end. The object is quite complex, so I hesitate to publish everything, but if anyone has ideas, I will publish the corresponding code.

Thank you so much in advance!

+4
source share
2 answers

This is not a bug in the code. What happens here, the C # debugger tries to evaluate the expression and returns the return value CORDBG_E_ILLEGAL_AT_GC_UNSAFE_POINT or CORDBG_E_ILLEGAL_IN_OPTIMIZED_CODE from the CLR. These are error codes that indicate that it is impossible to evaluate the expression in the current context and has little to do with the actual user code.

Mike Stoll has a good breakdown of these messages and why they occur, which may be worth reading.

Unfortunately, although little can be done to get around this problem. If the problem is not that you are optimizing debugging, then eliminating the optimizations will fix the problem.

+2
source

Comment:

Based on what you posted above,

public DateTime MaturityDate {get; set; }

is autoproperty ( http://msdn.microsoft.com/en-us/library/bb384054.aspx ) and should not have any connection to _maturityDate.

Did I miss something?

0
source

All Articles