0

I am using solr 7 and solrnet 0.4.0.4001. When I am querying to solr an exception occurs:

An exception of type 'System.Xml.XmlException' occurred in System.Xml.dll but was not handled in user code

Additional information:

Data at the root level is invalid. Line 1, position 1.

using Microsoft.Practices.ServiceLocation;
using SolrApp.Entities;
using SolrApp.Models;
using SolrNet;
using SolrNet.Commands.Parameters;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace SolrApp.Controllers
{
    public class HomeController : Controller
    {
        // GET: Home
        public ActionResult Index()
        {
            // find the service   
            Startup.Init<Products>("http://localhost:8983/solr/pro");
            ISolrOperations<Products> solr = ServiceLocator.Current.GetInstance<ISolrOperations<Products>>();

            var entityObj = new testEntities();

            var pro = entityObj.Products.Select(x => new Products { Id = x.Id, Name = x.Name }).ToList();
            solr.Delete(SolrQuery.All);
            solr.AddRange(pro);

            // commit to the index  
            solr.Commit();

            return View();
        }

        public JsonResult Search()
        {
            ISolrOperations<Products> solr = ServiceLocator.Current.GetInstance<ISolrOperations<Products>>();



            var appleProducts = solr.Query(new SolrQuery("*:*"));

            List<Products> prodList = new List<Products>();
            foreach (Products product in appleProducts)
            {
                var prod = new Products()
                { Id = product.Id, Name = product.Name };
                prodList.Add(prod);
            }
            return Json("", JsonRequestBehavior.AllowGet);
        }
    }
}
Nicomedes E.
  • 1,326
  • 5
  • 18
  • 27
  • On which line did you get the error and what was the state of the variables (debug your code)? – Jeroen Heier Dec 27 '17 at 11:34
  • @see _[Why “Data at the root level is invalid. Line 1, position 1.” for XML Document ?](https://stackoverflow.com/questions/17947238/why-data-at-the-root-level-is-invalid-line-1-position-1-for-xml-document)_ – EricLavault Dec 27 '17 at 12:36
  • Thanks for replying guys. I have changed solr schema fields type to string, doing this solved my issue . – Gaurav Juyal Jan 02 '18 at 04:46
  • using solrnet is there any way to get total records from solr instead of this => var lstMain = solr.Query(new SolrQuery(":")).Count(); – Gaurav Juyal Jan 10 '18 at 04:42

0 Answers0