Note that there are some explanatory texts on larger screens.

plurals
  1. POI get this error that I don't understand why, using NoRM and Mongo in my MVC project
    text
    copied!<p>Cannot access a disposed object. Object name: 'System.Net.Sockets.TcpClient'.</p> <p>I don't understand why it happen and how to deal with it. I use Ninject, my application is based on mvcstarter.codeplex.com/ what I do is delete some user or pages from my database and it happen for no reason(that I can find).</p> <p>Any help would be appreciated!</p> <p>Thanks a lot!</p> <p>*Edited Also, after a while it get back to normal and I can fetch my data from Mongo... My unit tests work fine...</p> <p>Here's my code for my session :</p> <pre><code>public class MongoSession : ISession{ private readonly Mongo _server; public MongoSession() { //this looks for a connection string in your Web.config - you can override this if you want _server = Mongo.Create("MongoDB"); } public T Single&lt;T&gt;(System.Linq.Expressions.Expression&lt;Func&lt;T, bool&gt;&gt; expression) where T : class { return _server.GetCollection&lt;T&gt;().AsQueryable().Where(expression).SingleOrDefault(); } public IQueryable&lt;T&gt; All&lt;T&gt;() where T : class { return _server.GetCollection&lt;T&gt;().AsQueryable(); } /*public void Add&lt;T&gt;(T item) where T : class { _provider.DB.GetCollection&lt;T&gt;().Insert(item); }*/ public void Save&lt;T&gt;(IEnumerable&lt;T&gt; items) where T : class { foreach (T item in items) { Save(item); } } public void Save&lt;T&gt;(T item) where T : class { var errors = DataAnnotationsValidationRunner.GetErrors(item); if (errors.Count() &gt; 0) { throw new RulesException(errors); } _server.Database.GetCollection&lt;T&gt;().Save(item); } //this is just some sugar if you need it. /*public T MapReduce&lt;T&gt;(string map, string reduce) { T result = default(T); using (MapReduce mr = _provider.Server.CreateMapReduce()) { MapReduceResponse response = mr.Execute(new MapReduceOptions(typeof(T).Name) { Map = map, Reduce = reduce }); MongoCollection&lt;MapReduceResult&lt;T&gt;&gt; coll = response.GetCollection&lt;MapReduceResult&lt;T&gt;&gt;(); MapReduceResult&lt;T&gt; r = coll.Find().FirstOrDefault(); result = r.Value; } return result; }*/ public void Delete&lt;T&gt;(System.Linq.Expressions.Expression&lt;Func&lt;T, bool&gt;&gt; expression) where T : class { var items = All&lt;T&gt;().Where(expression); foreach (T item in items) { Delete(item); } } public void Delete&lt;T&gt;(T item) where T : class { _server.GetCollection&lt;T&gt;().Delete(item); } public void Drop&lt;T&gt;() where T : class { _server.Database.DropCollection(typeof(T).Name); } /*public void CommitChanges() { //mongo isn't transactional in this way... it's all firehosed }*/ public void Dispose() { _server.Dispose(); } } </code></pre> <p>And the calling code would be something like this, my _session is pass to my Controller in the contrutor using Ninject, with the binding in my global.cs :</p> <pre><code>Bind&lt;ISession&gt;().To&lt;MongoSession&gt;().InSingletonScope(); public virtual ActionResult Liens() { var shortcutLionks = _session.All&lt;ShortcutLinks&gt;().ToList(); ViewData.Model = shortcutLionks.Count &gt; 0 ? shortcutLionks[0] : new ShortcutLinks(); return View(); } </code></pre> <p>EDITED :</p> <p>Here's the detail of my error :</p> <blockquote> <p>Stack Trace : at System.Net.Sockets.TcpClient.GetStream() at Norm.Connection.GetStream() at Norm.Connection.Write(Byte[] bytes, Int32 start, Int32 size) at Norm.Protocol.Messages.QueryMessage<code>2.Execute() at Norm.MongoQueryExecutor</code>3.d__0.MoveNext() at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable<code>1 source) at Norm.Linq.MongoQueryExecutor.Execute[T]() at Norm.Linq.MongoQueryProvider.ExecuteQuery[T](Expression expression) at Norm.Linq.MongoQueryProvider.System.Linq.IQueryProvider.Execute[S](Expression expression) at System.Linq.Queryable.SingleOrDefault[TSource](IQueryable</code>1 source) at Domain.Storage.MongoDB.MongoSession.Single[T](Expression<code>1 expression) in C:\inetpub\wwwroot\DubeLoiselle\Domain\Storage\MongoDB\MongoSession.cs:line 21 at Domain.Storage.MongoDB.MongoRepositoryBase</code>1.Single(Expression<code>1 expression) in C:\inetpub\wwwroot\DubeLoiselle\Domain\Storage\MongoDB\MongoRepositoryBase.cs:line 26 at SPK.CMS.Domain.Repository.PageRepository.GetHomePage() in C:\inetpub\wwwroot\DubeLoiselle\SPK.CMS.Domain\Repository\PageRepository.cs:line 146 at Web.Controllers.PageController.Home() in C:\inetpub\wwwroot\DubeLoiselle\Web\Controllers\PageController.cs:line 26 at Web.Controllers.PageController.RedirectTo(String url1, String url2, String url3) in C:\inetpub\wwwroot\DubeLoiselle\Web\Controllers\PageController.cs:line 50 at lambda_method(ExecutionScope , ControllerBase , Object[] ) at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary</code>2 parameters) at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary<code>2 parameters) at System.Web.Mvc.ControllerActionInvoker.&lt;&gt;c__DisplayClassd.b__a() at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func</code>1 continuation) at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList<code>1 filters, ActionDescriptor actionDescriptor, IDictionary</code>2 parameters) at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName)</p> </blockquote> <p><strong>Edited again :</strong></p> <p>Before I get this error I trap this one :</p> <p>Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host. </p> <p>Stack Trace : at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32 offset, Int32 size) at Norm.Connection.Write(Byte[] bytes, Int32 start, Int32 size) at Norm.Protocol.Messages.QueryMessage<code>2.Execute() at Norm.MongoQueryExecutor</code>3.d__0.MoveNext() at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable<code>1 source) at Norm.Linq.MongoQueryExecutor.Execute[T]() at Norm.Linq.MongoQueryProvider.ExecuteQuery[T](Expression expression) at Norm.Linq.MongoQueryProvider.System.Linq.IQueryProvider.Execute[S](Expression expression) at System.Linq.Queryable.SingleOrDefault[TSource](IQueryable</code>1 source) at Domain.Storage.MongoDB.MongoSession.Single[T](Expression<code>1 expression) in C:\inetpub\wwwroot\DubeLoiselle\Domain\Storage\MongoDB\MongoSession.cs:line 21 at Domain.Storage.MongoDB.MongoRepositoryBase</code>1.Single(Expression<code>1 expression) in C:\inetpub\wwwroot\DubeLoiselle\Domain\Storage\MongoDB\MongoRepositoryBase.cs:line 26 at SPK.CMS.Domain.Repository.PageRepository.GetHomePage() in C:\inetpub\wwwroot\DubeLoiselle\SPK.CMS.Domain\Repository\PageRepository.cs:line 146 at SPK.CMS.Domain.Repository.PageRepository.GetByUrl(String url1, String url2, String url3) in C:\inetpub\wwwroot\DubeLoiselle\SPK.CMS.Domain\Repository\PageRepository.cs:line 195 at Web.Controllers.PageController.RedirectTo(String url1, String url2, String url3) in C:\inetpub\wwwroot\DubeLoiselle\Web\Controllers\PageController.cs:line 52 at lambda_method(ExecutionScope , ControllerBase , Object[] ) at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary</code>2 parameters) at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary<code>2 parameters) at System.Web.Mvc.ControllerActionInvoker.&lt;&gt;c__DisplayClassd.b__a() at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func</code>1 continuation) at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList<code>1 filters, ActionDescriptor actionDescriptor, IDictionary</code>2 parameters) at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload