System.NullReferenceException on a CString

G

Guest

Project built using /CLR, but code is old and has not been converted
specifically to "managed" (__gc or __value).

Everything seemed to work great, until I got the following error.

I have a class, let's call it CMyLegacyClass, that has some CString (NOT
CString*) member variables.

Problem is, when the destructor is called (which actually has an empty
body), it automatically calls the destructors for my embedded CStrings. When
this happens, I get a "System.NullReferenceException".

How can this happen since I'm not using __gc, System::String, or CString*
(or any pointers for that matter)?


I even tried adding #pragma unmanaged to the top and #pragma managed to the
bottom of the .CPP and .H files.

Please advise, as this one has me stumped.

Thanks,
Klynt
 
G

Gary Chang[MSFT]

Hi Klynt,

I have tested some simple MFC programs with /clr compiler option, however I
could not repro the scenario you figured. Would you please give us a small
self-contain sample to repro this problem?

By the way, since you got the System.NullReferenceException in your class's
destructor function, I think you can take a try on inserting a
System::GC::Collect(); call in that destructor function...


Thanks!

Best regards,

Gary Chang
Microsoft Community Support
--------------------
Get Secure! ¡§C www.microsoft.com/security
Register to Access MSDN Managed Newsgroups!
http://support.microsoft.com/default.aspx?scid=/servicedesks/msdn/nospam.asp
&SD=msdn

This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top