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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:19:43+00:00 2026-05-16T11:19:43+00:00

I am writing tests to test Infopath Forms to open in Form Control, my

  • 0

I am writing tests to test Infopath Forms to open in Form Control, my test method is as

[TestMethod]
public void Validate_OpenInfopathInFormControl()
{
    Helper.OpenForm();
    //Other Code    
}

I have written Helper class as

public class Helper
{  
    public static void OpenForm()
    {
        //Code to Open Form
    }
}

But everytime I execute this code, this gives me:

Test method
InfoPathTest.TestAPI.Validate_OpenInfopathInFormControl
threw exception:
System.TypeInitializationException:
The type initializer for
‘InfoPathTest.Helpers.Helper’ threw an
exception. —>
System.NullReferenceException: Object
reference not set to an instance of an
object..

When I try to debug, it fails when Helper class needs to be initialized. This is really eating my head, is there any solution for this?

Here is the complete helper class:

namespace InfoPathTest.Helpers
{
    public class Helper
    {
    //This is the form i need to OPEN
        private static MainForm f =  new MainForm();
        private static bool _isOpen = false;

        public static bool isOpen
        {
            set { _isOpen = value; }
            get { return _isOpen; }
        }

        public static void OpenForm()
        {
            try
            {
                f.Show();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            _isOpen = true;

        }

        public static void CloseForm()
        {
            f.Hide();
        }
    }
}
  • 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-16T11:19:44+00:00Added an answer on May 16, 2026 at 11:19 am

    Your test calls Helper.OpenForm() and as you have no static constructor, the only thing I can see that would cause the exception to be thrown is:

    private static MainForm f =  new MainForm();
    

    Therefore something in the constructor for MainForm is likely throwing an exception. Put a breakpoint on the first line of the constructor for MainForm and step through until you see where the exception is thrown.

    Alternatively you might find it easier to determine what the problem is, at least initially, by writing a new test you can step through that calls new MainForm() directly:

    [TestMethod]
    public void Validate_OpenInfopathInFormControl()
    {
        var form = new MainForm();
    }
    

    Put a breakpoint on the only line of the test and step into the constructor to determine why it’s throwing a NullReferenceException.

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

Sidebar

Related Questions

I'm writing a test for a file parser class. The parse method receives a
I'm writing a unit test for a method that packs boolean values into a
Does anyone have some good hints for writing test code for database-backend development where
Writing some test scripts in IronPython, I want to verify whether a window is
I am writing a test program to copy some file in Application data folder
I am writing an unit test for a mvc web application that checks if
I am writing a few test cases that depend on the database being available,
I am writing a small app which I need to test with utf-8 characters
I am writing a silly little app in C++ to test one of my
I'm writing tests for my project, and after the Unit Tests, I'm now writing

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.