469,928 Members | 1,861 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,928 developers. It's quick & easy.

System.NullReferenceException on a CString

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.


Nov 17 '05 #1
1 1121
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...

Best regards,

Gary Chang
Microsoft Community Support
Get Secure! C www.microsoft.com/security
Register to Access MSDN Managed Newsgroups!

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

Nov 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Terrence | last post: by
3 posts views Thread by Morten Overgaard | last post: by
15 posts views Thread by Yifan | last post: by
1 post views Thread by msnews.microsoft.com | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.