0

We have some services in our project which we recently ported to .NetCore 3.0. Additionally, since StructureMap is to be sunset, we removed all references and are moving to Lamar since it was the fastest to migrate to. When bootstrapping, one of the service throws "System.NullReferenceException: 'Object reference not set to an instance of an object". Ofcourse I rewrote the registry classes for Lamar. I couldnt find any helpful Diagnosis methods in Lamar to find the source of an error. Please let me know if someone could guide me how to trap the source of the error because now the call stack just provides the the Bootstrap init call as the source of error. We look for all assemblies with a certain string in Assembly name eg: "Project-Name"

var container = new Container(x =>
                    x.Scan(y =>
                    {
                        // Scan all DLLs for Registries
                        y.AssembliesFromApplicationBaseDirectory(
                                assembly =>
                                {
                                     if (assembly.FullName.Contains("Project-Name"))
                                    {
                                        return true;
                                    }
                                    return false;
                                });

                        y.LookForRegistries();

                    }));
  • Please provide some more details. How does your registration code looks like? Also you can use following diagnostic methods of lamar to find what is registered https://jasperfx.github.io/lamar/documentation/ioc/diagnostics/whatdoihave/ https://jasperfx.github.io/lamar/documentation/ioc/diagnostics/validating-container-configuration/ – user3455363 Oct 28 '19 at 11:53

1 Answers1

0

I dont know if this is the right way, but I want to answer my own question to flag this as closed. I had to build my Projects one by one, Register them one by one to find the Project which was causing the issue.

Just wanted to add some more info in case its helpful for someone. "container.AssertConfigurationIsValid()" is only useful if the Container initialization is successful. For me the Container init itself was breaking. So Assert was not useful at all.

But in case Container gets initialized yet IoC calls fail or there are errors like "XYZInterface is not registered within this container and cannot be auto discovered by any missing family policy", these can be identified by setting a Watch on your container runtime value and checking if ErrorMessages property has values. This will give you more insight into what is actually breaking the Service Initialization. In the Immediate window you can check the ErrorMessage value for each of the instances.

Eg: To check Error message value of the the First Instance in the list, check

((Lamar.InstanceRef[])((Lamar.QueryModel)container.Model).AllInstances)[0].Instance.ErrorMessages. 

This will help identifying other breaking issues.