0

I have multiple projects in the solution, all targeting 4.7.2. I then add a method in a lib project that returns valueTuple. Multiple projects call this method, all projects are fine(compiled) except one project. This one project generates compiler error.

Error   CS1061  ValueTuple<IEnumerable<User>, Dictionary<string, string>, Dictionary<string, string>>' does not contain a definition for 'CreatedUsers' and no extension method 'CreatedUsers' accepting a first argument of type 'ValueTuple<IEnumerable<User>, Dictionary<string, string>, Dictionary<string, string>>' could be found (are you missing a using directive or an assembly reference?)

I've compared all nugets pkgs in this project with other projects, minor difference, I then unisntall those different nugets, still the same error. I searched around, knowing 4.7 has built in valuetuple, I then checked this project, it doesn't not have System.ValueTuple nuget, or hardcoded System.ValueTuple.dll anywhere.

Please help. I can always go back to the Tuple<> way, but valuetuple is cleaner. Unless you tell me there's more hidden issues ahead.

Thanks!

The method that returns valuetuple 

public static async Task<(IEnumerable<User> CreatedUsers, Dictionary<string, string> ErrorMsgsA, Dictionary<string, string> ErrorMsgsB)> CreateNewUsers(string param1, CreateUserDTO param2)

{

... ...

... ...

return (createdUs, ErrorMsgs_a, ErrorMsgs_b);

}

The line that causes error:

var createUserResult = await CreateNewUsers(param1, param2);
var created = createUserResult.CreatedUsers; //error

So that's it, compiler complains about not finding items in returned tuple. I listed here the compiler error which complains about the first item, "CreatedUsers", in valuetuple. There are actually one compiler error for each of other valuetuple items, "ErrorMsgsA", ErrorMsgsB. And remember, my other projects who reference itmes in this valuetuple are fine, no error.

Ken
  • 21
  • 4
  • In what code is this error being reported? Is that the complete and correct error message? – Paulo Morgado Jun 10 '19 at 11:24
  • When I posted the question, I updated the err msg, trying to hide the class name, which causes some confusion, the err msg should be Error CS1061 'ValueTuple, Dictionary, Dictionary>' does not contain a definition for 'CreatedUsers' and no extension method 'CreatedUsers' accepting a first argument of type 'ValueTuple, Dictionary, Dictionary>' could be found (are you missing a using directive or an assembly reference?) error on code line: "var created = createUserResult.CreatedUsers;" – Ken Jun 10 '19 at 15:01
  • I updated the original post, to reduce the confusion – Ken Jun 10 '19 at 15:08
  • Check your code again. Are you sure you don't have `var created = createUserResult.CreatedUsers();`? – Paulo Morgado Jun 10 '19 at 16:10
  • No, i don't. It's var created = createUserResult.CreatedUsers – Ken Jun 10 '19 at 17:37
  • Can you provide a [Minimal, Reproducible Example](https://stackoverflow.com/help/mcve)? – Paulo Morgado Jun 10 '19 at 20:39

3 Answers3

2

Okay, I found out why.

The problem project is using an older compiler.

I had to remove two packages, which were there for years, likely came with the source code we bought. Made me sweat thinking for these years we've been using software compiled by such an old compiler, but it is what it is:

Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0 Microsoft.Net.Compilers.1.0.0

Now problem is gone.

Ken
  • 21
  • 4
2

My problem was not at compile error, but during runtime.

But I suspect the fix is still usefull to some and could help somebody here too.

After switching my project to .Net framework 4.7.2 I had to manually update the hintpath for System.ValueTuple from net461 to net47

<HintPath>..\Solutions\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll</HintPath>
Schwarzie2478
  • 2,186
  • 26
  • 30
0

Your method signature is having syntax error of declaring ValueTuple. Because you cannot have ValueTuple property name initialization inside a generic type declaration such as Task<T>. All of your declared property name inside a ValueTuple must have a concrete type.

Change your method signature from:

public static async Task<(IEnumerable<T1> CreatedUsers, Dictionary<string, string> ErrorMsgsA, Dictionary<string, string> ErrorMsgsB)> CreateNewUsers(string param1, dtotype param2)

to:

public static async Task<ValueTuple<IEnumerable<T1>, Dictionary<string, string>, Dictionary<string, string>> CreateNewUsers(string param1, dtotype param2)

Or, you could change T1 as concrete type, for example an Object:

public static async Task<(IEnumerable<Object> CreatedUsers, Dictionary<string, string> ErrorMsgsA, Dictionary<string, string> ErrorMsgsB)> CreateNewUsers(string param1, dtotype param2)

Then you could compile your code.

Eriawan Kusumawardhono
  • 4,796
  • 4
  • 46
  • 49
  • Tuples don't have properties, they have named values. And the error has nothing to do with the names of the values but with the undeclared type parameter `T`. – Paulo Morgado Jun 10 '19 at 11:22
  • T1 is a concrete type, not a generic type. I just used T1 to replace the actual class name – Ken Jun 10 '19 at 14:46