Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Ncrunch Fody ContainsTypeChecker
Jonh04
#1 Posted : Friday, June 6, 2014 4:24:24 PM(UTC)
Rank: Member

Groups: Registered
Joined: 3/13/2012(UTC)
Posts: 20

Thanks: 1 times
Was thanked: 3 time(s) in 2 post(s)
Hey!

It seems that I'm getting an error that nobody else have had when using fody.
I have a solution with multiple project using Fody, but the issue only happens for 1 project. (The same one all the time)

I've added Fody.dll to the Solution configuration of files to include.

Here is the stack trace

Fody.targets (51): The "Fody.WeavingTask" task failed unexpectedly.
System.TypeInitializationException: The type initializer for 'ContainsTypeChecker' threw an exception. ---> System.InvalidCastException: Unable to cast transparent proxy to type 'IContainsTypeChecker'.
at ContainsTypeChecker..cctor() in c:\TeamCity\buildAgent\work\7495521761d392b9\Fody\ContainsTypeChecker.cs:line 15
--- End of inner exception stack trace ---
at ContainsTypeChecker..ctor()
at Processor..ctor() in c:\TeamCity\buildAgent\work\7495521761d392b9\Fody\Processor.cs:line 29
at Fody.WeavingTask.Execute() in c:\TeamCity\buildAgent\work\7495521761d392b9\Fody\WeavingTask.cs:line 46
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__20.MoveNext()


I'm on ncrunch v 2.7.0.5

Thanks for any help!
Let me know if I can provide more info.
Cheers
Remco
#2 Posted : Saturday, June 7, 2014 12:58:56 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,974

Thanks: 929 times
Was thanked: 1256 time(s) in 1169 post(s)
Hi,

Thanks for sharing this issue. As you've posted it here, can I safely assume that you're seeing this problem when working with NCrunch but not with other test runners or a normal build?

Would you be able to try setting your solution in compatibility mode? This exercise will help to establish whether there is a particular NCrunch feature that is surfacing the problem.

IL manipulation issues such as this are typically related to the structure of source code within a project. Possibly the project contains a code arrangement that triggers the issue. If you can narrow this down to a particular class or method (perhaps deductively), this will be very useful in solving the problem.
Jonh04
#3 Posted : Saturday, June 7, 2014 1:41:33 AM(UTC)
Rank: Member

Groups: Registered
Joined: 3/13/2012(UTC)
Posts: 20

Thanks: 1 times
Was thanked: 3 time(s) in 2 post(s)
I'll definitely try compatibility mode on Monday.

Weird thing is that it seems to work on "Resynchronize, rebuild and run all tests", but then as soon as any change triggers a rebuild it seem to break.
I thought it was just for one project, but it seems now that no other project triggered a rebuild from my changes. Changing other files made the issue surface for other projects.
Remco
#4 Posted : Saturday, June 7, 2014 3:56:38 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,974

Thanks: 929 times
Was thanked: 1256 time(s) in 1169 post(s)
I've pinged Simon Cropp (Frody Developer) about this issue. He suggested it might be related to this problem - https://github.com/Fody/Fody/wiki/TaskCouldNotBeLoaded. It may also be worth you checking with him directly to see if he can suggest anything.
Jonh04
#5 Posted : Saturday, June 7, 2014 12:19:16 PM(UTC)
Rank: Member

Groups: Registered
Joined: 3/13/2012(UTC)
Posts: 20

Thanks: 1 times
Was thanked: 3 time(s) in 2 post(s)
Thanks for your quick replies!

I did see that issue with fody not being found while searching for solutions.
But that doesn't seem to be the issue i'm experiencing. It seems to find fody and the typecast that fails is on line 15 inside fody.dll

I could be wrong, looking forward to hearing what Simon has to say.
SimonCropp
#6 Posted : Sunday, June 8, 2014 12:07:51 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 6/22/2012(UTC)
Posts: 5
Location: ACT

Was thanked: 4 time(s) in 3 post(s)
Can you upload a repro somewhere?
Jonh04
#7 Posted : Tuesday, June 10, 2014 5:26:01 PM(UTC)
Rank: Member

Groups: Registered
Joined: 3/13/2012(UTC)
Posts: 20

Thanks: 1 times
Was thanked: 3 time(s) in 2 post(s)
I think I was able to deduce what the problem was.
It seems one project has a dependency to a newer fody package, changing this to align with the other projects seems to have made it go away.

A better message would be useful. Telling me that the version is incorrect, instead of trying to use it and giving a typecast exception. Don't know if this is possible though : )

Thanks for your input, sorry for wasting your time with trivialities
2 users thanked Jonh04 for this useful post.
Remco on 6/10/2014(UTC), mattyboy on 7/2/2015(UTC)
mattyboy
#8 Posted : Thursday, July 2, 2015 8:38:31 AM(UTC)
Rank: Member

Groups: Registered
Joined: 7/2/2015(UTC)
Posts: 16
Location: United Kingdom

Thanks: 4 times
Was thanked: 4 time(s) in 4 post(s)
Jonh04;5990 wrote:
I think I was able to deduce what the problem was.
It seems one project has a dependency to a newer fody package, changing this to align with the other projects seems to have made it go away.

A better message would be useful. Telling me that the version is incorrect, instead of trying to use it and giving a typecast exception. Don't know if this is possible though : )

Thanks for your input, sorry for wasting your time with trivialities


Not a waste of time for me - I had exactly the same problem with different versions of Fody not working with NCrunch. So I created an account here just to say thanks for finding the fix :-)

Matt
SleepyBobos
#9 Posted : Wednesday, August 5, 2015 10:34:49 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 1/29/2015(UTC)
Posts: 2
Location: Australia

I too, thought I should login and add to this dialog.

I had same issue. I checked for version mismatches in Fody references I was aware of.

I couldn't find any until.....I enabled 'Log to output window' in NCrunch, see here, and set the output to Detailed (give me everything!).

Then I searched through this output on the Fody string looking for anomalies and indeed there was a project, the one not building, referencing Fody from the wrong spot in our solution.

I removed this reference, added it from the correct location and all was good.
abelb
#10 Posted : Friday, January 15, 2016 7:17:06 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 9/12/2014(UTC)
Posts: 155
Location: Netherlands

Thanks: 19 times
Was thanked: 11 time(s) in 11 post(s)
I'd like to add that, even if you have aligned all versions, the error can still pop up. I find it hard to solve (and haven't yet) because it does not pop up always. I.e., sometimes when I hit the Reload and Rebuild All button in NCrunch, the error goes away. But if I change something in a part of the project, then the auto-rebuild will throw the error again.

Sometimes the error does not go away at all until I restart Visual Studio. And in some sessions the error does not appear at all. What is even more confusing is that the error appears in different projects of the solution (sometimes in the first that is build, sometimes in the last, sometimes with any in-between).

The exact error I get is, I think, the same as the OP in this thread:

Code:
..\..\_Solutions\packages\Fody.1.29.3\build\dotnet\Fody.targets (50, 5): The "Fody.WeavingTask" task failed unexpectedly.
System.TypeInitializationException: The type initializer for 'ContainsTypeChecker' threw an exception. ---> System.InvalidCastException: Unable to cast transparent proxy to type 'IContainsTypeChecker'.
   at ContainsTypeChecker..cctor() in c:\Code\Fody\Fody\ContainsTypeChecker.cs:line 17
   --- End of inner exception stack trace ---
   at ContainsTypeChecker..ctor()
   at Processor..ctor() in c:\Code\Fody\Fody\Processor.cs:line 29
   at Fody.WeavingTask.Execute() in c:\Code\Fody\Fody\WeavingTask.cs:line 44
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()


Like the OP, the error only appears in NCrunch. Not in TC, not in local build, not in local commandline MSBuild, not in NUnit Runner (but the latter gets a compiled version, of course).
Remco
#11 Posted : Friday, January 15, 2016 9:12:40 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,974

