marten icon indicating copy to clipboard operation
marten copied to clipboard

NullReferenceException when SetApplicationProject assembly is being specified in StoreOptions

Open dalbarracin opened this issue 1 year ago • 2 comments

Hi @jeremydmiller

Following the documentation for pre-build generation code upfront in docs, a new issue is found when specifying the exact application assembly where the generated code is being placed beforehand.

System.NullReferenceException: Object reference not set to an instance of an object
at Marten.StoreOptions.SetApplicationProject(Assembly assembly, String hintPath)

The configuration is like bellow:

services.AddMarten(opts =>
            {
                opts.AutoCreateSchemaObjects = Weasel.Core.AutoCreate.CreateOrUpdate;
                opts.Connection(connectionString);
                opts.SetApplicationProject(typeof(SomeCustomDocument).Assembly); <---
                
                opts.GeneratedCodeMode = TypeLoadMode.Auto;

                opts.Advanced.HiloSequenceDefaults.MaxLo = 50;
                opts.CreateDatabasesForTenants(c =>
                    {
                        c.ForTenant().CheckAgainstPgDatabase()
                                     .WithOwner("postgres")
                                     .WithEncoding("UTF-8")
                                     .ConnectionLimit(-1);
                    });
                opts.Schema.Include<SomeCustomRegistry>();
            }),

Not sure how to debug this. I'm following the test example and without invoke the deprecated function.

dalbarracin avatar Jul 29 '22 13:07 dalbarracin

@dalbarracin could you please share a more detailed stack trace?

mysticmind avatar Jul 31 '22 13:07 mysticmind

The stack trace is as before. I would also like to give you more detail @mysticmind but unfortunately I can't. My only guess is that function is only reachable in development environment, but when deploying a container for instance it brakes.

You would argue why I would like to specify another Assembly different to the application startup one, but it is basically because the generated code is in a shared library which needs to be referenced by other projects.

Am I misusing this? @jeremydmiller

dalbarracin avatar Aug 01 '22 11:08 dalbarracin

@dalbarracin You can definitely make this easier by just putting the generated code into the root project, and that's what I would personally do. But, I'm still looking through that code today and trying to harden it against any possible problems with determining the path or the IHostEnvironment not existing.

jeremydmiller avatar Aug 17 '22 17:08 jeremydmiller