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

Simple project fails #20

Closed
damageboy opened this issue Apr 16, 2018 · 14 comments
Closed

Simple project fails #20

damageboy opened this issue Apr 16, 2018 · 14 comments
Labels

Comments

@damageboy
Copy link

damageboy commented Apr 16, 2018

I've prepared the simple dotnet-cli based project and it fails to build:

Here's the project itself...

https://github.com/damageboy/fodytest

And the error:

C:\temp\fodytest>dotnet build
Microsoft (R) Build Engine version 15.6.84.34536 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restoring packages for C:\temp\fodytest\fodytest.csproj...
  Installing Fody 3.0.3.
  Generating MSBuild file C:\temp\fodytest\obj\fodytest.csproj.nuget.g.props.
  Generating MSBuild file C:\temp\fodytest\obj\fodytest.csproj.nuget.g.targets.
  Restore completed in 2.37 sec for C:\temp\fodytest\fodytest.csproj.
    Fody: Fody (version 3.0.3.0) Executing
MSBUILD : error : Fody: An unhandled exception occurred: [C:\temp\fodytest\fodytest.csproj]
MSBUILD : error : Exception: [C:\temp\fodytest\fodytest.csproj]
MSBUILD : error : Failed to execute weaver C:\Users\dans\.nuget\packages\methodboundaryaspect.fody\1.0.12\MethodBoundaryAspect.Fody.dll [C:\temp\fodytest\fodytest.csproj]
MSBUILD : error : Type: [C:\temp\fodytest\fodytest.csproj]
MSBUILD : error : System.Exception [C:\temp\fodytest\fodytest.csproj]
MSBUILD : error : StackTrace: [C:\temp\fodytest\fodytest.csproj]
MSBUILD : error :    at InnerWeaver.ExecuteWeavers() in C:\projects\fody\FodyIsolated\InnerWeaver.cs:line 208 [C:\temp\fodytest\fodytest.csproj]
MSBUILD : error :    at InnerWeaver.Execute() in C:\projects\fody\FodyIsolated\InnerWeaver.cs:line 104 [C:\temp\fodytest\fodytest.csproj]
MSBUILD : error : Source: [C:\temp\fodytest\fodytest.csproj]
MSBUILD : error : FodyIsolated [C:\temp\fodytest\fodytest.csproj]
MSBUILD : error : TargetSite: [C:\temp\fodytest\fodytest.csproj]
MSBUILD : error : Void ExecuteWeavers() [C:\temp\fodytest\fodytest.csproj]
MSBUILD : error : Object reference not set to an instance of an object. [C:\temp\fodytest\fodytest.csproj]
MSBUILD : error : Type: [C:\temp\fodytest\fodytest.csproj]
MSBUILD : error : System.NullReferenceException [C:\temp\fodytest\fodytest.csproj]
MSBUILD : error : StackTrace: [C:\temp\fodytest\fodytest.csproj]
MSBUILD : error :    at MethodBoundaryAspect.Fody.ReferenceFinder.GetMethodReference(TypeReference typeReference, Func`2 predicate) [C:\temp\fodytest\fodytest.csproj]
MSBUILD : error :    at MethodBoundaryAspect.Fody.InstructionBlockChainCreator.CreateMethodExecutionArgsInstance(NamedInstructionBlockChain argumentsArrayChain, TypeReference anyAspectTypeDefinition) [C:\temp\fodytest\fodytest.csproj]
MSBUILD : error :    at MethodBoundaryAspect.Fody.MethodWeaver.Weave(ModuleDefinition module, MethodDefinition method, IEnumerable`1 aspectInfos) [C:\temp\fodytest\fodytest.csproj]
MSBUILD : error :    at MethodBoundaryAspect.Fody.ModuleWeaver.WeaveMethod(ModuleDefinition module, MethodDefinition method, List`1 aspectInfos) [C:\temp\fodytest\fodytest.csproj]
MSBUILD : error :    at MethodBoundaryAspect.Fody.ModuleWeaver.WeaveType(ModuleDefinition module, TypeDefinition type, Collection`1 assemblyMethodBoundaryAspects) [C:\temp\fodytest\fodytest.csproj]
MSBUILD : error :    at MethodBoundaryAspect.Fody.ModuleWeaver.Execute(ModuleDefinition module) [C:\temp\fodytest\fodytest.csproj]
MSBUILD : error :    at InnerWeaver.ExecuteWeavers() in C:\projects\fody\FodyIsolated\InnerWeaver.cs:line 204 [C:\temp\fodytest\fodytest.csproj]
MSBUILD : error : Source: [C:\temp\fodytest\fodytest.csproj]
MSBUILD : error : MethodBoundaryAspect.Fody [C:\temp\fodytest\fodytest.csproj]
MSBUILD : error : TargetSite: [C:\temp\fodytest\fodytest.csproj]
MSBUILD : error : Mono.Cecil.MethodReference GetMethodReference(Mono.Cecil.TypeReference, System.Func`2[Mono.Cecil.MethodDefinition,System.Boolean]) [C:\temp\fodytest\fodytest.csproj]
MSBUILD : error :  [C:\temp\fodytest\fodytest.csproj]
    Fody:   Finished Fody 335ms.

Build FAILED.

MSBUILD : error : Fody: An unhandled exception occurred: [C:\temp\fodytest\fodytest.csproj]
MSBUILD : error : Exception: [C:\temp\fodytest\fodytest.csproj]
MSBUILD : error : Failed to execute weaver C:\Users\dans\.nuget\packages\methodboundaryaspect.fody\1.0.12\MethodBoundaryAspect.Fody.dll [C:\temp\fodytest\fodytest.csproj]
MSBUILD : error : Type: [C:\temp\fodytest\fodytest.csproj]
MSBUILD : error : System.Exception [C:\temp\fodytest\fodytest.csproj]
MSBUILD : error : StackTrace: [C:\temp\fodytest\fodytest.csproj]
MSBUILD : error :    at InnerWeaver.ExecuteWeavers() in C:\projects\fody\FodyIsolated\InnerWeaver.cs:line 208 [C:\temp\fodytest\fodytest.csproj]
MSBUILD : error :    at InnerWeaver.Execute() in C:\projects\fody\FodyIsolated\InnerWeaver.cs:line 104 [C:\temp\fodytest\fodytest.csproj]
MSBUILD : error : Source: [C:\temp\fodytest\fodytest.csproj]
MSBUILD : error : FodyIsolated [C:\temp\fodytest\fodytest.csproj]
MSBUILD : error : TargetSite: [C:\temp\fodytest\fodytest.csproj]
MSBUILD : error : Void ExecuteWeavers() [C:\temp\fodytest\fodytest.csproj]
MSBUILD : error : Object reference not set to an instance of an object. [C:\temp\fodytest\fodytest.csproj]
MSBUILD : error : Type: [C:\temp\fodytest\fodytest.csproj]
MSBUILD : error : System.NullReferenceException [C:\temp\fodytest\fodytest.csproj]
MSBUILD : error : StackTrace: [C:\temp\fodytest\fodytest.csproj]
MSBUILD : error :    at MethodBoundaryAspect.Fody.ReferenceFinder.GetMethodReference(TypeReference typeReference, Func`2 predicate) [C:\temp\fodytest\fodytest.csproj]
MSBUILD : error :    at MethodBoundaryAspect.Fody.InstructionBlockChainCreator.CreateMethodExecutionArgsInstance(NamedInstructionBlockChain argumentsArrayChain, TypeReference anyAspectTypeDefinition) [C:\temp\fodytest\fodytest.csproj]
MSBUILD : error :    at MethodBoundaryAspect.Fody.MethodWeaver.Weave(ModuleDefinition module, MethodDefinition method, IEnumerable`1 aspectInfos) [C:\temp\fodytest\fodytest.csproj]
MSBUILD : error :    at MethodBoundaryAspect.Fody.ModuleWeaver.WeaveMethod(ModuleDefinition module, MethodDefinition method, List`1 aspectInfos) [C:\temp\fodytest\fodytest.csproj]
MSBUILD : error :    at MethodBoundaryAspect.Fody.ModuleWeaver.WeaveType(ModuleDefinition module, TypeDefinition type, Collection`1 assemblyMethodBoundaryAspects) [C:\temp\fodytest\fodytest.csproj]
MSBUILD : error :    at MethodBoundaryAspect.Fody.ModuleWeaver.Execute(ModuleDefinition module) [C:\temp\fodytest\fodytest.csproj]
MSBUILD : error :    at InnerWeaver.ExecuteWeavers() in C:\projects\fody\FodyIsolated\InnerWeaver.cs:line 204 [C:\temp\fodytest\fodytest.csproj]
MSBUILD : error : Source: [C:\temp\fodytest\fodytest.csproj]
MSBUILD : error : MethodBoundaryAspect.Fody [C:\temp\fodytest\fodytest.csproj]
MSBUILD : error : TargetSite: [C:\temp\fodytest\fodytest.csproj]
MSBUILD : error : Mono.Cecil.MethodReference GetMethodReference(Mono.Cecil.TypeReference, System.Func`2[Mono.Cecil.MethodDefinition,System.Boolean]) [C:\temp\fodytest\fodytest.csproj]
MSBUILD : error :  [C:\temp\fodytest\fodytest.csproj]
    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:04.35
@Ralf1108 Ralf1108 added the bug label Apr 24, 2018
@marcells
Copy link
Contributor

marcells commented May 31, 2018

Hm, did you find any solution? I tried it building with dotnetcore2.0 target framework and the latest version of our aspect and it doesn't work.

@Ralf1108 Do you have an idea? The project looks very simple.

@marcells
Copy link
Contributor

marcells commented Jun 5, 2018

@damageboy Could you try to build it with Visual Studio (not CLI)?

@damageboy
Copy link
Author

@marcells It works in VS on windows...

So now we have issues with command line build and linux only?

@marcells
Copy link
Contributor

marcells commented Jun 6, 2018

Looks so. Hm, I seriously have no idea, what it could be.

@marcells
Copy link
Contributor

marcells commented Jun 6, 2018

So, the following we tried:

VS: -> Working
Windows: msbuild /t:restore and msbuild fodytest.csproj -> Working
Windows: dotnet build -> Exception above
Linux: dotnet build -> Exception above

So, it's a dotnet sdk specific issue. But no idea, what is done different there.

@damageboy
Copy link
Author

damageboy commented Jun 6, 2018

@marcells right.
It's pretty much a known "thing" that VS internally uses msbuild.exe rather than dotnet (I've been bitten by this before when building .resx files with msbuild vs. dotnet

