Cannot access a disposed object. Object name: System.Net.Sockets.TcpClient .
我不理解为什么发生这种情况以及如何处理。 我使用Ninject,我的申请是基于mvcstarter.codeplex.com/,我确实从我的数据库中删除一些用户或网页,而且这样做是毫无理由的(我可以发现)。
感谢任何帮助!
感谢很多!
*Edited Also, after a while it get back to normal and I can fetch my data from Mongo... My unit tests work fine...
我的本届会议守则如下:
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<T>(System.Linq.Expressions.Expression<Func<T, bool>> expression) where T : class {
return _server.GetCollection<T>().AsQueryable().Where(expression).SingleOrDefault();
}
public IQueryable<T> All<T>() where T : class {
return _server.GetCollection<T>().AsQueryable();
}
/*public void Add<T>(T item) where T : class {
_provider.DB.GetCollection<T>().Insert(item);
}*/
public void Save<T>(IEnumerable<T> items) where T : class {
foreach (T item in items) {
Save(item);
}
}
public void Save<T>(T item) where T : class {
var errors = DataAnnotationsValidationRunner.GetErrors(item);
if (errors.Count() > 0)
{
throw new RulesException(errors);
}
_server.Database.GetCollection<T>().Save(item);
}
//this is just some sugar if you need it.
/*public T MapReduce<T>(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<MapReduceResult<T>> coll = response.GetCollection<MapReduceResult<T>>();
MapReduceResult<T> r = coll.Find().FirstOrDefault();
result = r.Value;
}
return result;
}*/
public void Delete<T>(System.Linq.Expressions.Expression<Func<T, bool>> expression) where T : class
{
var items = All<T>().Where(expression);
foreach (T item in items)
{
Delete(item);
}
}
public void Delete<T>(T item) where T : class
{
_server.GetCollection<T>().Delete(item);
}
public void Drop<T>() 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();
}
}
发出呼吁的守则就象这样,我的——会议由我的主计长主持,使用Ninject,在我的全球范围内具有约束力:
Bind<ISession>().To<MongoSession>().InSingletonScope();
public virtual ActionResult Liens()
{
var shortcutLionks = _session.All<ShortcutLinks>().ToList();
ViewData.Model = shortcutLionks.Count > 0 ? shortcutLionks[0] : new ShortcutLinks();
return View();
}
EDITED:
我的错误细节:
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
2.Execute() at Norm.MongoQueryExecutor
3.d__0.MoveNext() at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable1 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
1 source) at Domain.Storage.MongoDB.MongoSession.Single[T](Expression1 expression) in C:inetpubwwwrootDubeLoiselleDomainStorageMongoDBMongoSession.cs:line 21 at Domain.Storage.MongoDB.MongoRepositoryBase
1.Single(Expression1 expression) in C:inetpubwwwrootDubeLoiselleDomainStorageMongoDBMongoRepositoryBase.cs:line 26 at SPK.CMS.Domain.Repository.PageRepository.GetHomePage() in C:inetpubwwwrootDubeLoiselleSPK.CMS.DomainRepositoryPageRepository.cs:line 146 at Web.Controllers.PageController.Home() in C:inetpubwwwrootDubeLoiselleWebControllersPageController.cs:line 26 at Web.Controllers.PageController.RedirectTo(String url1, String url2, String url3) in C:inetpubwwwrootDubeLoiselleWebControllersPageController.cs:line 50 at lambda_method(ExecutionScope , ControllerBase , Object[] ) at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary
2 parameters) at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary2 parameters) at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClassd.b__a() at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func
1 continuation) at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList1 filters, ActionDescriptor actionDescriptor, IDictionary
2 parameters) at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName)
www.un.org/Depts/DGACM/index_spanish.htm :
在我发现这一错误之前,我把这一错误trap为一:
无法将数据写给运输连接: 遥远的东道国强行关闭了现有的连接。
Stack Tra: at System.Net.Sockets.NetworkStream.Write(Byte[]缓冲区,Int32.50,Int32 volume) at Norm.Connection。 文献目录 Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext Controller) 背景,行动说明者行动说明,IDictionary 2 参数,系统。 Web.Mvc.ControllerActionInvoker.<>c__DisplayClassd.b__a() at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilterfil), ActionExecutingContext preContext, Func
1sus) at System. Web.Mvc.ControllerActionInvoker. InvokeActionMethodWithFilters (ControllerContext Controller) 背景:IList1 过滤器, 行动说明者行动Descriptor, IDictionary
2参半 Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext ControllerContext, String actionName)