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 7179479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:08:55+00:00 2026-05-28T17:08:55+00:00

I have one user reporting this exception. My research here and elsewhere suggests this

  • 0

I have one user reporting this exception. My research here and elsewhere suggests this is a static contructor error. The class concerned contains a number of static fields that are initialized. I assume it is one of these but I am not sure how to find it. The suggestion seems to be to include a try/catch block in the static contructor. As written there is no explicit static contructor.

I am thinking that I should write an explicit static constructor, move the initialization of the static fields into it and wrap them in the try/catch block. I know I could try this but the error does not arise for me and I would like to send a modded executable to the user to try. My application does log the errors so I should get a log from him if the exception is caught in the static constructor.

The relevant (I hope) part of the class is here (it is not actually my code but I can mod it as required):

 [Serializable]
    public class PText : PNode, ISerializable {

    //comments elided by edit for brevity
        #region Fields

        public const int PROPERTY_CODE_FONT = 1 << 18;
        public const int PROPERTY_CODE_TEXT = 1 << 17;
        public static Font DEFAULT_FONT = new Font("Arial", 12);
        protected static readonly object PROPERTY_KEY_FONT = new object();
        protected static readonly object PROPERTY_KEY_TEXT = new object(); 
        private static Graphics GRAPHICS = Graphics.FromImage(new Bitmap(1, 1));

        [NonSerialized]
        private Color brushColor;
        private bool constrainHeightToTextHeight = true;
        private bool constrainWidthToTextWidth = true;
        private Font font;

        [NonSerialized]
        private Color penColor;

        [NonSerialized]
        private StringFormat stringFormat = new StringFormat();
        private String text;

        [NonSerialized]
        private Brush textBrush;

        #endregion Fields

        #region Constructors
        public PText() {
            textBrush = Brushes.Black;
        }

        public PText(String aText)
            : this() {
            Text = aText;
        }

        protected PText(SerializationInfo info, StreamingContext context)
            : base(info, context) {
            textBrush = PUtil.ReadBrush(info, "textbrush");
            TextAlignment = (StringAlignment)info.GetValue("alignment", typeof(int));
        }

        #endregion Constructors
.......
  • 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-05-28T17:08:55+00:00Added an answer on May 28, 2026 at 5:08 pm

    To answer your question, the idea you had is good. Put a try/catch around the possible lines that are throwing, and then log the error before it becomes a TypeInitializationException.

    Alternatively, change to use Lazy – this will change the exception to be where it is first accessed. This may or may not be useful for you, but it has helped me debug similar issues.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one user who gets an error message when he closes his browser.
it's possible to have one entity object (class, e.g. User) for more entity models
I have a class User with one field called birthDate which is a java.sql.Date
I have created one user named tuser with create database rights in SQL server
I have 2 tables - one storing user information (id, username, password) and the
I have WPF Application where I have One main form and other user controls
I have 2 collections, one of available features and one of user features. I
I have long since forgotten the password for the root user on one of
I have a function that, when the user selects one or more items, it
I have a selectbox with three options. When a user selects one of the

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.