Skip to content

trying to generate a type with a delegate crashes dotnet #417

@hahn-kev

Description

@hahn-kev

I came across this when trying to generate a bunch of types
exception

Fatal error. Internal CLR error. (0x80131506)
   at System.Reflection.MethodBaseInvoker.InvokeDirectByRefWithFewArgs(System.Object, System.Span`1<System.Object>, System.Reflection.BindingFlags)
   at System.Reflection.MethodBaseInvoker.InvokeWithFewArgs(System.Object, System.Reflection.BindingFlags, System.Reflection.Binder, System.Object[], System.Globalization.CultureInfo)
   at System.Reflection.RuntimeConstructorInfo.Invoke(System.Reflection.BindingFlags, System.Reflection.Binder, System.Object[], System.Globalization.CultureInfo)
   at System.Reflection.ConstructorInfo.Invoke(System.Object[])
   at Soenneker.Reflection.Cache.Constructors.CachedConstructor.Invoke(System.Object[])
   at Soenneker.Utils.AutoBogus.AutoFakerBinder.CreateInstance[[System.__Canon, System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](Soenneker.Utils.AutoBogus.Context.AutoFakerContext, Soenneker.Reflection.Cache.Types.CachedType)
   at Soenneker.Utils.AutoBogus.AutoFakerBinder.CreateInstanceWithRecursionGuard[[System.__Canon, System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](Soenneker.Utils.AutoBogus.Context.AutoFakerContext, Soenneker.Reflection.Cache.Types.CachedType)
   at Soenneker.Utils.AutoBogus.Generators.Types.TypeGenerator`1[[System.__Canon, System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Soenneker.Utils.AutoBogus.Generators.Abstract.IAutoFakerGenerator.Generate(Soenneker.Utils.AutoBogus.Context.AutoFakerContext)
   at Soenneker.Utils.AutoBogus.Extensions.AutoGenerateContextExtension.Generate[[System.__Canon, System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](Soenneker.Utils.AutoBogus.Context.AutoFakerContext)
   at Soenneker.Utils.AutoBogus.AutoFaker.Generate[[System.__Canon, System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]()
   at LcmCrdt.Tests.Changes.ChangeSerializationTests.FindBadType()

something as simple as this will reproduce the crash:

new AutoFaker().Generate<Action<string>>();

I don't think generating Actions is even possible or should be supported, but I do think a good error should be thrown, In my case I was trying to generate a bunch of types and it was quite difficult to track down the offender because I didn't know what was going on. A simple test like type.IsAssignableTo(typeof(Delegate) should work in my testing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions