Home Page
RABiD BUNNY FEVER
K.T.K

  • June 17, 2019, 07:57:34 PM *
  • Welcome, Guest
Please login or register.

Login with username, password and session length
Advanced search  

News:

Official site launch very soon, hurrah!


Author Topic: CSharp error failure  (Read 3098 times)

Dakusan

  • Programmer Person
  • Administrator
  • Hero Member
  • *****
  • Posts: 522
    • View Profile
    • Dakusan's Domain
CSharp error failure
« on: November 18, 2010, 09:50:37 PM »

Original post for CSharp error failure can be found at https://www.castledragmire.com/Posts/CSharp_error_failure.
Originally posted on: 11/19/10

I was running into a rather nasty .NET crash today in C# for a rather large project that I have been continuing development for on a handheld device that runs Windows CE6. When I was calling a callback function pointer (called a Delegate in .NET land) from a module, I was getting a TypeLoadException error with no further information. I started out making the incorrect assumption that I was doing something wrong with Delegates, as C# is not exactly my primary language ;-). The symptoms were pointing to the delegate call being the problem because the program was crashing during the delegate call itself, as the code reached the call, and did not make it into the callback function. After doing the normal debugging-thing, I found out the program crashed in the same manner every time the specific callback function was called and before it started executing, even if it was called in a normal fashion from the same class.

After further poking around, I realized that there was one line of code in the function that if included in any function, would cause the program to fail out on calling said function. Basically, resources were somehow missing from the compilation and there were no warnings anywhere telling me this. If I tried to access said resource normally, I was getting an easily traceable MissingManifestResourceException error. However, the weird situation was happening because I had the missing resource being accessed from a static member in another class. So here is some example code that was causing the problem:


public class ClassA
{
   public void PlaySuccess()
   {
      //Execution DOES NOT reach here
      Sound.Play(Sound.Success);
   }
}

public class Sound
{
   public static byte[] Success=MyResource.Success; //This resource is somehow missing from the executable
   public static byte[] Failure=MyResource.Failure;
   public static void Play(byte[] TheSound) { sndPlaySound(TheSound, SND_ASYNC|SND_MEMORY); }
}

ClassA Foo=new ClassA();
//Execution reaches here
Foo.PlaySuccess();

Oh well, at least it wasn’t an array overrun, those are fun to track down :-).

Logged