Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any codegen command fails with ExpectedTypeMissingException: Could not load expected pre-built types #3647

Open
amid0 opened this issue Feb 1, 2025 · 1 comment

Comments

@amid0
Copy link

amid0 commented Feb 1, 2025

I have a custom document store

public interface ICustomStore : IDocumentStore { }

And startup for it

services.AddMartenStore<ICustomStore>(sp =>
            {
                var options = new StoreOptions();
                options.DatabaseSchemaName = "custom";
                options.Schema.For<MyEntity>();

                return options;
            })

Both this thing is placed in the common assembly
It's used in two different services
MySolution.Api and MySolution.BackgroundWorker
The idea is that one of the projects writing to the separate storage and the second is reading.

The problem appears when I'm trying to pre-build code in the main project.
using

dotnet run -- codegen write

builds the project and then throws an error

info: Wolverine.Configuration.HandlerDiscovery[0]
      Searching assembly MySolution.Api, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null for Wolverine message handlers
[red]ERROR:[/]JasperFx.RuntimeCompiler.ExpectedTypeMissingException: Could not load expected pre-built types for code file ICustomStoreImplementation1112837882 
(Marten.Internal.SecondaryStoreConfig`1[MySolution.Common.MartenStorage.ICustomStore]) from assembly MySolution.Api, Version=1.0.0.0,   
Culture=neutral, PublicKeyToken=null. You may want to verify that this is the correct assembly for pre-generated types.

Suppose that it does not look to the referenced assemblies and the is no options to specify additional assemblies to look for.

Is there any workaround on that?

@nkosi23
Copy link

nkosi23 commented Feb 1, 2025

The problem you are getting is related to Wolverine rather than marten based on the exception raised. Make sure you have either:

options.CodeGeneration.TypeLoadMode = TypeLoadMode.Auto

or

options.CodeGeneration.TypeLoadMode = TypeLoadMode.Dynamic

In your Wolverine config.

Also, you can specify the path to load pre-built binaries with: options.ApplicationAssembly = yourAssembly.

To give you my example, I have logic to check the environment at startup so that in production, I point the ApplicationAssembly to my prebuilt binary and use TypeLoadMode.Auto (as a graceful fallback in case I forget to pregenerate types) while in dev I use TypeLoadMode.Dynamic.

Edit: ok my mistake, hadn't seen the second error line, but the configuration options to check are the same for Marten anyway. Hope my answer is helpful to you somehow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants