MissingFieldException (SimpleInjector.Lifestyle.Singleton) with SimpleInjector 5 integration

See original GitHub issue

Is this a bug report?

Yes

Can you also reproduce the problem with the latest version?

Yes

Environment

  1. Operating system: MS Windows 10 Pro
  2. Visual Studio version: VS Community 2019 v16.7.5
  3. Dotnet version: .NET Framework 4.8

Steps to Reproduce

  1. Create a VS Console application targeting .NET Framework 4.8
  2. Install nuget package SimpleInjector version 5.0.3
  3. Install nuget package MassTransit.SimpleInjector version 7.0.4
  4. In Main method, Create a SimpleInjector container and configure MassTransit with an empty action
    container.AddMassTransit(x => { });

Expected Behavior

The app must run and terminate without errors.

Actual Behavior

The app throws a System.MissingFieldException for the field SimpleInjector.Lifestyle.Singleton.

Reproducible Demo

using MassTransit;
using SimpleInjector;
using SimpleInjector.Lifestyles;

namespace MassTransitWithSimpleInjector5.Net48
{
    class Program
    {
        static void Main(string[] args)
        {
            var container = new Container();
            container.Options.DefaultScopedLifestyle = new AsyncScopedLifestyle();

            container.AddMassTransit(x => { });
        }
    }
}

The same happens when targeting .NET Core 3.1 and SimpleInjector 5 (the code is the same).

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
marcello-faugiana-kykloscommented, Oct 12, 2020

Yes, sure! I’ll do a pull request as soon as possible.

0reactions
phatboygcommented, Oct 12, 2020

Hi,

after some tries I found a solution that suits our companies’ needs. Just wanted to share.

Any chance you’d be willing to submit these changes as a pull request?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Lifestyle.Singleton Field
The lifestyle that caches components during the lifetime of the Container instance and guarantees that only a single instance of that component is...
Read more >
In Simple Injector why is it an error for a singleton or ...
Autofac does not contain a Transient lifestyle. Instead it has an InstancePerDependency lifestyle. Technically this is the same as transient, ...
Read more >
SimpleInjector
An easy, flexible, and fast Dependency Injection library that promotes best practice to steer developers towards the pit of success.
Read more >
Chapter 14: The Simple Injector DI Container
A Lifestyle is configured as part of registering components. It's as easy as this: container.Register<SauceBéarnaise>(Lifestyle.Singleton);. This example ...
Read more >
How to use Simple Injector in ASP.NET Core MVC
Following these steps will create a new ASP.NET Core MVC project in Visual Studio 2019 using .NET 5. Launch the Visual Studio IDE....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found