Search code examples
c#.netdynamics-crm.net-assembly

Targeting a higher version of .NET causes ms1685 warning when building


I'm using VS2013, which is defaulted to target .NET Framework 4.5. I was trying to work with third-party libraries that required targeting .NET 4.5.2. This is when things started breaking:

  1. I got warning MSB3270 ("There was a mismatch between the processor architecture...and the processor architectur...x86"), So I changed the platform to x86. Fine.
  2. I got thr error (see also the details at the end of this question):

The type 'System.Runtime.Serialization.IExtensibleDataObject' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime.Serialization' etc.

So I added a reference to System.Runtime.Serialization (I don't fully understand this error, though), and I needed to browse and go manually to add a reference to it from the GAC (since I have no assemblies there targeting .NET 4.5.2).

  1. I also needed to add a reference to System.ServiceModel.

  2. I ended up with warning MS1685 ("The predefined type (...) is defined in multiple assemblies"), and with the MSB3247 ("Found coflicts between different versions of the same dependent assemblies" etc). Looking into the build log, the conflict is:

There was a conflict between "System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" and "System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089".

"System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" was chosen because it was primary and "System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" was not.

I also ran AsmSpy (ClassLibrary1 is the name of my project):

Reference: mscorlib
        4.0.0.0 by ClassLibrary1
Reference: Microsoft.Xrm.Sdk
        8.0.0.0 by ClassLibrary1
Reference: System.ServiceModel
        4.0.0.0 by ClassLibrary1

Additional details: The third-party libraries I'm trying to use are the Dynamics CRM assemblies needed to build the example plug-in found here. I got the error mentioned in listing 2 on the line:

    // The InputParameters collection contains all the data passed in the message request.    
    if (context.InputParameters.Contains("Target") &&
                context.InputParameters["Target"] is Entity)

I read the SO posts regarding those warnings. Many (e.g. 1, 2) of them simply say to get rid of the reference causing the problem, but I guess I do need all of them. Others (1, 2) regard CopyLocal - I tried setting it both to True and False, didn't help.

Thus, I didn't managed to solve it, so I'd appreciate help. I know these are all "just warnings", but I'd really like to solve them.


Solution

  • What I guess is that .net 4.5.2 developer pack is not installed properly. I cannot comment on dynamics crm though as I never worked on that.

    Perform the following steps and let me know if that works. (I guess first you have completed the first step already. If yes, then I recommend to do that again as it might fix installation errors if any.)

    1. Install .net 4.5.2 developer pack from the link https://www.microsoft.com/en-us/download/details.aspx?id=42637
    2. Change the target version of your project by going to the project properties dialog box. This will unload the project and make the necessary changes to reference assemblies and config files.
    3. Fix targeting errors according the steps described in this document https://msdn.microsoft.com/en-us/library/cc668079.aspx