Tuesday, April 26, 2011

Structure map errors and their causes in Jcdc



Here is a cheat sheet I made of common Structure map errors, and all the different ways I've caused them.


Enjoy


Eric-


StructureMap Exception Code: 200 Could not find an Instance named "JCDC" for PluginType POCAdmin3G.DAL.Interfaces.ISessionManager

Answer: bootstrapper is not loading type, if it’s a session manager like above, check that the z.OfConcretetype stuff is loaded.
 
Check the bootstrap structure map file.
If that passes, check the connection to the DB

NHibernate.Cfg.HibernateConfigException: An exception occurred during configuration of persistence layer.

Answer:Probably can’t find the jcdcdbconifg.xml file, check the inner exception


 


 
StructureMap Exception Code: 202 - No D
efault Instance defined for PluginFamily JCDCHelper.Utilities.Interfaces.INetLog, JCDCHelper.Utilities, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null

Answers:


1.      Make sure it's scanning the assembly that contains the object you can't load:
x.Scan( y =>
{
y.Assembly(Assembly.GetAssembly(typeof(IWebAccess))); // JcdcHelper Utilities
y.Assembly(Assembly.GetAssembly(typeof(IUserMaintBLL))); // JcdcHelper.BLL
y.Assembly(Assembly.GetAssembly(typeof(IUserMaintDAL))); // JcdcHelper.DAL
y.Assembly(Assembly.GetAssembly(typeof(ICallDB))); // JcdcHelper.DALAccess
y.Assembly(Assembly.GetAssembly(typeof(ICenterDAL))); // CIS3G DAL
y.WithDefaultConventions();
});.

2.      Use objectFactory.WhatDoIHave() to see if the offending assembly is loaded or not.

3.      Check to make sure the spelling of the Concrete type is EXACTLY like the interface type, except for the 'I' at the beginning. For example IBobBLL and IBobBll will not
load. by default it only loads if the spelling of the name it exact. for other options to fix this issue, see this link:
http://stackoverflow.com/questions/1946228/structuremap-error-202-setting-up-ioc-container

4.      Check to be sure that resharper did not bind you to the incorrect name space, some BLLS exists in 2 places (JCDC.* And JcdcHelper.*)

5.      Make sure Interface is public Concrete class is public Double check namespaces for concrete and interface.

6.      Check that it's not a base object throwing the exception in one of the the paramters passed into the constructor of the BLL/DAL (passDal, PasssBll, etc)

Remove the Class from the passed in parameters, and do a ObjectFactory.GetInstance instead, it'll step into the constructor and blow on the new call to GetInstance.
You can debug it from there...
         Examples:
         Say the 202 error is on IInterface1, which is beign passed in as a constructor  parameter.
         StructureMap is Bad about returning the 202 error on the first parameter, even if its     
         actually from a later parameter... so


          Class(IInterface1 _i1, IInterface2 _i2, IInterface3 _i3)
          {}


         to


          Class(IInterface2 _i2, IInterface3 _i3)
          {
               IIntercafe1 _i1 = ObjectFactory.GetInstance<IInterface1>();
          }
        or
           Class(IInterface1 _i1, IInterface2 _i2, IInterface3 _i3): base(_il1)
          {}
        to
           Class(IInterface2 _i2, IInterface3 _i3): base(ObjectFactory.GetInstance<IInterface1>())
          {}

         Will help you figure out which it is...
   OR you can step into the constructor of IInterface1 on the ObjectFactory line, and see if   
         one of it's dependencies is the issue (sometimes you'll dig down , down, down before you
         get it...)

see comments below.


7.      Edit JCDCHelper, make INetlog lazy load, or comment it out, eventually you’ll unhide a
more descriptive error, if it’s caused by a reference miss match (ie FluentNhibernte from the bin instead of _CommonDlls.)

8.      Don't forget to inherit from the interface
1.      public class StudentBLL : IStudentBLL 
2.      public class StudentBLL : BaseBLL,  IStudentBLL

9.      Try explicit loading instead of convention based, see if it gives you meanign ful errors
1.      x.For<IStudentBLL>().Use<StudentBLL>();

10.  Make sure your BLL looks like this
[System.ComponentModel.DataObject]
public class ProcessingWrapperBLL : BaseBLL, IProcessingWrapperBLL
{

     include the follwing
     1. [...DataObject]
     2. Public class
     3. Derived from BaseBll
    4. Inherit from the matching Interface IProcessignWrapperBLL


StructureMap Exception Code: 180: No public construcotr defined.

Make sure it's Building the assembly that contains the object, not it's Interfacex.BuildInstancesOf<ITicketHelper>()
.TheDefaultIsConcreteType<
TicketHelperWinform>()//<-- if this is an interface you get the error.CacheBy(
InstanceScope.Hybrid );
:




=======================================================================
Structure map 3 errors



170

no default instalce of Class xx


in assertconfig is valid, it puke if you do ObjectFacory.GetInstance<xxx>, in the only construcutre of a class or up in the clas header outside the constructor... make another constructor that passes in the instances, SM will use that, and you're golden

3 comments:

  1. What no way to edit post, beh this blogapp suxxors!

    ReplyDelete
  2. Make sure your BLL looks like this

    [System.ComponentModel.DataObject]
    public class ProcessingWrapperBLL : BaseBLL, IProcessingWrapperBLL
    {

    [...DataObject]
    Public
    Derive from BaseBll
    Inherit INterface

    ReplyDelete
  3. Make sure you added this to your BootstrapStuctureMap.cs file to get this assembly scanned.

    ReplyDelete