Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mpc doesn't work ... #922

Closed
hattori opened this issue May 11, 2020 · 5 comments
Closed

mpc doesn't work ... #922

hattori opened this issue May 11, 2020 · 5 comments

Comments

@hattori
Copy link

hattori commented May 11, 2020

Hi there,

I'm so stuck on using mpc command.
mpc throws the following error against my simple code.

$ dotnet mpc  -i . -o . 
Project Compilation Start:.
Project Compilation Complete:00:00:05.7085541
Method Collect Start
Fail in console app running on MessagepackCompiler.RunAsync
System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at MessagePackCompiler.CodeAnalysis.TypeCollector.GetObjectInfo(INamedTypeSymbol type) in d:\a\1\s\src\MessagePack.GeneratorCore\CodeAnalysis\TypeCollector.cs:line 584
   at MessagePackCompiler.CodeAnalysis.TypeCollector.CollectObject(INamedTypeSymbol type) in d:\a\1\s\src\MessagePack.GeneratorCore\CodeAnalysis\TypeCollector.cs:line 578
   at MessagePackCompiler.CodeAnalysis.TypeCollector.CollectCore(ITypeSymbol typeSymbol) in d:\a\1\s\src\MessagePack.GeneratorCore\CodeAnalysis\TypeCollector.cs:line 388
   at MessagePackCompiler.CodeAnalysis.TypeCollector.Collect() in d:\a\1\s\src\MessagePack.GeneratorCore\CodeAnalysis\TypeCollector.cs:line 322
   at MessagePackCompiler.CodeGenerator.GenerateFileAsync(String input, String output, String conditionalSymbol, String resolverName, String namespace, Boolean useMapMode, String multipleIfDirectiveOutputSymbols) in d:\a\1\s\src\MessagePack.GeneratorCore\CodeGenerator.cs:line 58
   at MessagePack.Generator.MessagepackCompiler.RunAsync(String input, String output, String conditionalSymbol, String resolverName, String namespace, Boolean useMapMode, String multipleIfDirectiveOutputSymbols) in d:\a\1\s\src\MessagePack.Generator\MessagepackCompiler.cs:line 30
   at ConsoleAppFramework.ConsoleAppEngine.RunCore(ConsoleAppContext ctx, Type type, MethodInfo methodInfo, String[] args, Int32 argsOffset)

I tried with the osx/mpc command in mpc.zip as well but no luck...

I got this simple User class only in my project. (The project is an Unity project.)

using System;
using System.Collections.Generic;
using MessagePack;

[MessagePackObject]
public class User {
    [Key (0)]
    public string Name {get; set;}

    [Key (1)]
    public int Age { get; set; }
}

Not sure why but mpc works with -m option.
I don't want the option tho.

$ dotnet mpc  -i . -o . -m
Project Compilation Start:.
Project Compilation Complete:00:00:05.8547215
Method Collect Start
Method Collect Complete:00:00:00.0333554
Output Generation Start
[Out]./MessagePack_Formatters_UserFormatter.cs
[Out]./MessagePack_Resolvers_GeneratedResolver.cs
Output Generation Complete:00:00:00.0180744

Here is my env.

$ sw_vers
ProductName:	Mac OS X
ProductVersion:	10.13.6
BuildVersion:	17G65

$ dotnet --version
3.1.201

$ dotnet tool list -g
Package ID                   Version        Command      
--------------------------------------------------
messagepack.generator      2.1.115      dotnet-mpc

Unity version is 2019.3.3f1 just in case.

So what is wrong with my code ??
Are there anything I can try ??

Cheers

@hattori
Copy link
Author

hattori commented May 11, 2020

I've figured out the reason why mpc throws errors but don't know it's an mpc's bug or not.

https://github.com/neuecc/MessagePack-CSharp/blob/v2.1.115/src/MessagePack.GeneratorCore/CodeAnalysis/TypeCollector.cs#L596

The line (bool)contractAttr.ConstructorArguments[0].Value) assumes the size of ConstructorArguments array is bigger than 1 but it is 0 for my case.

I checked it with this print debug.
System.Console.WriteLine("ConstructorArguments Size " + contractAttr.ConstructorArguments.Length);

Unfortunately, I still don't know what is wrong.
Any comments or suggestions are welcome.

Thanks

@neuecc
Copy link
Member

neuecc commented May 13, 2020

thanks for reporting.
duplicate and discussing in #887

@neuecc neuecc closed this as completed May 13, 2020
@hattori
Copy link
Author

hattori commented May 14, 2020

@neuecc
Thanks for your reply.
My problem isn't related to the issue you mentioned but Unity 2019.

I've finally found out the reason.
mpc requires not only the main project file but referenced project files as well but Unity 2019 doesn't created them until you do so.

To generate them, you need to follow the instruction in this link.
https://forum.unity.com/threads/visual-studio-code-editor-1-1-4-error-the-referenced-project-does-not-exist.806628/#post-5468193

I got all referenced project files and mpc worked pretty good.

Thanks

@neuecc
Copy link
Member

neuecc commented May 14, 2020

@hattori
Thank you for the clarification.
The exception message isn't good, so it's going to have to be better.

I didn't know about this option, thank you for the information.

@RedDude
Copy link

RedDude commented Jun 5, 2020

I did @hattori suggestion and did not work for me. I'm using windows, so #887 is not the cause of the issue.
Same error from the OP.
"Fail in console app running on MessagepackCompiler.RunAsync
System.IndexOutOfRangeException: Index was outside the bounds of the array."

I'm using exactly the "MyClass" sample from the README.md, I also did try the "Person" from MasterMemory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants