Skip to content
This repository has been archived by the owner on Jan 24, 2021. It is now read-only.

System.MissingMethodException when running Nancy with Mono #2064

Closed
Infernno opened this issue Sep 25, 2015 · 8 comments
Closed

System.MissingMethodException when running Nancy with Mono #2064

Infernno opened this issue Sep 25, 2015 · 8 comments

Comments

@Infernno
Copy link

Hello guys.
I have a small problem when running Nancy with Mono under Windows & Linux.
The application fails to start due to MissingMethodException. This happens when you are trying to define the conventions in the bootstrapper.

This is how it looks:
Error

In anyway, simple repro project is here.

P.S. Google said that the problem might be in IoC container, more specifically - Array.Empty is passed as default parameter in Expression.Call method, but Array.Empty isn't implemented in Mono, so we get an exception.
P.S.S. Reproducible under Windows or Linux with latest Nancy (1.3) and Mono (4.0.4). Not reproducible with .NET Framework 4.6.

@khellang
Copy link
Member

I'm not sure what's happening here. Nancy is built against .NET 4.0, which doesn't have Array.Empty. That's an API that was added in .NET 4.6.

@thecodejunkie
Copy link
Member

Hi,

The short version is; this is not a bug in Nancy, it's a run-time framework / compiler issue. The StaticContentConventionBuilder.AddDirectory takes an optional parameter params string[] allowedExtensions and it's the string[] that is being handled incorrectly for some reason. To be honest I've not looked too deep into this, but if you search for array.empty missingmethodexception you see that there are lots of people experiencing this, in different scenarios and different tech stacks

This is what I think you're doing.

  1. You are compiling your application on .NET Framework 4.6 where the absence of values to a params string[] parameter gets compiled into Array.Empty<T>() by Roslyn.
  2. You then attempt to run this compiled application on an early build of .NET Framework or Mono, where Array.Empty<T> does not exist (source notice that it says Available since 4.6)

The way to work around this is to not target .NET 4.6, but instead target .NET 4.5.x

@khellang
Copy link
Member

This might actually be a compiler optimization. I guess when you call a params T[] method with no arguments, the compiler will generate a call using Array.Empty<T> in order to avoid the allocation (Array.Empty<T> will use a cached version per T). I guess your best bet is to stay on .NET 4.5, or target a newer version of Mono.

@MahendranShanmugam
Copy link

MahendranShanmugam commented Apr 6, 2018

Hi ,
I am getting below error when calling the nancy framework api can you please any one help me.
image

Thanks ,
Mahendran S.

@cloudhunter89
Copy link

cloudhunter89 commented Apr 6, 2018 via email

@cloudhunter89
Copy link

cloudhunter89 commented Apr 6, 2018 via email

@MahendranShanmugam
Copy link

Hi,

I am Nancy 1.4.4 version and also where we get the Nancy 2.0.0-clinteastwood can you please suggest me.

Thanks,
Mahendran S.

@MahendranShanmugam
Copy link

Hi,

We have report application so we like to rendering our report using Nancy web API how to do. Can you please explain.

Regards,
Mahendran S.

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

No branches or pull requests

5 participants