FluentNhibernate TypeLoadException
本文关键字:TypeLoadException FluentNhibernate | 更新日期: 2023-09-27 17:58:48
我正试图使用Fluenthibernate构建一个示例MVC3项目,当我试图创建会话工厂时,我得到了一个typeloadexception。
会话工厂
//using System;
//using NHibernate;
//using NHibernate.Cfg;
//using FluentNHibernate.Cfg;
//using FluentNHibernate.Cfg.Db;
//using System.Collections.Generic;
//using System.Linq;
//using System.Web;
//using System.Web.Mvc;
public class SessionProvider
{
public SessionProvider ()
{
}
public static ISessionFactory BuildFactory()
{
return Fluently.Configure()//Explosion here
.Database(MySQLConfiguration.Standard.ConnectionString(
c => c.FromConnectionStringWithKey("DashboardModels")
))
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<Accounts>())
.BuildSessionFactory();
}
}
Global。Asax
public class MvcApplication : System.Web.HttpApplication
{
public static ISessionFactory SessionFactory =
SessionProvider.BuildFactory();
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
}
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
}
}
异常
System.TypeInitializationException: An exception was thrown by the type initializer for
System.Web.Configuration.WebConfigurationManager ---> System.Exception: Method not found: 'System.Configuration.ConfigurationManager.get_ConfigurationFactory'.
--- End of inner exception stack trace ---
at (wrapper xdomain-invoke) System.AppDomain:DoCallBack (System.CrossAppDomainDelegate)
at (wrapper remoting-invoke-with-check) System.AppDomain:DoCallBack (System.CrossAppDomainDelegate)
at System.Web.Hosting.ApplicationHost.CreateApplicationHost (System.Type hostType, System.String virtualDir, System.String physicalDir) [0x00000] in <filename unknown>:0
at Mono.WebServer.VPathToHost.CreateHost (Mono.WebServer.ApplicationServer server, Mono.WebServer.WebSource webSource) [0x00000] in <filename unknown>:0
at Mono.WebServer.XSP.Server.RealMain (System.String[] args, Boolean root, IApplicationHost ext_apphost, Boolean quiet) [0x00000] in <filename unknown>:0
at Mono.WebServer.XSP.Server.Main (System.String[] args) [0x00000] in <filename unknown>:0
我过去在其他地方使用过这个确切的代码,没有任何问题,我不知道可能是什么问题。我是不是做错了什么?
我已经了解到,如果你在Monoddevelop中有任何错误,只需删除你的项目,把你的笔记本电脑扔到窗外,然后你就可以从它后面跳出来了。:p
老实说,我不得不删除这个项目,使用备份,并按照我最初采取的步骤进行操作,结果成功了。因此,很抱歉,我唯一的建议是在这一过程中保存许多备份。基本上,如果你的输出中有任何错误,但在构建时没有。只需删除它,然后重试。一旦编译器被弄糊涂了,就需要上帝来修复它。