Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Isolated call with linq method throws exception #11

Open
ilengyel opened this issue Jan 18, 2018 · 3 comments
Open

Isolated call with linq method throws exception #11

ilengyel opened this issue Jan 18, 2018 · 3 comments

Comments

@ilengyel
Copy link

Hello,

I get the following exception with version 1.2.0 of pose while shimming a method which has an extension method. This worked in v1.0.1

PoseTest.Test.TestShim3 [FAIL]
  System.NullReferenceException : Object reference not set to an instance of an object.
  Stack Trace:
       at Pose.Helpers.StubHelper.GetIndexOfMatchingShim(MethodBase methodBase, Type type, Object obj)
       at stub_virt_System.Collections.Generic.ICollection`1[System.String]_get_Count(ICollection`1 , RuntimeMethodHandle , RuntimeTypeHandle )
       at dynamic_System.Linq.Enumerable_LastOrDefault(IEnumerable`1 )
       at stub_System.Linq.Enumerable_LastOrDefault(IEnumerable`1 , RuntimeMethodHandle , RuntimeTypeHandle )
       at dynamic_PoseTest.Program_LinqFn(Program )
       at stub_virt_PoseTest.Program_LinqFn(Program , RuntimeMethodHandle , RuntimeTypeHandle )
       at dynamic_PoseTest.Test+<>c__DisplayClass2_0_<TestShim3>b__1(<>c__DisplayClass2_0 )

Sample project: PoseTest.zip

code extract:

var target = new Program();
var shim = Shim.Replace(() => target.Work())
    .With((Program @this) => "Changed");
PoseContext.Isolate(() => work = target.LinqFn(), shim);

// ...
public string LinqFn()
{
    var items = new[] { Work() };
    var item = items.LastOrDefault();
    return item;
}
@ilengyel
Copy link
Author

Also I attempted to compile the pose solution but when I do dotnet restore I get the following error

  Installing Mono.Reflection 1.1.0.0.
C:\Program Files\dotnet\sdk\1.0.4\NuGet.targets(97,5): error : Package Mono.Reflection 1.1.0 is not compatible with netstandard2.0 (.NETStandard,Version=v2.0). Package Mono.Reflection 1.1.0 supports: net (.NETFramework,Version=v0.0) [C:\DEV\INVESTIGATE\GIT\pose\Pose.sln]
C:\Program Files\dotnet\sdk\1.0.4\NuGet.targets(97,5): error : One or more packages are incompatible with .NETStandard,Version=v2.0. [C:\DEV\INVESTIGATE\GIT\pose\Pose.sln]

My environment is VS2017 (15.4.3). Any dependencies I need to install?

@tonerdo
Copy link
Owner

tonerdo commented Jan 18, 2018

Also I attempted to compile the pose solution but when I do dotnet restore I get the following error

You probably have a setting to treat warnings as errors turned on somewhere

@tonerdo
Copy link
Owner

tonerdo commented Jan 18, 2018

I get the following exception with version 1.2.0 of pose while shimming a method which has an extension method. This worked in v1.0.1

Thanks for the heads up and for providing sample code. I'll take a look at it and get back to you

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

No branches or pull requests

2 participants