Search Unity

The type 'Action<T1, T2, T3, T4, T5>' exists in both 'Moq, Version=4.0.10827.0, Culture=neutral, Pub

Discussion in 'Scripting' started by DrMaxP, May 15, 2019.

  1. DrMaxP

    DrMaxP

    Joined:
    Sep 18, 2018
    Posts:
    29
    Moving a project to .NET Standard API compatibility has introduced a type definition clash in our test projects that use Moq:

    The type 'Action<T1, T2, T3, T4, T5>' exists in both 'Moq, Version=4.0.10827.0, Culture=neutral, PublicKeyToken=69f491c39445e920' and 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'

    I've tried to alias the namespaces to get rid of this issue, but it doesn't work. It might be helped if I can change the alias for the assembly on the project reference properties, but I don't know if Unity supports that via the assembly definition files. Has anyone got any other suggestions?

    Use looks like this...

    private Action<IntPtr, uhsclHandle, string, size_t, byte[]> doSomething(byte[] bytes)
    {
    return (_, __, ___, ____, buffer) =>
    {
    for(var i = 0; i < bytes.Length; i++)
    {
    buffer = bytes;
    }
    };
    }
     
  2. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,196
    You said you can't resolve this merely by declaring it explcitly as System.Action, instead of simple Action?
     
  3. DrMaxP

    DrMaxP

    Joined:
    Sep 18, 2018
    Posts:
    29
    Yes, that is correct.
     
  4. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,196
    What doesn't work with that approach? Does it not compile? Could you show some code? Or explain the failure mode?
     
  5. DrMaxP

    DrMaxP

    Joined:
    Sep 18, 2018
    Posts:
    29
    You get the error:
    The type 'Action<T1, T2, T3, T4, T5>' exists in both 'Moq, Version=4.0.10827.0, Culture=neutral, PublicKeyToken=69f491c39445e920' and 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'

    and it doesn't compile. This is even if you alias the moq and mscorlib namespaces or the Action type with a using statement.

    So this doesn't work:

    Remove:
    using moq;
    using system;

    Fully qualify all type names in code as a result of the above.

    Define Action:
    using MyAction = System.Action:

    Change code:

    private MyAction.Action<IntPtr, uhsclHandle, string, size_t, byte[]> doSomething(byte[] bytes)
    {
    return (_, __, ___, ____, buffer) =>
    {
    for(var i = 0; i < bytes.Length; i++)
    {
    buffer = bytes;
    }
    };
    }


    Still get the same error.