Fody/MethodTimer

Fody: An unhandled exception occurred in a UWP project

igorkulman opened this issue · 23 comments

Trying to get MethodTimer to work in a UWP project, getting this at build:

1>MSBUILD : error : Fody: An unhandled exception occurred:
1>MSBUILD : error : Exception:
1>MSBUILD : error : Failed to read C:\Users\igor\.nuget\packages\Microsoft.NETCore.Runtime.CoreCLR-arm\1.0.0\runtimes\win8-arm\native\clretwrc.dll. Format of the executable (.exe) or library (.dll) is invalid.
1>MSBUILD : error : StackTrace:
1>MSBUILD : error :    at ModuleWeaver.ReadModule(String referencePath) in c:\projects\methodtimer\Fody\InterceptorFinder.cs:line 104
1>MSBUILD : error :    at ModuleWeaver.FindInterceptor() in c:\projects\methodtimer\Fody\InterceptorFinder.cs:line 30
1>MSBUILD : error :    at ModuleWeaver.Execute() in c:\projects\methodtimer\Fody\ModuleWeaver.cs:line 27
1>MSBUILD : error :    at lambda_method(Closure , Object )
1>MSBUILD : error :    at InnerWeaver.ExecuteWeavers() in c:\ConsoleBuildAgent\work\ed448661dbb30d2e\FodyIsolated\InnerWeaver.cs:line 164
1>MSBUILD : error :    at InnerWeaver.Execute() in c:\ConsoleBuildAgent\work\ed448661dbb30d2e\FodyIsolated\InnerWeaver.cs:line 82
1>MSBUILD : error : Source:
1>MSBUILD : error : MethodTimer.Fody
1>MSBUILD : error : TargetSite:
1>MSBUILD : error : Mono.Cecil.ModuleDefinition ReadModule(System.String)
1>MSBUILD : error : Format of the executable (.exe) or library (.dll) is invalid.
1>MSBUILD : error : StackTrace:
1>MSBUILD : error :    at Mono.Cecil.PE.ImageReader.ReadOptionalHeaders(UInt16& subsystem, UInt16& dll_characteristics)
1>MSBUILD : error :    at Mono.Cecil.PE.ImageReader.ReadImage()
1>MSBUILD : error :    at Mono.Cecil.PE.ImageReader.ReadImageFrom(Stream stream)
1>MSBUILD : error :    at Mono.Cecil.ModuleDefinition.ReadModule(Stream stream, ReaderParameters parameters)
1>MSBUILD : error :    at Mono.Cecil.ModuleDefinition.ReadModule(String fileName, ReaderParameters parameters)
1>MSBUILD : error :    at ModuleWeaver.ReadModule(String referencePath) in c:\projects\methodtimer\Fody\InterceptorFinder.cs:line 99
1>MSBUILD : error : Source:
1>MSBUILD : error : Mono.Cecil
1>MSBUILD : error : TargetSite:
1>MSBUILD : error : Void ReadOptionalHeaders(UInt16 ByRef, UInt16 ByRef)
1>MSBUILD : error : 

VS 2015?

Yes, VS2015 Update 1.

In release mode (.net native) or also in debug mode?

Also in debug

yeah having trouble repo'ing. can u upload or email simon.cropp@gmail.com

You are on Fody 1.29.3?

It is easy to reproduce. Create an empty UWP app, add MethodTimer, add [Time] to any method: https://dl.dropboxusercontent.com/u/73642/App4.zip

Good question about the Fody version. In UWP project Visual Studio does not show Nuget dependencies anywhere and the minimal version for MethodTime is Fody 1.29.2.

Can repro with MethodTimer and 1.29.3.

yeah nuget package resolution is broken. with project.json u need to manually the hierarchy of dependencies into project.json. otherwise you will always resolve to old broken versions.

but i do not think that is the problem here

Let me do some quick tests, will report in about 30 minutes.

i think i just need to skip non .net assemblies

I think so too. But also adding LogDebug and LogWarningPoint to the weaver (Since they are available anyway).

After some fixes (this is all debug when you set output to verbose):

