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.
The solution builds fine however, it's only when it tries to JIT at run-time that this error is thrown.
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 defaultImmutableArray
it requires I add theSystem.Runtime
. This resolves the issue.I have no idea why this fixed my issue but it did.