Moles References a .NET 4 Assembly in a .NET 3.5 P

2019-08-14 07:44发布

问题:

I am using Moles in Visual Studio 2010, and has been working very well. However, in this situation, Moles will not function. The mscorlib.Behaviors assembly references a .NET 4 assembly, even though the project is set to the .NET 3.5 (full) profile.

I have a solution originally built in .NET 4, using Visual Studio 2010. The required assemblies (System.ServiceProcess; System.Configuration.Install) function only with the .NET 4 Client Profile. Test projects may only be .NET 4 (full) Profile, and are therefore incompatible. Therefore, I changed the framework profile of both the target project and the test project to .NET 3.5 (full), since these assemblies are allowed in this profile.

The following is the compiler warning:

The primary reference "mscorlib.Behaviors, Version=0.94.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" could not be resolved because it has an indirect dependency on the .NET Framework assembly "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" which has a higher version "4.0.0.0" than the version "2.0.0.0" in the current target framework.

Is there some way to force Moles to stick to .NET 3.5, without having to port the application to Visual Studio 2008? I really, REALLY don't want to do that.


UPDATE:

I believe these are the same issue: Am I the only one getting "Assembly Not Available in the Currently Targeted Framework"?

回答1:

I'm not sure if this is the same problem or not but I was getting that "System.Behaviors" assembly added to my "MolesAssemblies" folder whenever I select "Add Moles Assembly" of the "System" reference. Then when I removed the System.Moles from my project, the System.Behavior.dll file was never removed from the "MolesAssemblies" folder and was causing build server issues (similar to what you are seeing). Even though I tried to remove the System.Behaviors reference from the project's references, every time I built that project, it would come back.

The solution was to make sure all references to System.Behavior were removed from the project and also removing MolesAssemblies\System.Behaviors.dll. After building the project, the reference would no longer show up.

Maybe since you switched to .NET 3.5, this original .NET 4.0 System.Behaviors.dll is still hanging around and causing these problems. Try removing it (and your moles references to the System assemblies) and then adding the Moles Assembly for the System assembly again.



回答2:

This question is partially answered by Am I the only one getting "Assembly Not Available in the Currently Targeted Framework"? There are still residual issues with specific solutions. However, this has not been a problem with new solutions, since reporting this problem.