none
Warning CS1685 - How to fix? RRS feed

  • Question

  • Hello,

    I got the following warning when I rebuilt my solution after updating some references to new dll files.

    Warning    CS1685    The predefined type 'ExtensionAttribute' is defined in multiple assemblies in the global alias; using definition from 'CommLib, Version=1.0.0.44, Culture=neutral, PublicKeyToken=b6b45f27e2749b17'

    Any ideas on how to correct this? Do I need to update my version of .NET?

    Thanks

    Sunday, October 21, 2018 12:40 PM

All replies

  • Hi,

    https://docs.microsoft.com/en-US/dotnet/csharp/language-reference/compiler-messages/cs1685

    This error occurs when a predefined system type such as System.int32 is found in two assemblies. One way this can happen is if you are referencing mscorlib from two different places, such as trying to run the.Net Framework versions 1.0 and 1.1 side-by-side.

    Greetings, Chris

    Sunday, October 21, 2018 10:24 PM
  • Hi LB27468,

    Thank you for posting here.

    For your question, there are many possibilities that can cause this error. If it is possible, could provide a simple example with could reproduce the error for us to test to check dll?

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, October 22, 2018 7:27 AM
    Moderator
  • CommLib looks like a third party assembly. That assembly is defining ExtensionAttribute which is already defined by another assembly. To work around this issue you're going to need to distinguish between the 2 definitions when you use it in your code. I would start by identifying where this type is defined at. This will help direct the solution you will need.

    Sometimes you can just use the fully-qualified type name (with namespace). However the error seems to indicate that this type is defined globally. Therefore a namespace doesn't exist so you could distinguish it. In the rare case where 2 assemblies define the same type in the global namespace there isn't a workaround because there is nothing you can do to change the names. C# doesn't support assembly-based dereferencing.

    Alternatives is to scan the references to see if you're including the same assembly multiple times (indirectly) which is causing the issue. This can happen with strongly named assemblies. 

    Another alternative is to move references to one of the assemblies to a separate assembly that doesn't depend upon both assemblies causing the collision.

    And another is to use reflection as a last resort. However in the case you seem to have I don't believe reflection would work.


    Michael Taylor http://www.michaeltaylorp3.net

    Monday, October 22, 2018 2:12 PM
    Moderator