2013-01-08 39 views
5

संकलित नहीं कर सका मैं NHibernate में नौसिखिया हूं। मैं SQLite के साथ इस ओआरएम का उपयोग करने की कोशिश कर रहा हूँ। projectNHibernate.MappingException: मैपिंग दस्तावेज़

Product.cs

namespace Stock.Models.Classes 
{ 
    class Product 
    { 
     public virtual string Name {get; set;} 
     public virtual int Id { get; set; } 
     public virtual decimal Price { get; set; } 
     public virtual decimal Quantity { get; set; } 
    } 
} 

Product.hbm.xml

<?xml version="1.0" encoding="utf-8" ?> 
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" 
        assembly="Stock.Models" 
        namespace="Stock.Models.Classes"> 
    <class name="Product" table="products"> 
    <id name="Id"> 
     <generator class="int" /> 
    </id> 
    <property name="Name" /> 
    <property name="Price" /> 
    <property name="Quantity" /> 
    </class> 
</hibernate-mapping> 

hibernate.cfg.xml

: मैं निम्नलिखित है

मैं प्रोग्राम.cs में परीक्षण करने की कोशिश कर रहा हूं। Program.cs

namespace Stock 
{ 
    static class Program 
    { 
     /// <summary> 
     /// The main entry point for the application. 
     /// </summary> 
     [STAThread] 
     static void Main() 
     { 
      Application.EnableVisualStyles(); 
      Application.SetCompatibleTextRenderingDefault(false); 
      //Application.Run(new Form1()); 
      var cfg = new Configuration(); 
      cfg.Configure(); 
       cfg.AddAssembly(typeof(Product).Assembly); 
     } 
    } 
} 

रन टाइम में पॉप-अप में संदेश के साथ लाइन cfg.AddAssembly(typeof(Product).Assembly); में एप्लिकेशन टूट जाता है: Could not compile the mapping document: Stock.Models.Mappings.Product.hbm.xml और कंसोल में:

The thread 'vshost.LoadReference' (0x10a8) has exited with code 0 (0x0). 
'Stock.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\...\Projects\WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\Stock.exe', Symbols loaded. 
'Stock.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\...\Projects\WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\NHibernate.dll' 
'Stock.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 
'Stock.vshost.exe' (Managed (v4.0.30319)): Loaded 'jsw3tdap' 
'Stock.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\...\Projects\WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\Iesi.Collections.dll' 
A first chance exception of type 'NHibernate.MappingException' occurred in NHibernate.dll 

मैं में आज़माएं/कैच जोड़ते हैं Program.cs:

try 
    { 
     cfg.AddAssembly(typeof(Product).Assembly); 
    } 
catch (Exception e) { Console.WriteLine(e); } 

मैं (चोर एकमात्र):

