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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:30:43+00:00 2026-06-17T13:30:43+00:00

I am trying to use an dynamically generated XML file with Data Driven test.

  • 0

I am trying to use an dynamically generated XML file with Data Driven test. I am using Visual Studio 2010 and .NET 4.0 .

[TestMethod]
[DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", @"|DataDirectory|\StudentData.xml", "Student", DataAccessMethod.Sequential)]

This StudentData.xml file is being generated by code and I am not deploying this file. I have written the code for generating StudentData.xml file in TestInitialize() method, also the file is being saved at current working directory.

Whenever I am going to run the test method it is throwing error:

The unit test adapter failed to connect to the data source or to read the data. For more information on troubleshooting this error, see "Troubleshooting Data-Driven Unit Tests" (http://go.microsoft.com/fwlink/?LinkId=62412) in the MSDN Library.
Error details: Object reference not set to an instance of an object.

What I think is before creating the file, the framework is trying to access the file. So, How can I use this XML file with unit test? Also, can I use variable names in Attributes?

Thanks for your help

  • 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-17T13:30:45+00:00Added an answer on June 17, 2026 at 1:30 pm

    I didn’t gey any reply from last 17 hours. As it was important for me, so I tried to explore other possibilities.

    Finally I made it to work. Below is the simple solution (I am posting this because it might help other begineers like me, in future).

    I have just moved my XML file generation code to [ClassInitialize] method instead of TestInitialize() and it worked fine.

    Also, below is the order that methods will be run is:

    1.  Methods marked with the AssemblyInitializeAttribute.
    2.  Methods marked with the ClassInitializeAttribute.
    3.  Methods marked with the TestInitializeAttribute.
    4.  Methods marked with the TestMethodAttribute
    

    Check Here for more

    Thanks…

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

Sidebar

Related Questions

I am trying to create a dynamically generated XML file from Java. This is
I'm trying to use a dynamically generated fully-qualified table name in sql server 2008.
I am trying to use UIMenuCnotroller to show a list of dynamically generated items,
I am trying to generate a PDF file based on a dynamically generated HTML
I am trying to use dynamically created list in WHERE, for example: select *
I'm trying use mod_rewrite to rewrite URLs from the following: http://www.site.com/one-two-file.php to http://www.site.com/one/two/file.php The
am trying to use the Jquery accordion to show a list of links generated
I'm trying to attach a jQuery plugin to a dynamically generated button. I've tried
I am trying to generate HTML which will display the data from XML through
Given the above dynamically generated text (meaning that I can't just use an image),

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.