1>    Fody:   Initializing weaver
1>    Fody:   Loading 'C:\Users\Geert\.nuget\packages\MethodTimer.Fody\1.15.8\MethodTimer.Fody.dll' from cache.
1>      Fody/MethodTimer:   Executing Weaver 
1>      Fody/MethodTimer:   Searching for an intercepter
1>      Fody/MethodTimer:   Failed to read module from 'C:\Users\Geert\.nuget\packages\Microsoft.NETCore.Runtime.CoreCLR-x86\1.0.0\runtimes\win7-x86\native\clretwrc.dll', probably a .net native assembly
1>      Fody/MethodTimer:   Failed to read module from 'C:\Users\Geert\.nuget\packages\Microsoft.NETCore.Runtime.CoreCLR-x86\1.0.0\runtimes\win7-x86\native\coreclr.dll', probably a .net native assembly
1>      Fody/MethodTimer:   Failed to read module from 'C:\Users\Geert\.nuget\packages\Microsoft.NETCore.Runtime.CoreCLR-x86\1.0.0\runtimes\win7-x86\native\dbgshim.dll', probably a .net native assembly
1>      Fody/MethodTimer:   Failed to read module from 'C:\Users\Geert\.nuget\packages\Microsoft.NETCore.Runtime.CoreCLR-x86\1.0.0\runtimes\win7-x86\native\mscordaccore.dll', probably a .net native assembly
1>      Fody/MethodTimer:   Failed to read module from 'C:\Users\Geert\.nuget\packages\Microsoft.NETCore.Runtime.CoreCLR-x86\1.0.0\runtimes\win7-x86\native\mscordbi.dll', probably a .net native assembly
1>      Fody/MethodTimer:   Failed to read module from 'C:\Users\Geert\.nuget\packages\Microsoft.NETCore.Runtime.CoreCLR-x86\1.0.0\runtimes\win7-x86\native\mscorrc.debug.dll', probably a .net native assembly
1>      Fody/MethodTimer:   Failed to read module from 'C:\Users\Geert\.nuget\packages\Microsoft.NETCore.Runtime.CoreCLR-x86\1.0.0\runtimes\win7-x86\native\mscorrc.dll', probably a .net native assembly
1>      Fody/MethodTimer:   Failed to read module from 'C:\Users\Geert\.nuget\packages\System.IO.Compression.clrcompression-x86\4.0.0\runtimes\win10-x86\native\ClrCompression.dll', probably a .net native assembly
1>      Fody/MethodTimer:       No reference to 'MethodTimer.dll' found. References not modified.
1>      Fody/MethodTimer:   Finished 'MethodTimer' in 112ms 

ok i am not going to get to this till tomorrow. a workaround is to add an interceptor https://github.com/Fody/MethodTimer#what-gets-compiled-with-an-interceptor

Just wanted to note that :p, with interceptor there are no issues.

How many ms do all the try catches take?

Good question, will measure. But is there another way to check if something is a .net native assembly?

1>      Fody/MethodTimer:   Reading module from 'C:\Users\Geert\.nuget\packages\Microsoft.NETCore.Portable.Compatibility\1.0.0\lib\netcore50\System.Xml.Serialization.dll'
1>      Fody/MethodTimer:   Read module, took 0 ms
1>      Fody/MethodTimer:   Reading module from 'C:\Users\Geert\.nuget\packages\Microsoft.NETCore.Runtime.CoreCLR-x86\1.0.0\runtimes\win7-x86\native\clretwrc.dll'
1>      Fody/MethodTimer:   Failed to read module, probably a .net native assembly, took 0 ms
1>      Fody/MethodTimer:   Reading module from 'C:\Users\Geert\.nuget\packages\Microsoft.NETCore.Runtime.CoreCLR-x86\1.0.0\runtimes\win7-x86\native\coreclr.dll'
1>      Fody/MethodTimer:   Failed to read module, probably a .net native assembly, took 0 ms
1>      Fody/MethodTimer:   Reading module from 'C:\Users\Geert\.nuget\packages\Microsoft.NETCore.Runtime.CoreCLR-x86\1.0.0\runtimes\win7-x86\native\dbgshim.dll'
1>      Fody/MethodTimer:   Failed to read module, probably a .net native assembly, took 0 ms
1>      Fody/MethodTimer:   Reading module from 'C:\Users\Geert\.nuget\packages\Microsoft.NETCore.Runtime.CoreCLR-x86\1.0.0\runtimes\win7-x86\native\mscordaccore.dll'
1>      Fody/MethodTimer:   Failed to read module, probably a .net native assembly, took 0 ms
1>      Fody/MethodTimer:   Reading module from 'C:\Users\Geert\.nuget\packages\Microsoft.NETCore.Runtime.CoreCLR-x86\1.0.0\runtimes\win7-x86\native\mscordbi.dll'
1>      Fody/MethodTimer:   Failed to read module, probably a .net native assembly, took 0 ms
1>      Fody/MethodTimer:   Reading module from 'C:\Users\Geert\.nuget\packages\Microsoft.NETCore.Runtime.CoreCLR-x86\1.0.0\runtimes\win7-x86\native\mscorrc.debug.dll'
1>      Fody/MethodTimer:   Failed to read module, probably a .net native assembly, took 0 ms
1>      Fody/MethodTimer:   Reading module from 'C:\Users\Geert\.nuget\packages\Microsoft.NETCore.Runtime.CoreCLR-x86\1.0.0\runtimes\win7-x86\native\mscorrc.dll'
1>      Fody/MethodTimer:   Failed to read module, probably a .net native assembly, took 1 ms
1>      Fody/MethodTimer:   Reading module from 'C:\Users\Geert\.nuget\packages\Microsoft.NETCore.Runtime.CoreCLR-x86\1.0.0\runtimes\win7-x86\lib\dotnet\mscorlib.ni.dll'
1>      Fody/MethodTimer:   Read module, took 14 ms
1>      Fody/MethodTimer:   Reading module from 'C:\Users\Geert\.nuget\packages\Microsoft.VisualBasic\10.0.0\lib\netcore50\Microsoft.VisualBasic.dll'
1>      Fody/MethodTimer:   Read module, took 1 ms

There is no reference to Mono.Reflection atm.

please try 1.15.9

Works fine now, thanks.