Object reference not set to an instance of an object.

518 views
Skip to first unread message

Đức Trần

unread,
Mar 15, 2014, 1:18:28 PM3/15/14
to sol...@googlegroups.com
I'm new solrnet Developer! I'm getting following error when trying to build "https://github.com/mausch/SolrNet/blob/master/Documentation/Basic-usage.md".
    Error: 

Server Error in '/SolrdotNET' Application.

Object reference not set to an instance of an object.

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.NullReferenceException: Object reference not set to an instance of an object.

Source Error: 

Line 26:             InStock = true,
Line 27:         };
Line 28:         var solr = ServiceLocator.Current.GetInstance<ISolrOperations<Product>>();
Line 29:         solr.Add(p);
Line 30:         solr.Commit();

Source File: d:\PROJECTS\FULL TEXT SEARCH\SOLR\SolrdotNET\Default.aspx.cs    Line: 28 

Please help me fix error! Thanks!


Mauricio Scheffer

unread,
Mar 15, 2014, 8:52:43 PM3/15/14
to sol...@googlegroups.com
You probably forgot to add the initialization code, as the "basic usage" page describes:

    Startup.Init<Product>("http://localhost:8983/solr");



Cheers



--
Mauricio


--
You received this message because you are subscribed to the Google Groups "SolrNet" group.
To unsubscribe from this group and stop receiving emails from it, send an email to solrnet+u...@googlegroups.com.
To post to this group, send email to sol...@googlegroups.com.
Visit this group at http://groups.google.com/group/solrnet.
For more options, visit https://groups.google.com/d/optout.

Tanvir Ahmed

unread,
Nov 29, 2017, 5:28:02 PM11/29/17
to SolrNet
I am having same problem.

Getting same exception in the following second line:

SolrNet.Startup.Init<guidanceDoc>("http://localhost:8983/solr/"); 
ISolrOperations<guidanceDoc> solr = ServiceLocator.Current.GetInstance<ISolrOperations<guidanceDoc>>();

Can you kindly guide me what might be wrong here?

Thanks,
Tanvir

Joe

unread,
May 31, 2018, 11:19:55 AM5/31/18
to SolrNet
Hello Tanvir, were you able to figure out what was wrong?  I am getting the error "The name 'Startup' does not exist in the current context" in my following code:

void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
Startup.Init(http://localhost:8080/solr); 
    }

Thanks

Mauricio Scheffer

unread,
May 31, 2018, 11:40:27 AM5/31/18
to sol...@googlegroups.com
Hi Joe, if you're getting a compile-time error there it means you're either missing the namespace ("using SolrNet;") or the assembly/nuget reference to SolrNet.dll altogether.

Cheers



--
Mauricio

To unsubscribe from this group and stop receiving emails from it, send an email to solrnet+unsubscribe@googlegroups.com.

To post to this group, send email to sol...@googlegroups.com.

Tanvir Ahmed

unread,
May 31, 2018, 11:43:19 AM5/31/18
to sol...@googlegroups.com
Joe,

In my case I solved the Startup error after adding SolrNet NuGet package and also adding "using SolrNet;"  library in the class. However, I gave up using SOlrNet when I could not resolve the exception shown in my question and could not get any support. Later on I used System.Net.WebClient() for my purpose. Also used Newtonsoft.Json and System.Json. It is not using SolrNet, but somehow fulfill what I wanted. A code snippet is given bellow:

using (var webClient = new System.Net.WebClient())
        {
            webClient.Encoding = Encoding.UTF8;
            webClient.UseDefaultCredentials = true;
            webClient.Credentials = CredentialCache.DefaultCredentials;
            var json = webClient.DownloadString("http://localhost:8983/solr/guidanceDoc/select?q="+ searchkey + "&hl=on&hl.fl=_text_&hl.fragsize=200&rows=20&fl=id,resourcename,score,title&wt=json");
            
            JObject obj = JObject.Parse(json);
            JObject resp = JObject.Parse(obj["response"].ToString());
            JObject hilights = JObject.Parse(obj["highlighting"].ToString());
            Label1.Text = "Search key: " + searchkey + " <br>Total documents found : " + resp["numFound"].ToString() +"<br>Maximum score : " + resp["maxScore"].ToString() + "<br>Showing maximum top 20  results (if available).";
         ........................
         .......
              } 
            


Hope that helps.

Kind regards,
Tanvir


--
You received this message because you are subscribed to a topic in the Google Groups "SolrNet" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/solrnet/V0ZB6sJa5bA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to solrnet+unsubscribe@googlegroups.com.

To post to this group, send email to sol...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Regards,
Tanvir Ahmed

Joe

unread,
May 31, 2018, 2:25:00 PM5/31/18
to SolrNet
Thank you Mauricio for getting back to me.  In the attached sample code file, you would see that I have included the namespace.  I also have reference to SolrNet,dll in my project.  I still get the error Object reference not set to an instance of an object at the line: SolrOperations <SolrSearchResult> solr = ServiceLocator.Current.GetInstance<ISolrOperations<SolrSearchResult>>();

Also, just wondering do I need the line Startup.Init<SolrSearchResult>("http://localhost:8080/solr"); if I already have solr running on my localhost.

Thank again.


--
Mauricio

code.txt

Joe

unread,
May 31, 2018, 2:29:02 PM5/31/18
to SolrNet
Thank you Tanvir for getting back to me. I am doing opposite to what you have done. I already have the app up and running without using SolrNet and want to rewrite the code using SolrNet.

Regards.
To unsubscribe from this group and all its topics, send an email to solrnet+u...@googlegroups.com.

To post to this group, send email to sol...@googlegroups.com.
Visit this group at https://groups.google.com/group/solrnet.
For more options, visit https://groups.google.com/d/optout.



--
Regards,
Tanvir Ahmed

Mauricio Scheffer

unread,
Jun 10, 2018, 3:40:03 PM6/10/18
to SolrNet
Hi Joe, yes you still need to include that in your app startup. It does not start or manage the Solr server in any way, it only initializes the SolrNet library.

Joe C S

unread,
Jun 11, 2018, 11:23:42 PM6/11/18
to sol...@googlegroups.com
Thank you Mauricio.  Should the port number be always 8080 in the startup line  Startup.Init<SolrSearchResult>("http://localhost:8080/solr")  or should it be the same port number where I have solr running which in my case  is the port 8983?
Reply all
Reply to author
Forward
0 new messages