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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T15:52:56+00:00 2026-05-19T15:52:56+00:00

I have a class definition that looks like this: public class SolrObj { [SolrUniqueKey(id)]

  • 0

I have a class definition that looks like this:

public class SolrObj
{
[SolrUniqueKey("id")]
public int id { get; set; }

[SolrField("title")]
public string title { get; set; }

[SolrField("description")]
public string description { get; set; }

[SolrField("url")]
public string url { get; set; }
}

And in some code from which SolrObj is accessible, I have this:

SolrObj a = new SolrObj
{
    id = edit_id,
    title = textbox_title.Text,
    description = textbox_description.Text,
    url = textbox_url.Text,
};

However, when the above snippet runs, I get a NullReferenceException on it. I don’t see how this can happen as I’m trying to define it right there. a is the null object that throws the exception. How can I fix this?

Sorry for the easy question. The same snippet above works elsewhere in another function, so I’m kind of puzzled here.

EDIT: I see that one of the Text attributes is null and causing this exception; thanks for the answers so far, sorry I’m stupid. How can I get around this? Is there a way I can test for null on the assignment and give an empty string instead? Maybe a ternary operator?

EDIT 2: This is a bad question, by the way. I truncated the class for posting here and excluded an element that used element.SelectedItem.Text. SelectedItem was the null value and the thing tripping us up — commenters below questioning a TextBox’s Text being null are correct, this is not null and shouldn’t be null, which was part of the confusion. The null thing was element.SelectedItem (the test data does not have elements selected). Sorry for the confusion and thanks again for the 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-05-19T15:52:57+00:00Added an answer on May 19, 2026 at 3:52 pm

    One of your source variables is null:

    textbox_title
    textbox_description
    textbox_url
    

    So when you try to reference it’s .Text property it is throwing an Object Reference not set exception, because (null).Text is not a valid expression.

    If it is null then you probably have some other error, probably on your .aspx/.ascx. Because normally you would expect a TextBox to exist if your markup is correct.

    To check for null use this:

    SolrObj a = new SolrObj
    {
        id = edit_id,
        title = textbox_title != null ? textbox_title.Text : string.Empty,
        description = textbox_description != null ? textbox_description.Text : string.Empty,
        url = textbox_url != null ? textbox_url.Text : string.Empty,
    };
    

    But I strongly suspect that you have something else wrong, because as said before you would not expect a TextBox to be null.

    You said that it works elsewhere – is it possible that you have copied the code, but not the markup? Do you actually have an <asp : TextBox id="textbox_title"> on your form?

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

Sidebar

Related Questions

Let's say that you have a Model that looks kind of like this: public
I have generic type that looks like: public class GenericClass<T, U> where T :
Basically I have code which looks like this inside a header file: class Bar;
Let's have the following class definition: CThread::CThread () { this->hThread = NULL; this->hThreadId =
This is something that I never ran into before. Say I have a class
Anyone knows if is possible to have partial class definition on C++ ? Something
I have class method that returns a list of employees that I can iterate
I have class A: public class ClassA<T> Class B derives from A: public class
I have class with internal property: internal virtual StateEnum EnrolmentState { get { ..getter
I have class with a member function that takes a default argument. struct Class

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.