Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8100607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:46:25+00:00 2026-06-05T22:46:25+00:00

I had a class: public class Constant { public static string ConnString = ConfigurationManager.ConnectionStrings[ConnString].ConnectionString;

  • 0

I had a class:

public class Constant
{

    public static string ConnString = ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString;
}

which would throw exception on LIVE: Type initialize failed for Constant ctor

If I change the class to:

public class Constant
{
    public static string ConnString
    {
        get
        {
            return ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString;
        }
    }
}

it works. I wasted 2 hours behind this but I still don’t know why would this happen. Any ideas?

Note: The 1st class used to work on DEV environment but not on LIVE. The 2nd class works on DEV and also on Production.

I am using VS2010 on production and Asp.Net 4.0 Website project.

I am totally amazed by this inconsistency to say the least!

Edit: This class was in App_Code folder.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T22:46:27+00:00Added an answer on June 5, 2026 at 10:46 pm

    I think the main difference is:

    • The first one is computed when Constant class is initialized
    • The second is evaluated first time ConnString property is accessed (so probably initialization phase is complete)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I had a class like this public class Child { public string ToXml() {
If I had a Java generic class of... public class EntityStuff<C> extends AbstractPropertyStuff<C> implements
The following program will not compile: class Program { static void Main(string[] args) {
I had a class that had lots of methods: public class MyClass { public
Assumptions Suppose I have a class with a property: class ClassWithProperty { public string
I had create a class named ChannelObj that contains values like this public class
If I had a class defined with this attributes public class GestionesDataSet { public
In java <1.5, constants would be implemented like this public class MyClass { public
If I had generic class: public class GenericTest<T> : IGenericTest {...} and I had
Say I had a class: public class Post { public int PostId { get;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.