A first chance exception of type 'NHibernate.MappingException' occurred in NHibernate.dll 
NHibernate.MappingException: Could not compile the mapping document: Stock.Models.Mappings.Product.hbm.xml ---> NHibernate.MappingException: persistent class Stock.Models.Classes.Product, Stock.Models not found ---> System.IO.FileNotFoundException: Could not load file or assembly 'Stock.Models' or one of its dependencies. El sistema no puede encontrar el archivo especificado. 
    at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) 
    at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) 
    at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection, Boolean suppressSecurityChecks) 
    at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) 
    at System.Reflection.Assembly.Load(String assemblyString) 
    at NHibernate.Util.ReflectHelper.TypeFromAssembly(AssemblyQualifiedTypeName name, Boolean throwOnError) 
    at NHibernate.Util.ReflectHelper.ClassForName(String name) 
    at NHibernate.Cfg.XmlHbmBinding.Binder.ClassForFullNameChecked(String fullName, String errorMessage) 
    --- End of inner exception stack trace --- 
    at NHibernate.Cfg.XmlHbmBinding.Binder.ClassForFullNameChecked(String fullName, String errorMessage) 
    at NHibernate.Cfg.XmlHbmBinding.Binder.ClassForNameChecked(String name, Mappings mappings, String errorMessage) 
    at NHibernate.Cfg.XmlHbmBinding.ClassBinder.BindClass(IEntityMapping classMapping, PersistentClass model, IDictionary`2 inheritedMetas) 
    at NHibernate.Cfg.XmlHbmBinding.RootClassBinder.Bind(HbmClass classSchema, IDictionary`2 inheritedMetas) 
    at NHibernate.Cfg.XmlHbmBinding.MappingRootBinder.AddRootClasses(HbmClass rootClass, IDictionary`2 inheritedMetas) 
    at NHibernate.Cfg.XmlHbmBinding.MappingRootBinder.AddEntitiesMappings(HbmMapping mappingSchema, IDictionary`2 inheritedMetas) 
    at NHibernate.Cfg.XmlHbmBinding.MappingRootBinder.Bind(HbmMapping mappingSchema) 
    at NHibernate.Cfg.Configuration.AddDeserializedMapping(HbmMapping mappingDocument, String documentFileName) 
    --- End of inner exception stack trace --- 
    at NHibernate.Cfg.Configuration.LogAndThrow(Exception exception) 
    at NHibernate.Cfg.Configuration.AddDeserializedMapping(HbmMapping mappingDocument, String documentFileName) 
    at NHibernate.Cfg.Configuration.AddValidatedDocument(NamedXmlDocument doc) 
    at NHibernate.Cfg.Configuration.ProcessMappingsQueue() 
    at NHibernate.Cfg.Configuration.AddDocumentThroughQueue(NamedXmlDocument document) 
    at NHibernate.Cfg.Configuration.AddXmlReader(XmlReaThe thread 'vshost.RunParkingWindow' (0x1700) has exited with code 0 (0x0). 
The thread '<No Name>' (0x5d4) has exited with code 0 (0x0). 
The program '[4428] Stock.vshost.exe: Managed (v4.0.30319)' has exited with code 0 (0x0). 
The program '[4428] Stock.vshost.exe: Program Trace' has exited with code 0 (0x0). 
der hbmReader, String name) 
    at NHibernate.Cfg.Configuration.AddInputStream(Stream xmlInputStream, String name) 
    at NHibernate.Cfg.Configuration.AddResource(String path, Assembly assembly) 
    at NHibernate.Cfg.Configuration.AddAssembly(Assembly assembly) 
    at Stock.Program.Main() in C:\Users\Cristhian\documents\visual studio 2010\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Program.cs:line 25 

एक्सएमएल फाइल Embedded Resource और Copy Always के रूप में seted कर रहे हैं। मैपिंग दस्तावेज़ को संकलित क्यों नहीं करता है Stock.Models.Mappings.Product.hbm.xml? क्या यह फ़ाइल प्रारूप या लाइब्रेरी डीएलएल समस्या की समस्या है?

उत्तर

9

ठीक है, Stock.Models असेंबली मौजूद नहीं है। केवल विधानसभा कि मौजूद है Stock है, तो आप उसके अनुसार अपनी मैपिंग फ़ाइल को बदलने की जरूरत:

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" 
        assembly="Stock" 
        namespace="Stock.Models.Classes"> 
0

मैं एक ही समस्या थी। यह "असेंबली" और "नेमस्पेस" में है। मैंने इसे हल करने के लिए क्या किया था, आपके उदाहरण में, "स्टॉक" दोनों का नाम था।

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" 
        assembly="Stock" 
        namespace="Stock"> 
0

मेरी मैपिंग फ़ाइलों को सही होने के बावजूद मुझे वही त्रुटि मिल रही थी।

C:\inetpub\wwwroot\wss\VirtualDirectories\<port>\bin फ़ोल्डर में अद्यतन असेंबली मौजूद नहीं हैं। जब मैंने उन्हें हाथ से कॉपी किया तो यह काम किया।

मुझे कोई स्पष्टीकरण नहीं है कि उन्हें अभी तक क्यों कॉपी नहीं किया जा रहा है या यहां तक ​​कि यदि वे होना चाहिए, तो मैं इसे केवल एक उत्तर के रूप में पोस्ट कर रहा हूं क्योंकि यह मेरी समस्या को ठीक करता है और मैंने इसे नहीं देखा है कहीं और ऑनलाइन दस्तावेज।

1

आपको hbm.xml फ़ाइल में असेंबली और नेमस्पेस जोड़ना चाहिए। यह जानने के लिए कि किस प्रकार का नाम टाइपऑफ (yourModel) का उपयोग करें। एस्प्लोरस और पूर्ण नाम की जांच करें। असेंबली और कक्षा का नाम समान नहीं है।