ASP.NET的nhibernate-无法添加程序集ORM\u dscnew

ASP.NET的nhibernate-无法添加程序集ORM\u dscnew,nhibernate,Nhibernate,我是nhibernate的新手。我面临以下问题: Exception thrown: 'NHibernate.MappingException' in NHibernate.dll NHibernate.MappingException: Could not add assembly ORM_dscnew ---> System.IO.FileNotFoundException: Could not load file or assembly 'ORM_dscnew' or one of

我是nhibernate的新手。我面临以下问题:

Exception thrown: 'NHibernate.MappingException' in NHibernate.dll
NHibernate.MappingException: Could not add assembly ORM_dscnew ---> System.IO.FileNotFoundException: Could not load file or assembly 'ORM_dscnew' or one of its dependencies. The system cannot find the file specified.
   at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection)
   at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
   at System.Reflection.Assembly.Load(String assemblyString)
   at NHibernate.Cfg.Configuration.AddAssembly(String assemblyName)
   --- End of inner exception stack trace ---
   at NHibernate.Cfg.Configuration.LogAndThrow(Exception exception)
   at NHibernate.Cfg.Configuration.AddAssembly(String assemblyName)
   at viroffice.ORM_sessionf.Init() in D:\GDrive\Projects\VirOffice\viroffice\DataObjects\ORM_sessionf.vb:line 7
执行函数时:

 Private Shared sFactory As NHibernate.ISessionFactory

    Private Shared Sub Init()
        Dim config As New NHibernate.Cfg.Configuration()
        Try
            config.AddAssembly("ORM_dscnew")
            sFactory = config.BuildSessionFactory()
        Catch ex As Exception
            System.Diagnostics.Debug.WriteLine(ex)

            Exit Sub

        End Try

    End Sub
在执行上述函数时,我得到了错误

ORM_dscnew.hbm.xml:

<?xml version="1.0" encoding="utf-8" ?>

<hibernate-mapping xmlns = "urn:nhibernate-mapping-2.2" namespace = "viroffice.DataObjects" assembly = "viroffice">

  <class name = "ORM_dscnew" table="dsc_new">
    <id name = "new_id">
      <generator class = "native"/>
    </id>

    <property name = "vnm" />
    <property name = "vcn_name" />
    <property name = "vref" />
    <property name = "vcn_per" />
    <property name = "vcn_no" />
    <property name = "vcn_email" />
    <property name = "vcn_email1" />
    <property name = "vrmks" />
    <property name = "vstatus" />
    <property name = "vapp_id" />
    <property name = "vmob_ver" />
    <property name = "vchg_code" />
  </class>

</hibernate-mapping>

请告知需要做什么?

使用
AddAssembly(“ORM\u dscnew”)
调用
System.Reflection.Assembly.Load(“ORM\u dscnew”)
。在您的情况下,.Net Framework无法找到您的程序集并生成
FileNotFoundException

NHibernate只需将其包装在一个
映射异常中
。根本问题是找不到程序集(或其依赖项之一…)。声明程序集名称应该是一个长名称,并且您的代码只提供简单名称,因此这可能是您的问题

无论如何,就个人而言,我喜欢通过从包含在其中的类型获取程序集来添加程序集。当然,这意味着您的工厂将需要对此类类型的引用

config.AddAssembly(typeof(ATypeInORM_dscnew).Assembly);

您是否已将hbm.xml文件设置为embadded Resources是。它已被设置为嵌入式资源。