MagicOnion
MagicOnion copied to clipboard
The code generator cannot find System.Threading.Tasks.Task
After I run the code generator, it writes to the console failed to get metadata of System.Threading.Tasks.Task
, after which it breaks on the hub implementation example with the error System.InvalidOperationException: A return type of a method must be 'void', 'UnaryResult<T>', 'Task<T>', 'Task'.
. The methods in the example return a task, so the error is, I would guess, because it wasn't able to find the task type. Would it be because the task assembly wasn't referenced in the csproj, do you think? It happens both when trying to reference just the subproject that I need to generate code for, and when trying to reference the whole Assembly-CSharp.csproj
, albeit when trying the latter it takes more than a minute to load everything. Here's the stack trace:
System.InvalidOperationException: A return type of a method must be 'void', 'UnaryResult<T>', 'Task<T>', 'Task'. (Method: IGamingHub.LeaveAsync(), Return: System.Threading.Tasks.Task)
at MagicOnion.CodeAnalysis.MethodCollector.ExtractRequestResponseType(IMethodSymbol method, MethodType& methodType, String& requestType, String& responseType, ITypeSymbol& unwrappedOriginalResponseType) in /home/runner/work/MagicOnion/MagicOnion/src/MagicOnion.GeneratorCore/CodeAnalysis/MethodCollector.cs:line 264
at MagicOnion.CodeAnalysis.MethodCollector.CreateMethodDefinition(IMethodSymbol y) in /home/runner/work/MagicOnion/MagicOnion/src/MagicOnion.GeneratorCore/CodeAnalysis/MethodCollector.cs:line 211
at System.Linq.Enumerable.SelectEnumerableIterator`2.ToArray()
at MagicOnion.CodeAnalysis.MethodCollector.<CollectHubInterface>b__8_0(INamedTypeSymbol x) in /home/runner/work/MagicOnion/MagicOnion/src/MagicOnion.GeneratorCore/CodeAnalysis/MethodCollector.cs:line 158
at System.Linq.Enumerable.SelectArrayIterator`2.ToArray()
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.OrderedEnumerable`1.ToArray()
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at MagicOnion.CodeAnalysis.MethodCollector.CollectHubInterface() in /home/runner/work/MagicOnion/MagicOnion/src/MagicOnion.GeneratorCore/CodeAnalysis/MethodCollector.cs:line 155
at MagicOnion.MagicOnionCompiler.GenerateFileAsync(String input, String output, Boolean unuseUnityAttr, String namespace, String conditionalSymbol, String messagePackGeneratedNamespace) in /home/runner/work/MagicOnion/MagicOnion/src/MagicOnion.GeneratorCore/MagicOnionCompiler.cs:line 52
at MagicOnion.Generator.Program.RunAsync(String input, String output, Boolean unuseUnityAttr, String namespace, String messagePackGeneratedNamespace, String conditionalSymbol) in /home/runner/work/MagicOnion/MagicOnion/src/MagicOnion.Generator/Program.cs:line 30
at ConsoleAppFramework.ConsoleAppEngine.RunCore(ConsoleAppContext ctx, Type type, MethodInfo methodInfo, String[] args, Int32 argsOffset)
I'm running the latest release (4.5.2) approximately like this:
"dotnet" tool run dotnet-moc -input D:\projects\UnityProject\Assembly-CSharp.csproj -output D:\projects\UnityProject\Assets\Source\MagicOnion\Runtime\MessagePackGenerated -unuseUnityAttr -namespace Generated -messagePackGeneratedNamespace Generated -conditionalSymbols UNITY_EDITOR
I think the filtering is wrong which makes the runtime get imported twice. Removing the .NET Core standard references added in manually and just letting it load on its own, even with the filtering enabled, made the error go away. It works fine even if I remove the filtering. I'm talking about this line. So the solution would be to either improve the filtering, or possibly remove it. I can't put my finger on whether it will work for older unity versions with that removed though. My version is 2021.
@AntonC9018 Please try to set your server side .csproj instead of Assembly-CSharp.csproj.
@yKimisaki I can't tho, there would be no Unity references then.
For Vector3
and stuff
And if you mean the csproj with the code I need code generation for, then I had already done that at the time of writing, as mentioned in the post
Sorry, I'm not good at English, so I may have missed and miscommunicated.
I had a same issue(failed to get metadata of System.Threading.Tasks.Task) with the command below.
dotnet moc -i C:\Works\MyProject\MyProject.UnityClient\Assembly-CSharp.csproj
I resolved this issue with the command below.
dotnet moc -i C:\Works\MyProject\MyProject.Server\MyProject.Server.csproj
MyProject.Server.csproj and Assembly-CSharp.csproj share .cs files of streaming hub definition interfaces. I added MessagePack.UnityShims nuget package to server side project. MessagePack.UnityShims allows to use Unity types(for example UnityEngine.Vector3) on server side project.
This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 30 days.