These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]

Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: MappingException - Could not add assembly
PostPosted: Fri Sep 24, 2010 2:58 pm 

Joined: Fri Sep 24, 2010 1:53 pm
Posts: 2

I searched in the forum and even finding some related (some about mappingexception and some about assembly) I do not found any one about this two together. So, if there is any "famous" topic about this please tell me.

My solutions is organized in the fallowing way:
---Ordering.Console (console app)
---Ordering.Data (library)
---------Address.cs (and others)
---------Address.hbm.xml (and othersConfigurei todos os XML como Build Action Embedded Resource e Copy to
Output Directory Copy Always )

I configured all my hbm.XML as Embedded Resource in the Build Action and Copy Always in the Copy to Output Directory property.

Program code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate;
using NHibernate.Cfg;
using Ordering.Data;
using System.IO;
namespace Ordering.Console
    public class Program
        static void Main(string[] args)
            Configuration cfg = new Configuration();

cfg.Properties.Add(NHibernate.Cfg.Environment.ConnectionProvider, typeof(NHibernate.Connection.DriverConnectionProvider).AssemblyQualifiedNam e);

            cfg.Properties.Add(NHibernate.Cfg.Environment.Dialect, typeof(NHibernate.Dialect.MsSql2008Dialect).AssemblyQualifiedName);

cfg.Properties.Add(NHibernate.Cfg.Environment.ConnectionDriver, typeof(NHibernate.Driver.SqlClientDriver).AssemblyQualifiedName);

cfg.Properties.Add(NHibernate.Cfg.Environment.ConnectionString, "Server= (local)\

cfg.Properties.Add(NHibernate.Cfg.Environment.ProxyFactoryFactoryClass, typeof(NHibernate.ByteCode.Castle.ProxyFactoryFactory).AssemblyQualifiedNam e);

cfg.AddAssembly(typeof(Ordering.Data.Address).AssemblyQualifiedName); //the exception is throw here.

Could not add assembly Ordering.Data.Address, Ordering.Data,
Version=, Culture=neutral, PublicKeyToken=null.
Inner Exception:
{"Could not load file or assembly 'Ordering.Data.Address\\,
Ordering.Data\\, Version\\=\\, Culture\\=neutral\\,
PublicKeyToken\\=null' or one of its dependencies. The given assembly
name or codebase was invalid. (Exception from HRESULT:
0x80131047)":"Ordering.Data.Address\\, Ordering.Data\\, Version\
\=\\, Culture\\=neutral\\, PublicKeyToken\\=null"}.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Ordering.Data
    public class Address
        public Address() { }
        public Address(int _id, string _address1, string _address2,
string _city, string _state, string _zip)
            : this()
            this.Id = _id; this.Address1 = _address1; this.Address2 =
_address2; this.City = _city; this.State = _state; this.Zip = _zip;
        public virtual int Id { get; set; }
        public virtual string Address1 { get; set; }
        public virtual string Address2 { get; set; }
        public virtual string City { get; set; }
        public virtual string State { get; set; }
        public virtual string Zip { get; set; }
        //Foreing key
        public Contact Contact { get; set; }
        public IList<OrderHeader> BillToOrderHeaders { get; set; }
        public IList<OrderHeader> ShipToOrderHeaders { get; set; }


<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                   namespace="Ordering.Data" assembly="Ordering.Data">
  <class name="Address" table="Address">
    <id name="Id" type="Int32" unsaved-value="null">
      <column name="Id"/>
      <generator class="hilo"/>
    <property name="Address1" type="String">
      <column name="Address1" length="255" sql-type="varchar" not-
    <property name="Address2" type="String">
      <column name="Address2" length="255" sql-type="varchar" not-
    <property name="City" type="String">
      <column name="City" length="255" sql-type="varchar" not-
    <property name="State" type="String">
      <column name="State" length="2" sql-type="varchar" not-
    <property name="Zip" type="String">
      <column name="Zip" length="12" sql-type="varchar" not-
    <many-to-one name="Contact" class="Ordering.Data.Contact,
      <column name="Contact_Id" length="4" sql-type="int" not-
    <bag name="BillToOrderHeaders" inverse="true" cascade="all-delete-
      <key column="BillToAddress_Id"/>
      <one-to-many class="Ordering.Data.Common.OrderHeader,
    <bag name="ShipToOrderHeaders" inverse="true" cascade="all-delete-
      <key column="ShipToAddress_Id"/>
      <one-to-many class="Ordering.Data.Common.OrderHeader,

Both projects are .NET 3.5 framework.

Thanks for any help,

Pedro Dusso

Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.