Fatal error: Exception code=C0000005 and VFP9

grijalbo used Ask the Experts™
Hello experts

I have an application that works fine (was developed in VFP9).  However, once in a while, when I install my application in a new customer/computer, I have the message:

Fatal error: Exception code=C0000005

Right at the beginning of the application (it doesn't even show the foxpro screen or anything else, just the message and then the program aborts).  I checked again virus, chkdsk, etc. and nothing works.

Sometimes it occurs in XP, sometimes  W7.  Some of those machines are brand new.  The same disk that I use to install my app in one machine that works fine, is being used in another machine that occasionally doesn't work.

Thanks in advance.

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
CaptainCyrilFounder, Software Engineer, Data Scientist

This has nothing to do with the computer. It might be a printer driver, ban index, incompatible code page or system language regional setting.

Try to put breakpoints and find out where exactly it is doing so.

Completely reindexing the files might help. Deleting corrupted foxuser.dbf and foxuser.fpt might also help. Back them up first.
I  with captaincyril, delete the fox user fie.

Other thing is to check the error log, vfp9err.log, which should be next to the DLLs, normally c:\Program Files\Common Files\microsoft shared\VFP

That may give you an error line, you can then trap that in a TRY / CATCH block and trace the error.
CaptainCyrilFounder, Software Engineer, Data Scientist
From all the applications that I have built, I found workarounds or fixed the problem with the following:

Install a service pack
Delete foxuser
Complete delete index and reindex each table
Installed a new printer driver
Changed the regional settings or code page to match system.

There are hundreds of possible problems if you search for C5 error on Google. We need to narrow down the search in order to help you.
Exploring SharePoint 2016

Explore SharePoint 2016, the web-based, collaborative platform that integrates with Microsoft Office to provide intranets, secure document management, and collaboration so you can develop your online and offline capabilities.

This behavior occurs on computers where are some components (DLLs) which do not match your VFP version. Look e.g. into folder C:\Program Files (x86)\Common Files\microsoft shared\VFP or even in C:\Windows\System32 etc.

It should not happen if you place all necessary DLLs into the app folder. The list of necessary files is here: http://fox.wikis.com/wc.dll?Wiki~VFP9RuntimeFiles~VFP
Olaf DoschkeSoftware Developer

If you provide your foxuser.dbf with the setup, because it contains some settings, it could easily cause the C5 errors, that's true. Either provide no foxuser.dbf and let the exe create one, or even include a config.fpw into compilation, which prevents creation of a foxuser.dbf via the config.fpw line RESOURCE=OFF

Especially when installing to program files, no write access is given and no foxuser.dbf can be created. That would not cause a C5 error, though.

What runtime files do you include in your setup?
As you mentioned this happening on brand new computers, you may rely on something installed with other software, which you would perhaps simply need to add to your setup.

Bye, Olaf.


Thanks for your answers:

To   CaptainCyril : your sugestion can not be used ("...reindexing the files might help. Deleting corrupted foxuser.dbf and foxuser.fpt....."). My app doesn't work with DBF tables, only with SQL (Express 2008) tables and I already install my app without Foxuser.* files.

To   Gary2Seven: "......check the error log, vfp9err.log,.........", regretfully, only shows the error, plus date, hour and nothing else. Don't even the name of the program that made the  first call. Not big help on this file. In regards to TRY and CATCH, I am trying to use that, but so far I can not "catch" that elusive error.

To  pcelba: ".....place all necessary DLLs into the app folder.............", Already try that and it didn't work.

Still to try:  replace printer driver , and find out if my app is expecting some "hidden" DLL from Foxpro  ( GDIPLUS,...., etc.). I would say that out of 30 installations, one of them has de C5 error, the rest of computers works fine (keep in mind that it is same software without changes). I "googled" C5 error and there are many possible causes (perhaps hundreds), I can not try all of the possible solutions.  The only possible solution is keep trying with TRY and CATCH. I was thinking that perhaps there is a more efficient way to solve this problem.
CaptainCyrilFounder, Software Engineer, Data Scientist

Can you put breakpoints or milestones?

For example: Connecting to database, Writing log, deleting temp files, ...
This way you can know what the software is doing to find the source of the problem. So instead of hundreds of problems you can narrow it down to 2 or 3.

In my last C5 error, I managed to know that it was an EditBox with Chinese characters on an English-US OS language that caused the application to crash.
If the C5 error rises right at the beginning then it cannot be caused by the app itself or by printer driver etc.

VFP has no hidden DLLS but you have to inspect your computer for all VFP related DLLs occurence. E.g. old version of VFP9R.DLL in Windows\System32\ folder causes C5 error.
The list of DLLs used by VFP is in my previous post. It does not contain file sizes but you may post file sizes and versions of DLLs from your PC.

Also, you could install the VFP run-time from this link http://archive.msdn.microsoft.com/FoxPro/Release/ProjectReleases.aspx?ReleaseId=125. I am just not sure if it deletes possible occurences of the old versions residing on PC. Probably not. You'll get the correct DLL versions by installing the above run-time at least.
Olaf DoschkeSoftware Developer

Again: What runtime fiels DO you include in your setup?
If you don't include the C runtime you depend on whatever is already on the system.
If you don't include the gdiplus.dll you depend on what is already on the system.
And that can crash.

You are explicitly allowed and it is explicitly recommended you install not only the core VFP runtime vfp9r.dll, but also all the related DLLs.

Pavel has pointed you to a runtime installer suite of which you can pick the appropriate one having the right SP revision. Just see what Version() says, the last number is what is meant as the Revision in the link pavel gave you.

As you don't install foxuser.dbf, it's recommendable you suppress it's generation, too. Write a textfile with RESOURCE=OFF as it's only line, name it config.fpw, include it to the project in text or other files and right click on it to untick the exclude context menu item. If that is unticked the file is not excluded from compilation into the final EXE. If you then build you have an exe that won't try to create a foxuser.dbf file and if that is by chance the reason you get your c5 error in some cases, that would resolve it.

In the normal case the OS restricts writing the foxuser.dbf right besides the EXE, if you install into program files, but it is instead written into a user directory. If that is also suppressed by group policies eg, then that could cause a c5. That would also explain, why it doesn't happen always and only at some clients.

Bye, Olaf.

PS: Yes, there are many reasons for a C5, but very few for a C5 right at the start, even before any of your code lines run. Put a messagebox as your fist line and see if that executes. If the C5 error is before, the only reasons are runtime mismatch or a problem in foxuser.dbf usage or creation. There is nothing else done, before your code starts, than loading the runtime(s) and creating/using foxuser.dbf.


Thank you again for answers

I will try your suggestions.  It will take some time before I have the answer, I can not reproduce the problem in my computers, and access to my customers' computers is hard (they are in another countries, the only way is remote desktop), As soon as I have something I will let you know.
Olaf DoschkeSoftware Developer
Take your time.

The things you can do without knowing the result of the "Messagebox-Test":

1. create a config.fpw file with RESOURCE=OFF, add it to the project and include it in the compilation into the EXE. As you don't use foxuser.dbf, that's a reasonable thing to do and also removes one possible reason for an error.
2. Check the Runtime files version(s) of the DLLs you bundle in your setup with the Version() your IDE shows. It's verifyable by the version the Windows Explorer shows in file properties of vfp9r.dll, vfp9t.dll (eventually) and vfp9renu.dll, too, which must match what VERSION() shows.

This is an overview over all the files of which you might have forgotten the one or other: http://fox.wikis.com/wc.dll?Wiki~VFP9RuntimeFiles

Also: Checking VERSION() at runtime you see what runtime version is really loaded and _VFP.Servername will give you the main runtime DLL name used. But that again is a step to take at the client installation.

I'm sure you reveal something.

Bye, Olaf.
CaptainCyrilFounder, Software Engineer, Data Scientist

To the moderators. The C5 error is not something specific or can be easily solved. I second pcelba's suggestions to split points because these are the most common solutions to the C5 error.

Every discussion about C000005 error in FoxPro is worth to read as this unhandled exception can have thousands of possible reasons... and this knows every Visual FoxPro developer.

All what was written in our posts is true and could help others to understand the foggy C000005 reasons. Unfortunately, grijalbo stopped responding and did not post the final resolution.

But are you sure just this final resolution would tell others what should they fix in their own applications to avoid C0000005 error? Not at all but others can try what we have recommended during the three days in the discussion.

So we have condensed our decades accumulated knowledge into three days and you now simply say "delete everything"...?

OTOH, it could also seem we are just points collectors... So in such case select the post hppps:a#41696557 as the answer please but don't delete this question.

CaptainCyrilFounder, Software Engineer, Data Scientist

I second pcelba.

Keep the question. Don't give us points if that satisfies you eenookami. Your words should be directed to Microsoft for their vague handling of C000005 errors.

Dear all Fox Users
my app appear to those error c5

i try to trap step by step, error appear because  one of my table missing field in my grid.

in my programming error appear when the routing program "thisform.grid1.refresh"

i am no need  reinstall my VFP9, DLL or anything

Matur nuwun
We cannot help as we don't know your code, your VFP version, your conditions. Just read all the posts here and try to implement all hints.

MSDN Archive never more offers VFP Runtime download so here is the working link for VFP runtime downloads:  http://www.foxpert.com/download/runtime.html
Olaf DoschkeSoftware Developer

Just to add once more: C5 is just a headline. It categorizes this as an error the VFP runtime is not able to handle itself, no VFP error that has a specific error number, no specific reason for it. So don't think when you find someone stating he found the reason, the same solution applies to you. You get a good hint in vfp9err.log stating the line which last executed. That can be a hint about a corrupt file like dbf or frx, but the error rarely is that line itself, it just has the bad luck of acting on something broken. Could be using a method of an object still in memory, though it should have released 100 lines of code back in some other class that ran before.

C5 error even is a C++ concept, not a VFP one, it's access violation accessing invalid memory buffer, for any reason, eg a pointer in a dbf pointing to a non-existing offset of an FPT file. A memory address an object instance once was existing - anything.


You can't suppress this or catch it in a try..catch. Some reasons are the VFP runtime not expecting certain corruption in files, no pointers to non-existing FPT file portions, for example. It's just a made up example anyway, but all you can do is verify what's been acted with the line of code, so this is just a starting point for an investigation of the involved PRG or SCX or VCX, involved open tables and reports and much more code and files up to the point of everything that ran previously and led to the situation. Even simpler errors the ones having a native VFP error number and a distinct simple explanation often need more than fixing that single line of code.

If you never debugged code, a C5 is a good reason to start. Once you know where it happens reproducible set a breakpoint for example in some click leading there and go through what happens step by step. And don't wait for the C5 to happen, the seed of the error is typically planted earlier, it might even already exist when you start into single-step debugging. It can be a buffered record that is just committed when a dbf is closed because another one is opened, and then you should not only suspect the newly opened dbf. So this really needs experience of debugging in general, which you never get, if this is the first hard error challenging your bug fixing.

Know your FoxPro, use coverage logging to see much more than just the last few lines of code executing up to the C5 error incident. Have a health check of all files involved, maybe even the whole dbf, your project and also foxuser.dbf resource files. Even the intelliisense  foxcode.dbf once caused a reproducible error. And now please, don't check your foxcode.dbf, just because I mentioned it last.

You examine such things with detective skills, switch components, even the whole computer, to see if anything on that client and driver or OS issue catches you.

Bye, Olaf.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial