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

#110: Made type lookup more robust. Fixed exception on .NET Standard … #111

Merged
merged 5 commits into from Oct 16, 2017

Conversation

mstyura
Copy link
Contributor

@mstyura mstyura commented Oct 12, 2017

…2.0 libraries.

@AppVeyorBot
Copy link

@tpluscode
Copy link
Member

Hey @mstyura. Thank you so much for taking the time to add this fix.

Could you please make the tests run also against .net core 2.0? You'll have to add a netcoreapp20 build target to the XAssemblyToProcess and have tests code run the weaver against it. Here's where I set it for Serilog. Similarly for Custom.

@mstyura
Copy link
Contributor Author

mstyura commented Oct 13, 2017

@tpluscode I can do this (and already roughly tried), but what I can say is that issue is only reproducible during actual build. But not via test. So there is some critical different between test and actual build. But I'l add netstandard2.0 target to project and test (for other tests I guess it would be valuable).

@tpluscode
Copy link
Member

tpluscode commented Oct 13, 2017

Interesting. Are you saying that current tests ran against netcoreapp20 would not fail? I'm going to try that myself right now

var runtime = AssemblyResolver.Resolve(new AssemblyNameReference("System.Runtime", null));
var core = AssemblyResolver.Resolve(new AssemblyNameReference("System.Core", null));

var typeType =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These sets of FirstOrDefault are repeated a few times. Please extract these fragments including the null check and Debug.Write into a method. Maybe something like GetTypeFromFirst(params AssemblyReference[] candidateAssemblies)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem, will do

@mstyura
Copy link
Contributor Author

mstyura commented Oct 13, 2017

@tpluscode either I did wrong changes in my tests for .netstandard2.0 so the did not fail, or the test environment is different from build environment.

@mstyura
Copy link
Contributor Author

mstyura commented Oct 13, 2017

@tpluscode have you managed to reproduce the original issue in your environment during build and test?

@tpluscode
Copy link
Member

Unfortunately not. That shouldn't stop me from merging this.

@tpluscode
Copy link
Member

Actually, you wouldn't have a repro of this, would you?

@mstyura
Copy link
Contributor Author

mstyura commented Oct 14, 2017

@tpluscode I'm going to dive deep into how the current implementation of unit tests works to find out why they does not detect problem

@mstyura
Copy link
Contributor Author

mstyura commented Oct 14, 2017

So the key difference is different AssemblyResolver used during unit test and during MSBuild execution.
When weaver is executed under MSBuild the AssemblyResolver has type AssemblyResover from assembly FodeIsoleated. Unit tests have its own relatively simple MockAssemlbyResolver.
So the key thing is that during unit tests mscorlib is resolved to assembly from CLR under which test is executed. On my machine it is mscorlib is come from regular desktop .NET Framework and has all types like System.Object, System.String and etc in it.
When weaver is executed under MSBuild mscorlib is resolved to %USERPOFILE% .nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\\ref\mscorlib.dll. This assembly doesn't have any type definition except type forwarding like [assembly: TypeForwardedTo(typeof(Action))].
So, there are three ways I see to fix the issue:

  1. use the same resolver as Fody itself when it execute weavers (tests will reveal such problems in future)
  2. add handling of forwarded types (will fix execution on existing and possibly new runtimes)
  3. implement both 1 & 2 solutions.

I think the best option would be 3, but I'll start with 2 since it looks like the easiest one.

@tpluscode
Copy link
Member

Great findings. Do you think it will be a lot of code? Maybe let's have it in a new branch?

@mstyura
Copy link
Contributor Author

mstyura commented Oct 15, 2017

@tpluscode don't think that solution 1 would be easy, so dedicated branch (and probably github issue) is good way to tackle the problem. The solution 2: type lookup among type-forwarded types already implemented in this merge request and ready to be merged.

@tpluscode tpluscode merged commit 42284be into Fody:master Oct 16, 2017
@mstyura
Copy link
Contributor Author

mstyura commented Oct 16, 2017

@tpluscode would you mind publishing beta package to nuget with merged changes?

@tpluscode
Copy link
Member

Try the latest prerelease

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

Successfully merging this pull request may close these issues.

None yet

3 participants