Я играю с Castle activeRecord и успешно создал приложение MVC asp.net, которое может генерировать схему, выполнять операции crud и запрашивать базу данных mysql. Я сделал это в MonoDevelop.
Странно то, что, если я использую почти тот же код в проекте командной строки, он не работает, выдает следующее исключение:
Could not create the driver from NHibernate.Driver.MySqlDataDriver
Исключение выдается на pc.Create();
в коде ниже. Несмотря на то, что я говорю это для генерации схемы, на самом деле этого никогда не происходит, но это происходит в веб-приложении.
Некоторое гугление этого сообщения указывает на то, что это происходит, когда файл mysql.data.dll не находится в пути или на него ссылаются и т. Д. На него ссылаются, и «локальное копирование» включено, поэтому оно копируется в папку отладки. Я проверил, что он действительно присутствует в папке тоже.
У меня точно такие же ссылки, что и в приложении asp.net mvc. Почему это терпит неудачу?
Вот код приложения командной строки:
using System;
using Castle.ActiveRecord;
using Castle.ActiveRecord.Framework.Config;
using ArTestCmd;
namespace ArTestCmd
{
class MainClass
{
public static void Main (string[] args)
{
String configFile = @"/home/si/Projects/ArTestCmd/CastleAR.config";
XmlConfigurationSource source = new XmlConfigurationSource(configFile);
ActiveRecordStarter.Initialize(source, typeof(Pc));
ActiveRecordStarter.UpdateSchema();
Pc pc = new Pc();
pc.name = "blah";
pc.Create();
}
}
[ActiveRecord]
public class Pc : ActiveRecordBase<Pc>
{
[PrimaryKey]
public int PcId { get; set; }
[Property (NotNull=true,Unique=true)]
public String name { get; set; }
}
}
Вот трассировка стека:
Unhandled Exception: NHibernate.HibernateException: Could not create the driver from NHibernate.Driver.MySqlDataDriver. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Configuration.ConfigurationErrorsException: Failed to find or load the registered .Net Framework Data Provider 'MySql.Data.MySqlClient'.
at System.Data.Common.DbProviderFactories.GetFactory (System.String providerInvariantName) [0x00000] in <filename unknown>:0
at NHibernate.Driver.ReflectionBasedDriver..ctor (System.String providerInvariantName, System.String driverAssemblyName, System.String connectionTypeName, System.String commandTypeName) [0x00000] in <filename unknown>:0
at NHibernate.Driver.MySqlDataDriver..ctor () [0x00000] in <filename unknown>:0
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
--- End of inner exception stack trace ---
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
at System.Reflection.MonoCMethod.Invoke (BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0
at System.Reflection.ConstructorInfo.Invoke (System.Object[] parameters) [0x00000] in <filename unknown>:0
at System.Activator.CreateInstance (System.Type type, Boolean nonPublic) [0x00000] in <filename unknown>:0
at System.Activator.CreateInstance (System.Type type) [0x00000] in <filename unknown>:0
at NHibernate.Bytecode.ActivatorObjectsFactory.CreateInstance (System.Type type) [0x00000] in <filename unknown>:0
at NHibernate.Connection.ConnectionProvider.ConfigureDriver (IDictionary`2 settings) [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at NHibernate.Connection.ConnectionProvider.ConfigureDriver (IDictionary`2 settings) [0x00000] in <filename unknown>:0
at NHibernate.Connection.ConnectionProvider.Configure (IDictionary`2 settings) [0x00000] in <filename unknown>:0
at NHibernate.Connection.ConnectionProviderFactory.NewConnectionProvider (IDictionary`2 settings) [0x00000] in <filename unknown>:0
at NHibernate.Cfg.SettingsFactory.BuildSettings (IDictionary`2 properties) [0x00000] in <filename unknown>:0
at NHibernate.Cfg.Configuration.BuildSettings () [0x00000] in <filename unknown>:0
at NHibernate.Cfg.Configuration.BuildSessionFactory () [0x00000] in <filename unknown>:0
at Castle.ActiveRecord.Framework.SessionFactoryHolder.GetSessionFactory (System.Type type) [0x00000] in <filename unknown>:0
at (wrapper remoting-invoke-with-check) Castle.ActiveRecord.Framework.SessionFactoryHolder:GetSessionFactory (System.Type)
at Castle.ActiveRecord.Framework.SessionFactoryHolder.CreateSession (System.Type type) [0x00000] in <filename unknown>:0
at (wrapper synchronized) Castle.ActiveRecord.Framework.SessionFactoryHolder:CreateSession (System.Type)
at Castle.ActiveRecord.ActiveRecordBase.InternalCreate (System.Object instance, Boolean flush) [0x00000] in <filename unknown>:0
at Castle.ActiveRecord.ActiveRecordBase.Create (System.Object instance) [0x00000] in <filename unknown>:0
at Castle.ActiveRecord.ActiveRecordBase.Create () [0x00000] in <filename unknown>:0
at IntervalTool.MainClass.schemaAction (System.String action, System.String filename) [0x00000] in <filename unknown>:0
at IntervalTool.MainClass.Main (System.String[] args) [0x00000] in <filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: NHibernate.HibernateException: Could not create the driver from NHibernate.Driver.MySqlDataDriver. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Configuration.ConfigurationErrorsException: Failed to find or load the registered .Net Framework Data Provider 'MySql.Data.MySqlClient'.
at System.Data.Common.DbProviderFactories.GetFactory (System.String providerInvariantName) [0x00000] in <filename unknown>:0
at NHibernate.Driver.ReflectionBasedDriver..ctor (System.String providerInvariantName, System.String driverAssemblyName, System.String connectionTypeName, System.String commandTypeName) [0x00000] in <filename unknown>:0
at NHibernate.Driver.MySqlDataDriver..ctor () [0x00000] in <filename unknown>:0
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
--- End of inner exception stack trace ---
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
at System.Reflection.MonoCMethod.Invoke (BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0
at System.Reflection.ConstructorInfo.Invoke (System.Object[] parameters) [0x00000] in <filename unknown>:0
at System.Activator.CreateInstance (System.Type type, Boolean nonPublic) [0x00000] in <filename unknown>:0
at System.Activator.CreateInstance (System.Type type) [0x00000] in <filename unknown>:0
at NHibernate.Bytecode.ActivatorObjectsFactory.CreateInstance (System.Type type) [0x00000] in <filename unknown>:0
at NHibernate.Connection.ConnectionProvider.ConfigureDriver (IDictionary`2 settings) [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at NHibernate.Connection.ConnectionProvider.ConfigureDriver (IDictionary`2 settings) [0x00000] in <filename unknown>:0
at NHibernate.Connection.ConnectionProvider.Configure (IDictionary`2 settings) [0x00000] in <filename unknown>:0
at NHibernate.Connection.ConnectionProviderFactory.NewConnectionProvider (IDictionary`2 settings) [0x00000] in <filename unknown>:0
at NHibernate.Cfg.SettingsFactory.BuildSettings (IDictionary`2 properties) [0x00000] in <filename unknown>:0
at NHibernate.Cfg.Configuration.BuildSettings () [0x00000] in <filename unknown>:0
at NHibernate.Cfg.Configuration.BuildSessionFactory () [0x00000] in <filename unknown>:0
at Castle.ActiveRecord.Framework.SessionFactoryHolder.GetSessionFactory (System.Type type) [0x00000] in <filename unknown>:0
at (wrapper remoting-invoke-with-check) Castle.ActiveRecord.Framework.SessionFactoryHolder:GetSessionFactory (System.Type)
at Castle.ActiveRecord.Framework.SessionFactoryHolder.CreateSession (System.Type type) [0x00000] in <filename unknown>:0
at (wrapper synchronized) Castle.ActiveRecord.Framework.SessionFactoryHolder:CreateSession (System.Type)
at Castle.ActiveRecord.ActiveRecordBase.InternalCreate (System.Object instance, Boolean flush) [0x00000] in <filename unknown>:0
at Castle.ActiveRecord.ActiveRecordBase.Create (System.Object instance) [0x00000] in <filename unknown>:0
at Castle.ActiveRecord.ActiveRecordBase.Create () [0x00000] in <filename unknown>:0
at IntervalTool.MainClass.schemaAction (System.String action, System.String filename) [0x00000] in <filename unknown>:0
at IntervalTool.MainClass.Main (System.String[] args) [0x00000] in <filename unknown>:0