Nhibernate 什么原因:Unix传输错误?

Nhibernate 什么原因:Unix传输错误?,nhibernate,postgresql,nunit,Nhibernate,Postgresql,Nunit,我正在Postgresql上进行单元测试(使用NUnit),不幸的是,它导致了一个错误: Internal error RemotingException: Unix transport error. 注意:如果使用Sqlite,则不会发生此错误 代码: 使用系统; 使用ncfg=NHibernate.Cfg; 使用System.Collections.Generic; 运用系统反思; 使用NHibernate; 使用系统数据; 使用NHibernate.Tool.hbm2ddl; 使

我正在Postgresql上进行单元测试(使用NUnit),不幸的是,它导致了一个错误:

Internal error
    RemotingException: Unix transport error.
注意:如果使用Sqlite,则不会发生此错误

代码:

使用系统;
使用ncfg=NHibernate.Cfg;
使用System.Collections.Generic;
运用系统反思;
使用NHibernate;
使用系统数据;
使用NHibernate.Tool.hbm2ddl;
使用NHibernate方言;
使用NHibernate.Driver;
使用NHibernate.ByteCode.LinFu;
使用NUnit.Framework;
使用NHibernate.Mapping;
命名空间RuntimeNhibernate
{
类主类
{
公共静态void Main(字符串[]args)
{
使用(var c=new BlogTestFixture())
{
c、 CanSaveAndLoadBlog();
}
}
}
MemoryDatabaseTest中的公共类:IDisposable
{
专用静态ncfg.配置;
私人静态ISessionFactory SessionFactory;
受保护的会话;
public InMemoryDatabaseTest(程序集组装包含映射)
{
if(配置==null)
{
配置=新的ncfg.Configuration()
.SetProperty(ncfg.Environment.ReleaseConnections,“打开/关闭”)
.SetProperty(ncfg.Environment.dialogue,typeof(sqlitedialogue).AssemblyQualifiedName)
.SetProperty(ncfg.Environment.ConnectionDriver,typeof(SQLite20Driver).AssemblyQualifiedName)
.SetProperty(ncfg.Environment.ConnectionString,“数据源=:内存:”)
.SetProperty(ncfg.Environment.ProxyFactoryFactoryClass,typeof(ProxyFactoryFactory).AssemblyQualifiedName)
.AddAssembly(assemblyContainingMapping);
/*配置=新的ncfg.Configuration()
.SetProperty(ncfg.Environment.ReleaseConnections,“打开/关闭”)
.SetProperty(ncfg.Environment.dialent,typeof(PostgreSqlDialent).AssemblyQualifiedName)
.SetProperty(ncfg.Environment.ConnectionDriver,typeof(NpgsqlDriver).AssemblyQualifiedName)
.SetProperty(ncfg.Environment.ConnectionString,“服务器=127.0.0.1;数据库=memdb;用户ID=postgres;密码=Password;池=false;”)
.SetProperty(ncfg.Environment.ProxyFactoryFactoryClass,typeof(ProxyFactoryFactory).AssemblyQualifiedName)
.AddAssembly(assemblyContainingMapping)*/
SessionFactory=Configuration.BuildSessionFactory();
}
session=SessionFactory.OpenSession();
新的SchemaExport(配置).Execute(true、true、false、session.Connection、Console.Out);
}
公共空间处置()
{
session.Dispose();
}
}//内存中的类
公共类博客
{
公共虚拟int BlogId{get;set;}
公共虚拟bool AllowsComments{set;get;}
公共虚拟日期时间CreatedAt{get;set;}
公共虚拟字符串字幕{get;set;}
公共虚拟字符串标题{get;set;}
}
[测试夹具]
公共类BlogTestFixture:InMemoryDatabaseTest
{
public BlogTestFixture():基(typeof(Blog.Assembly)
{
}
[测试]
公共无效IsOK()
{
断言.AreEqual(真,真);
返回;
}
[测试]
public void CanSaveAndLoadBlog()
{
对象id;
使用(var tx=session.BeginTransaction())
{
id=会话。保存(新博客)
{
AllowsComments=true,
CreatedAt=新日期时间(2000,1,1),
Subtitle=“你好”,
Title=“世界”,
});
tx.Commit();
}
session.Clear();
WriteLine(“Hello{0}”,id);
使用(var tx=session.BeginTransaction())
{
var blog=session.Get(id);
AreEqual(新日期时间(2000,1,1),blog.CreatedAt);
AreEqual(“你好”,blog.Subtitle);
Assert.AreEqual(“世界”,blog.Title);
arenequal(true,blog.AllowsComments);
tx.Commit();
}
}
}//试验
}//名称空间
当我对Postgresql进行单元测试时,可能会导致远程处理异常:Unix传输错误。


如果我在单元测试之外运行代码(例如Main),它就可以工作。顺便说一句,如果我对Sqlite进行单元测试,它也不会导致任何错误

找到答案,我尝试从终端启动MonoDevelop(/Applications/MonoDevelop.app/Contents/MacOS/MonoDevelop),我在运行单元测试时从命令行看到了更详细的错误

