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

  • Home
  • SEARCH
  • 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 722767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:01:43+00:00 2026-05-14T06:01:43+00:00

Description: An unhandled exception occurred during the execution of the current web request. Please

  • 0
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.ArgumentNullException: Value cannot be null.
Parameter name: mapping

Source Error: 


Line 45:     #endregion
Line 46:        
Line 47:        public db() : 
Line 48:                base(global::data.Properties.Settings.Default.nanocrmConnectionString, mappingSource)
Line 49:        {

this is what i get if i implement such class:

partial class db
{
    static db _db = new db();

    public static db GetInstance()
    {
        return _db;
    }
}

db is a linq2sql datacontext

why this hapenned and how to solve this?

UPD: that file is generated by linq2sql:

    private static System.Data.Linq.Mapping.MappingSource mappingSource = new AttributeMappingSource();

    public db() : 
            base(global::data.Properties.Settings.Default.nanocrmConnectionString, mappingSource)
    {
        OnCreated();
    }

if I instantiate db inside method (not property like here) all works fine. and the static method worked until this morning, but now even 2 days ago version (restored from repository) falls with the same error.

UPD 2:

so this is my partial class after problem was solved:

namespace data
{
using System.Data.Linq.Mapping;

partial class db
{
    static db _db = new db(global::data.Properties.Settings.Default.nanocrmConnectionString, new AttributeMappingSource());

    public static db GetInstance()
    {
        return _db;
    }
}
}
  • 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-14T06:01:43+00:00Added an answer on May 14, 2026 at 6:01 am

    Ah, I just had a look. It seems the static variable is not initialized for some reason.

    For now you can solve the problem by doing the following:

    static db _db = new db(
     global::data.Properties.Settings.Default.nanocrmConnectionString, 
     new AttributeMappingSource());
    

    It is rather strange though that mappingSource would still be null.

    Thinking about it now, it could be how partial classes are stitched together. For some reason, it uses your code as the ‘prefix’ of the entire class. It seems, as I would expect, that mappingSource is not initialized when _db is being initialized.

    A further explanation of what is causing the issue.

    The order of initialization of static members are undefined, but generally they tend to be in order.

    Take the follow program as an example to further complicate things.

    Main.cs

      class Printer
      {
        public Printer(string s)
        {
          Console.WriteLine(s);
        }
      }
    
      partial class Program
      {
        static void Main()
        {
          new Program();
          Console.ReadLine();
        }
      }
    

    X.cs

      partial class Program
      {
        static Printer x = new Printer("x");
      }
    

    Y.cs

      partial class Program
      {
        static Printer y = new Printer("y");
      }
    

    Z.cs

      partial class Program
      {
        static Printer z = new Printer("z");
      }
    

    Now depending on how feed the compiler the classes, the order of initialization can change.

    Try:

    • csc Main.cs X.cs Y.cs Z.cs
    • csc Main.cs Y.cs Z.cs X.cs
    • csc Main.cs Y.cs X.cs Z.cs

    I suspect you will see different results every time.

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

Sidebar

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.