【问题标题】:FluentNhibernate TypeLoadExceptionFluentNhibernate TypeLoadException
【发布时间】:2013-02-12 21:35:51
【问题描述】:

我正在尝试使用 FluentNhibernate 构建示例 MVC3 项目,当我尝试创建 sessionFactory 时遇到 typeloadexception。

SessionFactory

//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

我过去在其他地方使用过这个确切的代码没有问题,但我不知道可能是什么问题。我在这里做错了吗?

【问题讨论】:

  • 异常的信息是什么?
  • 原谅我,我用异常消息更新了问题
  • 是否有内部异常?
  • 这就是它给我的全部:/内部异常:(Null)
  • Arrrgh :(。我会尝试删除所有与 NH 相关的引用并再次逐步添加它们。

标签: c# asp.net-mvc-3 fluent-nhibernate monodevelop


【解决方案1】:

我了解到,如果您在 Monodevelop 中出现任何错误,只需删除您的项目,将您的笔记本电脑扔出窗外,然后您就有一个清晰的开口可以从它后面跳出来。 :P

老实说,我不得不删除该项目,使用备份并执行我最初采取的确切步骤并且它有效。所以很抱歉,我唯一的建议是在此过程中保存许多备份。基本上,如果您的输出中有任何错误,但在构建时没有。只需将其删除并重试。一旦编译器感到困惑,就需要上帝的作为来修复它。

【讨论】:

    猜你喜欢
    • 2019-10-19
    • 1970-01-01
    • 1970-01-01
    • 2011-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多