Unhandled Exception: System.TypeInitializationException: An exception was thrown by the type initializer for Npgsql.NpgsqlConnection ---> System.TypeLoadException: Could not load type 'System.Runtime.Versioning.TargetFrameworkAttribute' from assembly 'Npgsql'.
  at (wrapper managed-to-native) System.MonoCustomAttrs:GetCustomAttributesInternal (System.Reflection.ICustomAttributeProvider,System.Type,bool)
  at System.MonoCustomAttrs.GetCustomAttributesBase (ICustomAttributeProvider obj, System.Type attributeType) [0x00000] in <filename unknown>:0 
  at System.MonoCustomAttrs.GetCustomAttributes (ICustomAttributeProvider obj, System.Type attributeType, Boolean inherit) [0x00000] in <filename unknown>:0 
  at System.Reflection.Assembly.GetCustomAttributes (System.Type attributeType, Boolean inherit) [0x00000] in <filename unknown>:0 
  at System.Resources.ResourceManager.GetNeutralResourcesLanguage (System.Reflection.Assembly a) [0x00000] in <filename unknown>:0 
  at System.Resources.ResourceManager..ctor (System.Type resourceSource) [0x00000] in <filename unknown>:0 
  at Npgsql.NpgsqlConnection..cctor () [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at (wrapper managed-to-native) System.Reflection.MonoCMethod:InternalInvoke (System.Reflection.MonoCMethod*,object,object[],System.Exception&)
  at System.Reflection.MonoCMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0 
未处理的异常:System.TypeInitializationException:Npgsql.NpgsqlConnection的类型初始值设定项引发了异常-->System.TypeLoadException:无法从程序集“Npgsql”加载类型“System.Runtime.Versioning.TargetFrameworkAttribute”。
at(包装器管理到本机)System.MonoCustomAttrs:GetCustomAttributesInternal(System.Reflection.ICCustomAttributeProvider,System.Type,bool)
在System.MonoCustomAttrs.GetCustomAttributesBase(ICCustomAttributeProvider对象,System.Type attributeType)[0x00000]中:0
在System.MonoCustomAttrs.GetCustomAttributes(ICustomAttributeProvider obj,System.Type attributeType,布尔继承)[0x00000]中:0
在:0中的System.Reflection.Assembly.GetCustomAttributes(System.Type attributeType,布尔继承)[0x00000]处
位于:0中的System.Resources.ResourceManager.GetNeutralResourcesLanguage(System.Reflection.Assembly a)[0x00000]处
位于:0中的System.Resources.ResourceManager..ctor(System.Type resourceSource)[0x00000]处
在:0中的Npgsql.NpgsqlConnection..cctor()[0x00000]处
---内部异常堆栈跟踪的结束---
at(包装器管理为本机)System.Reflection.MonoCMethod:InternalInvoke(System.Reflection.MonoCMethod*,object,object[],System.Exception&)
在System.Reflection.MonoCMethod.Invoke(System.Object obj、BindingFlags invokeAttr、System.Reflection.Binder Binder、System.Object[]参数、System.Globalization.CultureInfo区域性)[0x00000]中:0
然后,我尝试将Npgsql版本(导致错误的版本来自)更改为之后,不再出现Unix传输错误^_^


吸取的教训,使用您正在使用的组件的Mono版本如果您在Mono上运行东西

找到答案,我尝试从终端启动MonoDevelop(/Applications/MonoD
Unhandled Exception: System.TypeInitializationException: An exception was thrown by the type initializer for Npgsql.NpgsqlConnection ---> System.TypeLoadException: Could not load type 'System.Runtime.Versioning.TargetFrameworkAttribute' from assembly 'Npgsql'.
  at (wrapper managed-to-native) System.MonoCustomAttrs:GetCustomAttributesInternal (System.Reflection.ICustomAttributeProvider,System.Type,bool)
  at System.MonoCustomAttrs.GetCustomAttributesBase (ICustomAttributeProvider obj, System.Type attributeType) [0x00000] in <filename unknown>:0 
  at System.MonoCustomAttrs.GetCustomAttributes (ICustomAttributeProvider obj, System.Type attributeType, Boolean inherit) [0x00000] in <filename unknown>:0 
  at System.Reflection.Assembly.GetCustomAttributes (System.Type attributeType, Boolean inherit) [0x00000] in <filename unknown>:0 
  at System.Resources.ResourceManager.GetNeutralResourcesLanguage (System.Reflection.Assembly a) [0x00000] in <filename unknown>:0 
  at System.Resources.ResourceManager..ctor (System.Type resourceSource) [0x00000] in <filename unknown>:0 
  at Npgsql.NpgsqlConnection..cctor () [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at (wrapper managed-to-native) System.Reflection.MonoCMethod:InternalInvoke (System.Reflection.MonoCMethod*,object,object[],System.Exception&)
  at System.Reflection.MonoCMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0 
Unhandled exceptions:
1) Residata.Platform.Server.Message.Test.MemoryBrokerTest.AssertThatReceiveMethodWaitsUntilPublish : System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
   at System.Collections.Generic.List`1+Enumerator[Residata.Platform.Contract.Message.IPackage].MoveNext () [0x00000] in <filename unknown>:0