| 
					
						 Hi, i've got some Unit Tests that i can't fix in VB.NET 2005.  It always generate Casting Exception.  In VB.NET 2003, All Unit Tests are running sucessfully.  
 
 I tried several things:
 
 I changed all of the IList for the Generic type, i.e: IList(of T);
 I changed the lazy binding to false but that didn't do it!  
 I read the FAQ section and I searched for a while on the forum but I didn't find anything that seems similar to my problem
 
 apart from a page which talked about using the GoF Visitor design pattern.  But I read about it, and I thank that wouldn't help!
 
  Help me please!!!  I want to keep NHibernate in our developement practice.  Thank You in advance.
  Michel Desgroseillers. 
 
 P.S: If you need info, just tell me, i hope it's clear enough...
 
 NHibernate 1.2.0.Alpha1: 
 
 Equipment.hbm.xml:
 Start
 <?xml version="1.0" encoding="utf-8" ?>
 <hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" schema="dbo">
   <class name="Model.EquipmentSAT, Model" table="EquipmentSAT" 
          dynamic-update="true" dynamic-insert="true" discriminator-value="E" >
     <id name="EquipmentID" column="EquipmentID">
       <generator class="identity" />
     </id>
     
     <discriminator column="EquipmentType" type="String" length="1" />    
     
     <property name="Name" column="Name" type="String"/>
     
 	<!-- —Début Tag (À copier) -->
 	<bag name="Grouplst" table="Group_Equipment" inverse="false" lazy="true" cascade="save-update">
 		<key column="EquipmentFID"/>
 		<many-to-many class="Model.GroupSAT, Model" column="GroupFID"/>
 	</bag>
     <!-- —Fin Tag (À copier) -->       
   
 	<!-- —Début Tag (À copier) -->
        <many-to-one name="theAlarm" column="AlarmFID" unique="false" class="Model.AlarmSAT, Model" />
     <!-- —Fin Tag (À copier) -->           
     
     <!-- —Début Tag (À copier) -->
 	<bag name="HWConnexionlst" table="Equipment_HWConnexion" inverse="false" lazy="true" cascade="save-update">
 		<key column="EquipmentFID"/>
 		<many-to-many  class="Model.HWConnexionSAT, Model" column="HWConnexionFID"/>
 	</bag>
     <!-- —Fin Tag (À copier) -->
     
     <!-- —Début Tag (À copier) -->
 	<bag name="EquipmentCategorylst" table="Equipment_EquipmentCategory" inverse="false" lazy="true" cascade="save-update">
 		<key column="EquipmentFID"/>
 		<many-to-many  class="Model.EquipmentCategorySAT, Model" column="EquipmentCategoryFID"/>
 	</bag>
     <!-- —Fin Tag (À copier) -->
     
     <subclass name="Model.SystemM1SAT, Model" discriminator-value="M">
       <!-- —Début Tag (À copier) -->
 		<bag name="M1LAPWlst" table="SystemM1_M1LAPW" inverse="false" lazy="true" cascade="save-update">
 			<key column="SystemM1FID"/>
 			<many-to-many  class="Model.M1LAPWSAT, Model" column="M1LAPWFID"/>
 		</bag>
     <!-- —Fin Tag (À copier) --> 
 		<property name="UserCode1" column="UserCode1" type="String"/>
 		<property name="Password1" column="Password1" type="String"/>
 		<property name="UserCode2" column="UserCode2" type="String"/>
 		<property name="Password2" column="Password2" type="String"/>
 		<property name="OldUserCode2" column="OldUserCode2" type="String"/>
 		<property name="OldPassword2" column="OldPassword2" type="String"/>		
     </subclass>
     
 	<subclass name="Model.SystemCallPilotSAT, Model" discriminator-value="C">
 		<property name="UserCode1" column="UserCode1" type="String"/>
 		<property name="Password1" column="Password1" type="String"/>
     </subclass>    
     
   </class>
 </hibernate-mapping>
 Finish
 
 HWConnexionSAT.hbm.xml:
 Start
 <?xml version="1.0" encoding="utf-8" ?>
 <hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" schema="dbo">
   <class name="Model.HWConnexionSAT, Model" discriminator-value="C">
     <id name="HWConnexionID" type="Int32" column="HWConnexionID">
       <generator class="identity" />
     </id>
     <discriminator force="true" column="HWConnexionType" type="String" length="1" />
     <property name="Name" column="Name" type="String" />
 
     <subclass name="Model.ModemServerConnexionSAT, Model" discriminator-value="S">
     
 		<property name="PhoneNumber" column="PhoneNumber" type="String" />	
 		
     <!-- —Début Tag (À copier) -->
 		<bag name="ModemConfiglst" table="ModemServerConnexion_ModemConfig" 
 		     inverse="false" lazy="true" cascade="save-update">
 			<key column="ModemServerConnexionFID"/>
 			<many-to-many  class="Model.ModemConfigSAT, Model" 
 			               column="ModemConfigFID"/>
 		</bag>
     <!-- —Fin Tag (À copier) -->
     
         <!-- —Début Tag (À copier) -->
 		<bag name="ModemServerlst" table="ModemServerConnexion_ModemServer" 
 		     inverse="false" lazy="true" cascade="save-update">
 			<key column="ModemServerConnexionFID"/>
 			<many-to-many  class="Model.ModemServerSAT, Model" 
 			               column="ModemServerFID"/>
 		</bag>
     <!-- —Fin Tag (À copier) 
         <property name="InitStr" column="InitStr" type="String" /> -->
     
     </subclass>
     
     <subclass name="Model.SSHConnexionSAT, Model" discriminator-value="H">
         <property name="IPAddress" column="IPAddress" type="String" />
         <property name="IPPort" column="IPPort" type="Int16" />
     </subclass>
     
     <subclass name="Model.TelnetConnexionSAT, Model" discriminator-value="T">
 		<property name="InitCommand" column="InitCommand" type="String" />
 		<property name="InitConfirmation" column="InitConfirmation" type="String" />		
         <property name="IPAddress" column="IPAddress" type="String" />
         <property name="IPPort" column="IPPort" type="Int16" />    
     </subclass>
 
   </class>
 </hibernate-mapping>
 Finish
 
 ModemServerSAT.hbm.xml:
 Start
 <?xml version="1.0" encoding="utf-8" ?>
 <hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" schema="dbo">
   <class name="Model.ModemServerSAT, Model" table="ModemServerSAT" dynamic-update="true" dynamic-insert="true" >
     <id name="ModemServerID" column="ModemServerID">
       <generator class="identity" />
     </id>
     
     <property name="Name" column="Name" type="String"/>
     <property name="ConfirmationMessage" column="ConfirmationMessage" type="String"/>
     <property name="Password" column="Password" type="String"/>
     <property name="PasswordPrompt" column="PasswordPrompt" type="String"/>
     <property name="UserCode" column="UserCode" type="String"/>
     <property name="UserCodePrompt" column="UserCodePrompt" type="String"/>
     
     <!-- —Début Tag (À copier) -->
 		<bag name="ModemPortlst" table="ModemServer_ModemPort" inverse="false" lazy="true" cascade="save-update">
 			<key column="ModemServerFID"/>
 			<many-to-many  class="Model.ModemPortSAT, Model" column="ModemPortFID"/>
 		</bag>
     <!-- —Fin Tag (À copier) -->
  
   </class>
 </hibernate-mapping>
 Finish
 
 ModemPortSAT.hbm.xml:
 Start
 <?xml version="1.0" encoding="utf-8" ?>
 <hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" schema="dbo">
   <class name="Model.ModemPortSAT, Model" table="ModemPortSAT" dynamic-update="true" dynamic-insert="true" >
     <id name="ModemPortID" column="ModemPortID">
       <generator class="identity" />
     </id>
     <property name="IPAddress" column="IPAddress" type="String"/>
 	<property name="IPPort" column="IPPort" type="Int16"/>
 	<property name="IsPortEnabled" column="IsPortEnabled" type="Boolean"/>
  
   </class>
 </hibernate-mapping>
 Finish
 
 EquipmentSAT.vb:
 Start
 Imports System.Collections
 
 Namespace Model
 
    Public Class EquipmentSAT
 
       Private _EquipmentID As Int32
 
       Private _Name As String
 
       '<link>association</link>
       '  <supplierCardinality>0..*</supplierCardinality>
       '  <associates>Model.GroupSAT</associates>
       '  <directed>True</directed>
       Private _Grouplst As Generic.IList(Of GroupSAT)
 
       '<directed>True</directed>
       '  <supplierCardinality>0..1</supplierCardinality>
       Dim _theAlarm As AlarmSAT
 
       '<link>association</link>
       '  <supplierCardinality>0..*</supplierCardinality>
       '  <associates>Model.HWConnexionSAT</associates>
       '  <directed>True</directed>
       Private _HWConnexionlst As Generic.IList(Of HWConnexionSAT)
 
       '<link>association</link>
       '  <supplierCardinality>0..*</supplierCardinality>
       '  <associates>Model.EquipmentCategorySAT</associates>
       '  <directed>True</directed>
       Private _EquipmentCategorylst As Generic.IList(Of EquipmentCategorySAT)
 
       Private _isSchedulerTaskActivated As System.Object
 
       Private _IsTelnetUserActivated As System.Object
 
       Public Overridable Property EquipmentID() As Int32
          Get
             EquipmentID = _EquipmentID
          End Get
          Set(ByVal Value As Int32)
             _EquipmentID = Value
          End Set
       End Property
 
       Public Overridable Property Name() As String
          Get
             Name = _Name
          End Get
          Set(ByVal Value As String)
             _Name = Value
          End Set
       End Property
 
       Public Overridable Property Grouplst() As Generic.IList(Of GroupSAT)
          Get
             Grouplst = _Grouplst
          End Get
          Set(ByVal Value As Generic.IList(Of GroupSAT))
             _Grouplst = Value
          End Set
       End Property
 
       Public Overridable Property theAlarm() As AlarmSAT
          Get
             Return _theAlarm
          End Get
          Set(ByVal Value As AlarmSAT)
             _theAlarm = Value
          End Set
       End Property
 
       Public Overridable Property HWConnexionlst() As Generic.IList(Of HWConnexionSAT)
          Get
             HWConnexionlst = _HWConnexionlst
          End Get
          Set(ByVal Value As Generic.IList(Of HWConnexionSAT))
             _HWConnexionlst = Value
          End Set
       End Property
 
       Public Overridable Property EquipmentCategorylst() As Generic.IList(Of EquipmentCategorySAT)
          Get
             EquipmentCategorylst = _EquipmentCategorylst
          End Get
          Set(ByVal Value As Generic.IList(Of EquipmentCategorySAT))
             _EquipmentCategorylst = Value
          End Set
       End Property
 
       Public Overridable Property isSchedulerTaskActivated() As System.Object
          Get
             isSchedulerTaskActivated = _isSchedulerTaskActivated
          End Get
          Set(ByVal Value As System.Object)
             _isSchedulerTaskActivated = Value
          End Set
       End Property
 
       Public Overridable Property IsTelnetUserActivated() As System.Object
          Get
             IsTelnetUserActivated = _IsTelnetUserActivated
          End Get
          Set(ByVal Value As System.Object)
             _IsTelnetUserActivated = Value
          End Set
       End Property
    End Class
 
 End Namespace
 Finish
 
 HWConnexionSAT.vb:
 Start
 Namespace Model
 
    Public Class HWConnexionSAT
 
       Private _HWConnexionID As Int32
 
       Private _Name As String
 
       Private _isConnexionActivated As System.Object
 
       Public Overridable Property HWConnexionID() As Int32
          Get
             HWConnexionID = _HWConnexionID
          End Get
          Set(ByVal Value As Int32)
             _HWConnexionID = Value
          End Set
       End Property
 
       Public Overridable Property Name() As String
          Get
             Name = _Name
          End Get
          Set(ByVal Value As String)
             _Name = Value
          End Set
       End Property
 
       Public Overridable Property isConnexionActivated() As System.Object
          Get
             isConnexionActivated = _isConnexionActivated
          End Get
          Set(ByVal Value As System.Object)
             _isConnexionActivated = Value
          End Set
       End Property
 
    End Class
 
 End Namespace
 Finish
 
 ModemServerSAT.vb:
 Start
 Namespace Model
 
    Public Class ModemServerSAT
 
       Private _ModemServerID As Int32
 
       Private _Name As String
 
       Private _ConfirmationMessage As String
 
       Private _Password As String
 
       Private _PasswordPrompt As String
 
       Private _UserCode As String
 
       Private _UserCodePrompt As String
 
       '<link>association</link>
       '  <supplierCardinality>0..*</supplierCardinality>
       '  <associates>Model.ModemPortSAT</associates>
       '  <directed>True</directed>
       Private _ModemPortlst As Generic.IList(Of ModemPortSAT)
 
       Public Overridable Property ModemServerID() As Int32
          Get
             ModemServerID = _ModemServerID
          End Get
          Set(ByVal Value As Int32)
             _ModemServerID = Value
          End Set
       End Property
 
       Public Overridable Property Name() As String
          Get
             Name = _Name
          End Get
          Set(ByVal Value As String)
             _Name = Value
          End Set
       End Property
 
       Public Overridable Property ConfirmationMessage() As String
          Get
             ConfirmationMessage = _ConfirmationMessage
          End Get
          Set(ByVal Value As String)
             _ConfirmationMessage = Value
          End Set
       End Property
 
       Public Overridable Property Password() As String
          Get
             Password = _Password
          End Get
          Set(ByVal Value As String)
             _Password = Value
          End Set
       End Property
 
       Public Overridable Property PasswordPrompt() As String
          Get
             PasswordPrompt = _PasswordPrompt
          End Get
          Set(ByVal Value As String)
             _PasswordPrompt = Value
          End Set
       End Property
 
       Public Overridable Property UserCode() As String
          Get
             UserCode = _UserCode
          End Get
          Set(ByVal Value As String)
             _UserCode = Value
          End Set
       End Property
 
       Public Overridable Property UserCodePrompt() As String
          Get
             UserCodePrompt = _UserCodePrompt
          End Get
          Set(ByVal Value As String)
             _UserCodePrompt = Value
          End Set
       End Property
 
       Public Overridable Property ModemPortlst() As Generic.IList(Of ModemPortSAT)
          Get
             ModemPortlst = _ModemPortlst
          End Get
          Set(ByVal Value As Generic.IList(Of ModemPortSAT))
             _ModemPortlst = Value
          End Set
       End Property
 
    End Class
 
 End Namespace
 Finish
 
 ModemPortSAT.vb:
 Start
 Namespace Model
 
    Public Class ModemPortSAT
 
       Private _ModemPortID As Int32
 
       Private _IPAddress As String
 
       Private _IPPort As Int16
 
       Private _IsPortEnabled As Boolean
 
       Public Overridable Property ModemPortID() As Int32
          Get
             ModemPortID = _ModemPortID
          End Get
          Set(ByVal Value As Int32)
             _ModemPortID = Value
          End Set
       End Property
 
       Public Overridable Property IPAddress() As String
          Get
             IPAddress = _IPAddress
          End Get
          Set(ByVal Value As String)
             _IPAddress = Value
          End Set
       End Property
 
       Public Overridable Property IPPort() As Int16
          Get
             IPPort = _IPPort
          End Get
          Set(ByVal Value As Int16)
             _IPPort = Value
          End Set
       End Property
 
       Public Overridable Property IsPortEnabled() As Boolean
          Get
             IsPortEnabled = _IsPortEnabled
          End Get
          Set(ByVal Value As Boolean)
             _IsPortEnabled = Value
          End Set
       End Property
 
    End Class
 
 End Namespace
 Finish
 
 Here's the Configuration file(Embedded Resource) in my /bin directory...
 Start
 <?xml version="1.0" encoding="utf-8" ?>
 <hibernate-configuration  xmlns="urn:nhibernate-configuration-2.0" >
 	<session-factory name="Model">
 		<!-- properties -->
 		<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
 		<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
 		<property name="connection.connection_string">Server=10.4.163.210;User Id=sa;Password=mystery!;initial catalog=SAT2</property>
 		<property name="dialect">NHibernate.Dialect.MsSql2000Dialect</property>
 		<!-- mapping files -->
 		<mapping assembly="Model" />
 	</session-factory>	
 </hibernate-configuration>
 Finish
 
 
 This is one of the TestUnit which generate an exception:
  <Test(), Category("Update")> Sub Test_23_UpdateHWConnexionName()       _myConnexionCtrl.OpenConnexionCtrl()
        _myEquipmentCtrl.ConnexionCtrl = _myConnexionCtrl.MainConnCtrl
        Dim Equipmentlist As Generic.IList(Of EquipmentSAT) = _myEquipmentCtrl.LoadAllEquipmentCtrl()       Assert.IsNotNull(Equipmentlist, vbCrLf & "La liste Equipment est vide")
        Dim theEquipment As EquipmentSAT = Equipmentlist.Item(Equipmentlist.Count - 1)
  This is where it cast the HWConnexion List to a 'CProxyTypeHWConnexionSATModel_INHibernateProxy1 object list instead of the ModemServerSAT object list.       Dim theHWConnexion As HWConnexionSAT = theEquipment.HWConnexionlst(theEquipment.HWConnexionlst.Count - 1)
        Try          theHWConnexion.Name = theHWConnexion.Name & "*"
  It failed in this function call, because the param is a ModemServerSAT type and instead, it received a Proxy object( generated by NHibernate...)          If Not _myModemServerConnexionCtrl.UpdateModemServerConnexionCtrl(CType(theHWConnexion, ModemServerConnexionSAT)) Then             Throw New System.Exception          End If
        Catch ex As Exception          Assert.Fail(vbCrLf & "ne peut mettre à jour HWConnexion dans la transaction UpdateHWConnexionName:" & ex.ToString)       End Try
        Dim thename As String = theEquipment.HWConnexionlst(theEquipment.HWConnexionlst.Count - 1).Name       Assert.IsTrue(theHWConnexion.Name = thename, vbCrLf & "ne peut synchroniser le HWConnexion dans la transaction UpdateHWConnexionName")
        _myConnexionCtrl.CloseConnexionCtrl()    End Sub :
 
 UT_GroupRelation - equipx.EquipmentID = 5 TestCase 'UnitTestLayer.UT_35_GroupRelations.AllUnitTests' failed: System.InvalidCastException : Unable to cast object of type 'CProxyTypeHWConnexionSATModel_INHibernateProxy1' to type 'Model.ModemServerConnexionSAT'. 	C:\Code\SAT-2005_HBM_Spring\UnitTestLayer\UT_35_GroupRelations.vb(432,0): at UnitTestLayer.UT_35_GroupRelations.Test_31_RefreshGroup() 	C:\Code\SAT-2005_HBM_Spring\UnitTestLayer\UT_35_GroupRelations.vb(91,0): at UnitTestLayer.UT_35_GroupRelations.AllUnitTests()
  TestFixture failed::
 
 SQL Server Version:
 Microsoft SQL Enterprise 2000: 
					
  
						
					 |