Method 'Array.Empty' not found. - when running on Mono 4.0.1

Issue #124 resolved
Rajasekar Shanmugam created an issue

When trying out a sample from page https://bitbucket.org/dadhi/dryioc/wiki/Home, and running it on Mono (Mono JIT compiler version 4.0.1 (Visual Studio built mono)), an exception is thrown.

Test program attached.

Package version used - 2.0.0-rc1build270. Program was compiled using VS2015RC, .NET 4.6 was the target. Works fine on MS.NET and an error when run on mono.

Exception Details: System.TypeInitializationException: An exception was thrown by the type initializer for DryIoc.Portable ---> System.MissingMethodException: Method 'Array.Empty' not found.

--- End of inner exception stack trace --- at DryIoc.ReflectionFactory.CreateExpressionOrDefault (DryIoc.Request request) [0x00000] in <filename unknown>:0 at DryIoc.Factory.GetExpressionOrDefault (DryIoc.Request request, System.Type reuseWrapperType) [0x00000] in <filename unknown>:0 at DryIoc.Container+<>cDisplayClass14_1.<FallbackToContainers>b3 (DryIoc.Request r) [0x00000] in <filename unknown>:0 at DryIoc.ExpressionFactory.CreateExpressionOrDefault (DryIoc.Request request) [0x00000] in <filename unknown>:0 at DryIoc.Factory.GetExpressionOrDefault (DryIoc.Request request, System.Type reuseWrapperType) [0x00000] in <filename unknown>:0 at DryIoc.Factory.GetDelegateOrDefault (DryIoc.Request request) [0x00000] in <filename unknown>:0 at DryIoc.Container.ResolveAndCacheDefaultDelegate (System.Type serviceType, IfUnresolved ifUnresolved, IScope scope) [0x00000] in <filename unknown>:0 at DryIoc.Container.DryIoc.IResolver.ResolveDefault (System.Type serviceType, IfUnresolved ifUnresolved, IScope scope) [0x00000] in <filename unknown>:0 at DryIoc.Resolver.Resolve[Client] (IResolver resolver, IfUnresolved ifUnresolved) [0x00000] in <filename unknown>:0 at TestDryIOC.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0 [ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: An exception was thrown by the type initializer for DryIoc.Portable ---> System.MissingMethodException: Method 'Array.Empty' not found. --- End of inner exception stack trace --- at DryIoc.ReflectionFactory.CreateExpressionOrDefault (DryIoc.Request request) [0x00000] in <filename unknown>:0 at DryIoc.Factory.GetExpressionOrDefault (DryIoc.Request request, System.Type reuseWrapperType) [0x00000] in <filename unknown>:0 at DryIoc.Container+<>cDisplayClass14_1.<FallbackToContainers>b3 (DryIoc.Request r) [0x00000] in <filename unknown>:0 at DryIoc.ExpressionFactory.CreateExpressionOrDefault (DryIoc.Request request) [0x00000] in <filename unknown>:0 at DryIoc.Factory.GetExpressionOrDefault (DryIoc.Request request, System.Type reuseWrapperType) [0x00000] in <filename unknown>:0 at DryIoc.Factory.GetDelegateOrDefault (DryIoc.Request request) [0x00000] in <filename unknown>:0 at DryIoc.Container.ResolveAndCacheDefaultDelegate (System.Type serviceType, IfUnresolved ifUnresolved, IScope scope) [0x00000] in <filename unknown>:0 at DryIoc.Container.DryIoc.IResolver.ResolveDefault (System.Type serviceType, IfUnresolved ifUnresolved, IScope scope) [0x00000] in <filename unknown>:0 at DryIoc.Resolver.Resolve[Client] (IResolver resolver, IfUnresolved ifUnresolved) [0x00000] in <filename unknown>:0 at TestDryIOC.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0

Comments (15)

  1. Maksim Volkau repo owner
    • changed status to open

    Not sure if I can fix this issue fast enough. Googling produced only this thread without solution yet https://connect.microsoft.com/VisualStudio/feedback/details/1097462/missingmethodexception-additional-information-method-not-found-0-system-array-empty.

    Could you point me exactly to the line of code with exception? You may try DryIoc source NuGet package to get sources. May be we can guess and change the code to something else.

  2. Rajasekar Shanmugam reporter

    Sure Maksim, Tried brute force...

    Following line is causing it - A program with just this line itself is failing. I hope this could help a bit.

    Portable.GetPropertyGetMethod((PropertyInfo)null)

    Above is called from below function- ReflectionFactory.GetFactoryMethod( )

    var isStaticMember = member is MethodInfo ? ((MethodInfo)member).IsStatic : member is PropertyInfo ? Portable.GetPropertyGetMethod((PropertyInfo)member).IsStatic : ((FieldInfo)member).IsStatic;

  3. Rajasekar Shanmugam reporter

    Tried justdecompile... See following lines... Think, Array.Empty is replaced for params... Wondering if Mono does not have an implementation...

    func = Expression.Lambda<Func<int>>(Expression.Call(Portable._getEnvCurrentManagedThreadIdMethod, Array.Empty<Expression>()), (ParameterExpression[])null).Compile();

  4. Rajasekar Shanmugam reporter

    4.5.2 seems to generate below equivalent code...

    Expression.Lambda<Func<int>>(Expression.Call(Portable._getEnvCurrentManagedThreadIdMethod, new Expression[0]), (ParameterExpression[])null).Compile();

    and 4.6 is using Array.Empty for optional params. Replaced the code in container.cs, to above code and that seems to fix it. Would this be a permanent fix? I am not sure what other surprises are there. Will have to try MoMA i guess, if it helps.

  5. Maksim Volkau repo owner

    Hi, great job to hunting this thing down!

    I have committed fix. Basically, I am explicitly passing now (Expression[])null where it was missing.

    Please wait until it built on CI, install and check if bug is gone. Then we can close this issue.

    Thanks, Maksim

  6. Rajasekar Shanmugam reporter

    Sure Maksim, Would try the next available nuget package and would post a note.

  7. Rajasekar Shanmugam reporter

    Tried 2.0.0-rc1build272. There were few other references that had to be changed too. Also above change (Expression[])null, got mapped to IEnumerable<Expression>... and resulted in few other errors. hence changed to use new Type[0] etc.

    I have attached the entire container.cs that worked. Sorry, i could not generate a pull request.

  8. Rajasekar Shanmugam reporter

    Found this - Miguel Note on New Types Support, Its unclear when this would be supported in Mono. I am not sure if the creation of an instance (no use of it afterwards) will be an overhead. It will be an interesting call to take. 4.6 seems to be using this new singleton to avoid this.

  9. Maksim Volkau repo owner

    Hello, Thanks again!

    I have changed the code using my own alternative for Array.Empty. You can check after it built.

    Regards,
    Maksim

  10. Rajasekar Shanmugam reporter

    Hello Maksim, One line is not updated.

    Dryloc.ExpressionTools.GetMethodDelegateOrNull( ) - First line in the method - Second parameter had to be passed using the new API. ArrayTools is working for other conditions. Changed line is below -

    var methodInfo = typeof(TOwner).GetDeclaredMethodOrNull(methodName, ArrayTools.No<Type>());

  11. Log in to comment