Since Fody officially support dotnet a dn SDK style projects, there must be something specific with this AddIn... Is there an easy way to debug the adding at work?
Maybe calling DEbugger.Break() from inside the addin and attaching from VS to try to see that is going on?

@marcells
Copy link
Contributor

marcells commented Jun 6, 2018

That could work. The weaving process happens during the build time. Never tried using Debugger.Break() when building on Linux. Let's see what will happen.

@marcells
Copy link
Contributor

marcells commented Jun 6, 2018

Debugger.Launch() or Debugger.Break() does nothing on my Linux machine. :-(

@damageboy
Maybe you could try it on Windows with dotnet build. Place the nuget.config next to your project and configure the path to the directory were the package is located.
MethodBoundaryAspect.Fody.1.0.47.zip

@alishahbaz111
Copy link

Could this be related? Fody/Fody#330

@marcells
Copy link
Contributor

marcells commented Jun 6, 2018

No, I think that was an other issue. Our weaver is called properly. But it throws an exception while looking for method references. Maybe it's a Mono.Cecil or FodyCecil issue.

@damageboy
Copy link
Author

This happens on windows too, as long as you build using dotnet build, I'm guessing the debugger break method should work there more consistently

@keith-anders
Copy link
Contributor

So I have a change that fixes this. That is, it allows me to weave and run the given sample project with dotnet build without errors and getting the expected output. I've also only tried it on windows. But I get the same error described above when I run it without my change, so I do think it's a legitimate fix.

The issue is that when the weaver creates an instance of MethodBase (or anything from mscorlib) by using ModuleDefinition.ImportReference(typeof(MethodBase)), it's giving a TypeReference that is scoped to use that mscorlib and not the mscorlib that the weaved assembly uses. (I think this has something to do with the side-by-side capabilities of dot net Core? I'm not familiar with all that)

So fortunately, it's simple to fix. Unfortunately, because the issue only occurs when you're weaving an assembly that's targeting a different mscorlib than the weaver, I haven't the foggiest idea how to write a test for this. Should I just skip that and submit a PR? Or does someone else have an idea how to write such a test?

@marcells
Copy link
Contributor

Awesome, that you found the issue. I have no good idea, too. Maybe @Ralf1108 has one?

If not, I would suggest, you make a comment in the source code and exceptionally skip the test.

@Ralf1108
Copy link
Collaborator

hm.. this sounds complicated :-)
for now submit a PR. Maybe another guy can derive a unittest from your code changes

keith-anders pushed a commit to keith-anders/MethodBoundaryAspect.Fody that referenced this issue Jun 10, 2018
marcells added a commit that referenced this issue Jun 11, 2018
Fixed dotnet core weaver using wrong mscorlib. Issue #20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants