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 am writing tests in testNG. Each test method shares a number of common
I'm writing WatiN tests to test an Ajax web application and have come across
I'm writing unit tests using Test::More and Test::Output. I use Test::More to validate the
I'm having some difficulty writing some Unit Tests to test a custom ModelBinder that
Possible Duplicate: Choose order to execute JUnit tests I am writing a JUnit test.
I often find that in writing tests for a method I want to throw
I am currently writing Unit Tests to test the connection between a client and
I'm writing some tests to test my sqllite database code. Can someone here explain
I am writing unit tests in GHUnit test framework. I have a NSMutableDictionary detailsDict
I'm writing unit tests to test whether data typed in the GUI is validated

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.