gpt4 book ai didi

nhibernate - 是什么导致: Unix transport error?

转载 作者:行者123 更新时间:2023-11-29 12:28:01 25 4
gpt4 key购买 nike

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

Internal error
RemotingException: Unix transport error.

注意:如果我使用的是 Sqlite,则不会发生此错误

代码:

 using System;
using ncfg = NHibernate.Cfg;
using System.Collections.Generic;
using System.Reflection;
using NHibernate;
using System.Data;
using NHibernate.Tool.hbm2ddl;
using NHibernate.Dialect;
using NHibernate.Driver;
using NHibernate.ByteCode.LinFu;
using NUnit.Framework;
using NHibernate.Mapping;



namespace RuntimeNhibernate
{
class MainClass
{
public static void Main (string[] args)
{


using(var c = new BlogTestFixture())
{
c.CanSaveAndLoadBlog();

}

}
}



public class InMemoryDatabaseTest : IDisposable
{
private static ncfg.Configuration Configuration;
private static ISessionFactory SessionFactory;
protected ISession session;

public InMemoryDatabaseTest(Assembly assemblyContainingMapping)
{
if (Configuration == null)
{

Configuration = new ncfg.Configuration()
.SetProperty(ncfg.Environment.ReleaseConnections,"on_close")
.SetProperty(ncfg.Environment.Dialect, typeof (SQLiteDialect).AssemblyQualifiedName)
.SetProperty(ncfg.Environment.ConnectionDriver, typeof(SQLite20Driver).AssemblyQualifiedName)
.SetProperty(ncfg.Environment.ConnectionString, "data source=:memory:")
.SetProperty(ncfg.Environment.ProxyFactoryFactoryClass, typeof (ProxyFactoryFactory).AssemblyQualifiedName)
.AddAssembly(assemblyContainingMapping);


/*Configuration = new ncfg.Configuration()
.SetProperty(ncfg.Environment.ReleaseConnections,"on_close")
.SetProperty(ncfg.Environment.Dialect, typeof (PostgreSQLDialect).AssemblyQualifiedName)
.SetProperty(ncfg.Environment.ConnectionDriver, typeof(NpgsqlDriver).AssemblyQualifiedName)
.SetProperty(ncfg.Environment.ConnectionString, "Server=127.0.0.1;Database=memdb;User ID=postgres;Password=password;Pooling=false;")
.SetProperty(ncfg.Environment.ProxyFactoryFactoryClass, typeof (ProxyFactoryFactory).AssemblyQualifiedName)
.AddAssembly(assemblyContainingMapping);*/

SessionFactory = Configuration.BuildSessionFactory();
}

session = SessionFactory.OpenSession();

new SchemaExport(Configuration).Execute(true, true, false, session.Connection, Console.Out);
}

public void Dispose()
{
session.Dispose();
}
}//class InMemory

public class Blog
{
public virtual int BlogId { get; set; }
public virtual bool AllowsComments { set; get; }
public virtual DateTime CreatedAt { get; set; }
public virtual string Subtitle { get; set; }
public virtual string Title { get; set; }
}

[TestFixture]
public class BlogTestFixture : InMemoryDatabaseTest
{
public BlogTestFixture() : base(typeof(Blog).Assembly)
{
}


[Test]
public void IsOK()
{
Assert.AreEqual(true, true);
return;
}

[Test]
public void CanSaveAndLoadBlog()
{


object id;




using (var tx = session.BeginTransaction())
{
id = session.Save(new Blog
{
AllowsComments = true,
CreatedAt = new DateTime(2000,1,1),
Subtitle = "Hello",
Title = "World",
});

tx.Commit();
}

session.Clear();

Console.WriteLine("Hello {0}", id);


using (var tx = session.BeginTransaction())
{
var blog = session.Get<Blog>(id);




Assert.AreEqual(new DateTime(2000, 1, 1), blog.CreatedAt);
Assert.AreEqual("Hello", blog.Subtitle);
Assert.AreEqual("World", blog.Title);
Assert.AreEqual(true, blog.AllowsComments);

tx.Commit();
}
}
}//Test


}//namespace

当我对 Postgresql 进行单元测试时,它导致 RemotingException: Unix transport error. 的可能原因是什么?

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

最佳答案

找到答案,我尝试从终端 (/Applications/MonoDevelop.app/Contents/MacOS/monodevelop) 启动 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

然后我尝试将 Npgsql 版本(导致错误的版本来自 http://pgfoundry.org/frs/download.php/2868/Npgsql2.0.11-bin-ms.net4.0.zip )更改为 http://pgfoundry.org/frs/download.php/2860/Npgsql2.0.11-bin-mono2.0.zip在此之后,就没有更多的 Unix 传输错误 ^_^

经验教训,如果您在 Mono 上运行,请使用您正在使用的组件的 Mono 版本

关于nhibernate - 是什么导致: Unix transport error?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4344225/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com