C# Static Contstructor Not Called When Referencing Static Object

by dcurtis 1/16/2010 12:40:00 PM
I had a situation today where I had a static constructor that was never getting initialized and setting some of the default values.  As a result, other content within my code suffered from the same issue.  I searched in vain for a solution and couldn't find anything until I finally revised my search terms.  It turns out that Visual Studio was firing the constructor the first time it would run, but then it encountered an error and would never fire again.  I found a reference in the .Net Development Center that mentioned shutting down the development web server; however, I had already tried that and it didn't do anything for me.  What did work, though, was changing something within the class as the author of that post said (adding a comment, inserting a space, deleting something) and then recompiling and I was finally able to get the static constructor to fire so I could continue to debug the code.  

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Visual Studio 2008 | C#

Powered by BlogEngine.NET
Theme by Mads Kristensen

About the author

Derek Curtis Derek Curtis
President, Plaid Pony Technology Solutions LLC

E-mail me Send mail


<<  June 2018  >>

View posts in large calendar


    Recent comments



    The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

    © Copyright 2018

    Sign in