Thanks: 929 times
Was thanked: 1256 time(s) in 1169 post(s)
When you receive this error, it may be worth examining the NCrunch workspace in which its occurring.

Fody is invoked via MSBuild task. Under NCrunch, this will always happen inside a workspace. If you receive the error, try navigating to the workspace by right clicking on the failed build, then going Advanced->Browse to workspace.

You can then examine the generated project file and try running MSBuild against it yourself using the command line. Check where the references are pointing - does the correct version of Fody exist in the workspace? Performing MSBuild with the '/v:d' parameter will allow you access diagnostic information that may help with resolving version clashes and resolution issues.
1 user thanked Remco for this useful post.
abelb on 1/17/2016(UTC)
abelb
#12 Posted : Sunday, January 17, 2016 12:53:07 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 9/12/2014(UTC)
Posts: 155
Location: Netherlands

Thanks: 19 times
Was thanked: 11 time(s) in 11 post(s)
Quote:
If you receive the error, try navigating to the workspace by right clicking on the failed build, then going Advanced->Browse to workspace.


Thanks, that is a good suggestion. I have meanwhile found the cause. If you use a NuGet package that itself is based on Fody (in my case, ModuleInit.Fody), even if all versions are the same, it will not always load the same dependency (not sure why, I have checked settings for each and the settings appear the same). In a single solution of 45 projects I found 8x v2.28.2, 3x v2.28.3 and 14x v2.28.4 (the current version).

The resolution was to uninstall the Fody dependency through NuGet (separate from ModuleInit.Fody, which I left in place) and then reinstalled the latest version of Fody. At each step I needed to check the fsproj and csproj files, because sometimes the uninstall left a build task there.

Once everything was aligned, it worked as it should. Though I am still unsure why there's a difference here, because I would expect that NCrunch uses either version, and since it is only used during build, isolation should *not* result in this error (unless the same process runs the msbuild task on multiple projects in-process, in which case conflicting versions are loaded in the same application domain).
Remco
#13 Posted : Sunday, January 17, 2016 10:06:23 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,974

Thanks: 929 times
Was thanked: 1256 time(s) in 1169 post(s)
abelb;8245 wrote:

Once everything was aligned, it worked as it should. Though I am still unsure why there's a difference here, because I would expect that NCrunch uses either version, and since it is only used during build, isolation should *not* result in this error (unless the same process runs the msbuild task on multiple projects in-process, in which case conflicting versions are loaded in the same application domain).


This is exactly what NCrunch does. The nCrunch.BuildHost.x86.exe process is re-used between build actions and between projects. If there is a build task used by one project with a conflicting reference to a build task used by another project inside the same solution, there is a potential for problems. I believe this is similar to problems that may be experienced by running MSBuild.exe against the solution as whole, although this may depend upon the version of MSBuild/VS in use and the sequence of projects inside the build.

It's possible to force NCrunch to recycle the nCrunch.BuildHost.x86.exe process between each build by setting the build process memory limit to '1'. Note that rebuilding this process between every build action does carry a performance cost and should only be done if there is no other option.
1 user thanked Remco for this useful post.
abelb on 2/4/2016(UTC)
abelb
#14 Posted : Thursday, February 4, 2016 6:24:18 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 9/12/2014(UTC)
Posts: 155
Location: Netherlands

Thanks: 19 times
Was thanked: 11 time(s) in 11 post(s)
Quote:
This is exactly what NCrunch does. The nCrunch.BuildHost.x86.exe process is re-used between build actions and between projects. If there is a build task used by one project with a conflicting reference to a build task used by another project inside the same solution, there is a potential for problems.


This is insightful and explains certain issues I have been having in the past as well, from the kind of "unsure why it works on one system and not on another". When I build the solution with msbuild for the whole solution, I don't know why, but the issue does not arise (this scenario is used on TeamCity for instance).
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.102 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download