3

Problem

I have the below code in the two respective dlls. dll1 depends on dll2.

When DoWork() is called it will execute myInterface.MyListMethod(ImmutableList<byte>.Empty); fine. When it goes to execute myInterface.MyArrayMethod(ImmutableArray<byte>.Empty); the following exception is thrown:

Exception:System.MissingMethodException: Method not found: Namespace.MyArrayMethod(System.Collections.Immutable.ImmutableArray'1<Byte>)

dll1.dll

public class TestClass
{
    public void DoWork()
    {
        IMyInterface myInterface = new MyInterface();
        myInterface.MyListMethod(ImmutableList<byte>.Empty);
        myInterface.MyArrayMethod(ImmutableArray<byte>.Empty);          
    }
}

dll2.dll

public class MyInterface : IMyInterface
{
    public void MyArrayMethod(ImmutableArray<byte> byteArray)
    {
        // Do stuff
    }

    public void MyListMethod(ImmutableList<byte> byteList)
    {
        // Do stuff
    }
}
public interface IMyInterface
{
    void MyArrayMethod(ImmutableArray<byte> byteArray);
    void MyListMethod(ImmutableList<byte> byteList);
}

Testing

From my point of view it seems that ImmutableArray<> is at fault as I've tried this with multiple types, including as you can see above, with other types in the Immutable namespace. It only happens with ImmutableArray<> as far as I've tried.

I've also made sure that both the dlls are the current dlls and there isn't some old cached version hanging around the gac. Updating the Interface to have another method then calling that before MyArrayMethod works as expected.

Visual Studios specifically doesn't pick up calling references to the method on the interface that contains the ImmutableArray<> param but it will for methods with the ImmutableList<>. It will also pick up references if you remove the ImmutableArray<> param from the method.

MyArrayMethod only has one reference

The solution builds fine however, it's only when it tries to JIT at run-time that this error is thrown.

Skyler Jokiel
  • 318
  • 2
  • 11
  • Did you try to clean the solution and rebuild? It's interesting that the missing method is referring to a String parameter. This would seem to indicate maybe an old build that used to try to call MyArrayMethod(string,ImmutableArray); – Ayo I Mar 22 '16 at 22:46
  • Have you tried this solution? http://stackoverflow.com/questions/29966585/asp-net-vnext-missingmethodexception-method-not-found-microsoft-codeanalysis – silkfire Mar 22 '16 at 22:49
  • @silkfire yea I tired that. both dlls are reading the same immutable dll and I tried different versions of that. To add to it. This only happens for my existing projects that I'm trying to build on. I created a new sln with two projs, and the same immutable dll and that has no problem. It seems to be with the way the sln/projs have been setup. I'm guessing the compiler version but I really don't know. – Skyler Jokiel Mar 25 '16 at 20:17
  • @SkylerJokiel Check if the `App.config` or `Web.config` files are differently setup? – silkfire Mar 25 '16 at 20:48

1 Answers1

1

If I add a project reference to 'System.Runtime' everything works fine. That’s it.

I ended up solving the problem when I was trying to repro it there was a Culture issue that VS solved by auto added a project reference to System.Runtime. This ended up fixing the larger problem. The references in VS are working fine now and the code runs without an issue.

When I pass null it will build without System.Runtime but when I call the method it will throw the exception. However when try and pass a default ImmutableArray it requires I add the System.Runtime. This resolves the issue.

I have no idea why this fixed my issue but it did.

Skyler Jokiel
  • 318
  • 2
  • 11