# Thursday, July 30, 2009

We have an application at work that pulls images from a proprietary binary file and saves them to a local directory. The directory path and filename on the local machine are built on the fly based on client information. The application went through a full round of testing and passed all cases. However, when we moved the application to production and ran it against live data we ran into the following error:

System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+

We spent most of the day trying to track down the error, but nothing I found on the Internet gave a clue. First we thought that perhaps we were getting image data in a format that we didn't expect (i.e. loading JPEG data and saving it as a TIFF file), but that wasn't it. Finally, we tried writing the raw data out to disk using a FileStream instead of Image.Save(). This did not solve the problem, but it produced a different Exception that pointed us in the right direction. The new Exception stated something similar to the message below:

"Could not find part of the path 'C:\TEMP\2345\111299\Bin1\Slot3\Company.Bin1\Slot3.PartNumber_1.TIFF'"

The clue came in the last part of the message. The path format was supposed to be:

<Root_Dir><CompanyID><FranchiseID><StorageSection><FileName>.TIFF

where...

<FileName> = <CompanyID>.<StorageSection>.<PartNumber>.TIFF

Looking closely we discovered that our path was including a <StorageSection> that had a backslash in the name (i.e. "Bin1\Slot3"). Therefore, when .NET tried to create a file with the name "Company.Bin1\Slot3.PartNumber_1.TIFF" an Exception was thrown.

A simple one line change to our application fixed the issue by cleaning up the file name before attempting to save the file:

// Ensure that we have a safe filename
strFileNamePrefix = Regex.Replace(strFileNamePrefix, @"[\\/\?\:\<\>\|\*]", "_");

Hopefully the above will help you save more time than it took us to figure this out.

 

posted on Thursday, July 30, 2009 8:35:07 PM (Central Daylight Time, UTC-05:00)  #    Comments [0]
# Monday, July 06, 2009
“What kind of kingdom is this? The last are first they say. What kind of kingdom is this? Where servants are called great.” -- Jill Moore

Those words are from a Jill Moore song that I am really beginning to like quite a bit. We were listening to it in the van yesterday and I found it going through my thoughts as I woke up this morning.

What kind of Kingdom is this?

The Bible says that the last shall be first and the first shall be last, that the weak shall be strong and the meek shall inherit the Earth. How can this be? It is a concept that we cannot even comprehend in our minds though we try will all our might, which is to say in our flesh.

Cain tried in this way. He brought “an offering to the Lord.” His brother Abel, for his part, brought “the firstlings of his flock and their fat portions.” What is the difference here? Cain brought God something. Abel brought God the best that he had. What were the two sacrifices? One might say “Cain brought the fruit of the ground, while Abel brought the firstlings of his flocks.” That is true, but that is according to this Earthly kingdom. What did each bring in accordance with God’s kingdom?

Cain brought a portion of his heart; a portion of his devotion. What ever it was it was not pleasing to God. Abel brought his whole heart; his entire devotion. He sacrificed the very portions of his flock that stood the best chance of making him rich. The firstlings. The best. He sacrificed the portions of his flock that stood the best chance of making his stomach happy; the fat portions. He took the very best of what he had and he brought that to God. This was an outward sign of an inward reality that God had his whole heart.

You see, God’s kingdom is not like this Earthly kingdom. God’s kingdom is spiritual; the kingdom of this world is physical. The Bible says “But we are all as an unclean thing, and all our righteousnesses are as filthy rags; and we all do fade as a leaf; and our iniquities, like the wind, have taken us away.” Isaiah 64:6.

Many have tried, like Cain, in their own strength to gain righteousness before God. They try, often with all their might, to be good. They desire with all their strength to be holy. However, this one thing they have held back from God, that is, their heart. The one thing that is required to true acceptance from God is the one thing they are not willing to let go of.

It’s a shame too, the heart is deceitfully wicked (Jeremiah 17:9); it’s not to be trusted.

posted on Monday, July 06, 2009 9:44:53 PM (Central Daylight Time, UTC-05:00)  #    Comments [0]