grumpydev / TinyIoC

An easy to use, hassle free, Inversion of Control Container for small projects, libraries and beginners alike.
MIT License
830 stars 235 forks source link

Registering any class with a copy constructor throws a System.TypeInitializationException #159

Open FunkyLambda opened 1 year ago

FunkyLambda commented 1 year ago

Steps to reproduce:

  1. Define the following:
    
    public interface IFoo
    {
    }

public class Foo : IFoo { public Foo() { }

public Foo(Foo copy) { } }


2. Now register:

TinyIoCContainer.Current.Register(typeof(IFoo), typeof(Foo)); // Does not make a difference if using AsSingleton() or AsMultiInstance().



3. Run application.

Expected behaviour:
Should just work.

Actual Behaviour:
You receive a System.TypeInitializationException during application startup.

Observations:
1. Removing the copy constructor results in the exception not being thrown.

Environment:
Xamarin.Forms 4.8.0.1821
NETStandard.Library 2.0.3
niemyjski commented 1 year ago

Hello,

Can you please create a pr that contains a test for this as well as a fix.