nhibernate - What causes: Unix transport error? -
i'm doing unit test(using nunit) on postgresql, unfortunately causes error:
internal error remotingexception: unix transport error. note: error doesn't happen if i'm using sqlite
code:
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 what possible reason when unit test postgresql, results remotingexception: unix transport error. ?
if run code outside of unit test (e.g. main), works. btw, if unit test sqlite, doesn't cause errors too
found answer, tried launching monodevelop terminal (/applications/monodevelop.app/contents/macos/monodevelop), saw more detailed error commandline when ran unit tests.
unhandled exception: system.typeinitializationexception: exception thrown type initializer npgsql.npgsqlconnection ---> system.typeloadexception: not load type 'system.runtime.versioning.targetframeworkattribute' assembly 'npgsql'. @ (wrapper managed-to-native) system.monocustomattrs:getcustomattributesinternal (system.reflection.icustomattributeprovider,system.type,bool) @ system.monocustomattrs.getcustomattributesbase (icustomattributeprovider obj, system.type attributetype) [0x00000] in <filename unknown>:0 @ system.monocustomattrs.getcustomattributes (icustomattributeprovider obj, system.type attributetype, boolean inherit) [0x00000] in <filename unknown>:0 @ system.reflection.assembly.getcustomattributes (system.type attributetype, boolean inherit) [0x00000] in <filename unknown>:0 @ system.resources.resourcemanager.getneutralresourceslanguage (system.reflection.assembly a) [0x00000] in <filename unknown>:0 @ system.resources.resourcemanager..ctor (system.type resourcesource) [0x00000] in <filename unknown>:0 @ npgsql.npgsqlconnection..cctor () [0x00000] in <filename unknown>:0 --- end of inner exception stack trace --- @ (wrapper managed-to-native) 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[] parameters, system.globalization.cultureinfo culture) [0x00000] in <filename unknown>:0 then tried changing npgsql version(the 1 causes error came 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 after this, there's no more unix transport error ^_^
lesson learned, use mono version of component using if running things on mono
Comments
Post a Comment