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

Invalid code generated with new mpc on macOS #355

Closed
kyubuns opened this issue Dec 17, 2018 · 42 comments
Closed

Invalid code generated with new mpc on macOS #355

kyubuns opened this issue Dec 17, 2018 · 42 comments

Comments

@kyubuns
Copy link
Contributor

kyubuns commented Dec 17, 2018

I think new mpc generate empty GeneratedResolver always.
I got same result by sandbox/SharedData/SharedData.csproj in this repository, and own project csproj.

./osx-x64/mpc -i /Users/kyubuns/code/MessagePack-CSharp/sandbox/SharedData/SharedData.csproj -o ~/Desktop/Test.cs

#pragma warning disable 618
#pragma warning disable 612
#pragma warning disable 414
#pragma warning disable 168

namespace MessagePack.Resolvers
{
    using System;
    using MessagePack;

    public class GeneratedResolver : global::MessagePack.IFormatterResolver
    {
        public static readonly global::MessagePack.IFormatterResolver Instance = new GeneratedResolver();

        GeneratedResolver()
        {

        }

        public global::MessagePack.Formatters.IMessagePackFormatter<T> GetFormatter<T>()
        {
            return FormatterCache<T>.formatter;
        }

        static class FormatterCache<T>
        {
            public static readonly global::MessagePack.Formatters.IMessagePackFormatter<T> formatter;

            static FormatterCache()
            {
                var f = GeneratedResolverGetFormatterHelper.GetFormatter(typeof(T));
                if (f != null)
                {
                    formatter = (global::MessagePack.Formatters.IMessagePackFormatter<T>)f;
                }
            }
        }
    }

    internal static class GeneratedResolverGetFormatterHelper
    {
        static readonly global::System.Collections.Generic.Dictionary<Type, int> lookup;

        static GeneratedResolverGetFormatterHelper()
        {
            lookup = new global::System.Collections.Generic.Dictionary<Type, int>(0)
            {
            };
        }

        internal static object GetFormatter(Type t)
        {
            int key;
            if (!lookup.TryGetValue(t, out key)) return null;

            switch (key)
            {
                default: return null;
            }
        }
    }
}

#pragma warning restore 168
#pragma warning restore 414
#pragma warning restore 618
#pragma warning restore 612
  • macOS 10.14.1 (18B75)
  • dotnet version: 2.1.500
@itn3000
Copy link
Contributor

itn3000 commented Dec 18, 2018

I tested on ubuntu-18.04 and got same output.
I think this is the difference of windows and other platform.
Buildalzyer uses dotnet command in ProjectAnalyzer.Build(),
but linux(and mac)'s SDK does not resolve net461 framework, so internal build will be failed.

This can be avoided by

  1. using msbuild command with '/bl:[output file path]' option
  2. executing AnalyzerManager.Analyze()
  3. adding to workspace by AnalyzerResult.AddToWorkspace()

@Omegastick
Copy link

I'm getting results identical to those above on a Windows Unity project.

mpc.exe -i ..\Src.csproj -o ..\Assets\Src\MessagePackGenerated.cs generates an empty GeneratedResolver.

Does anyone have a fix?

@itn3000
Copy link
Contributor

itn3000 commented Dec 20, 2018

I'm trying to resolve the problem, and this is my progress.
Currently, I'm thinking about the following points

  • how to determine the command line?
    • should it be determined by Platform, commandline option
    • or trying both dotnet msbuild and msbuild
  • how to resolve the path for msbuild or dotnet?
    • currently, it is hard-coded

itn3000 added a commit to itn3000/MessagePack-CSharp that referenced this issue Dec 25, 2018
…essagePack-CSharp#355)

It is because dotnet SDK's msbuild in linux and mac cannot
resolve `net4x` targetframework.

This fix changes to following behavior in generating project info.

1. execute `dotnet msbuild` with output msbuild's binary log
2. if failed, execute `msbuild` with output msbuild's binary log
3. if success with `dotnet msbuild` or `msbuild`, analyze binary log
@jkampitakis
Copy link

I'm trying to resolve the problem, and this is my progress.
Currently, I'm thinking about the following points

  • how to determine the command line?

    • should it be determined by Platform, commandline option
    • or trying both dotnet msbuild and msbuild
  • how to resolve the path for msbuild or dotnet?

    • currently, it is hard-coded

Hi, have you managed to solve this issue?

@itn3000
Copy link
Contributor

itn3000 commented Jan 4, 2019

my fix is replacing from using Buildalyzer.ProjectAnalyzer.Build() to generate msbuild's binary log and Buildalyzer.AnalyzerManager.Analyze().
so mono-devel package is needed when generating from net46x project if linux or mac.

@jkampitakis
Copy link

my fix is replacing from using Buildalyzer.ProjectAnalyzer.Build() to generate msbuild's binary log and Buildalyzer.AnalyzerManager.Analyze().
so mono-devel package is needed when generating from net46x project if linux or mac.

Sorry, I have no idea what this means..
Do you have a working example?

Kind regards

@kyubuns kyubuns closed this as completed Jan 5, 2019
@kyubuns kyubuns reopened this Jan 5, 2019
@jkampitakis
Copy link

I am having the following error

Unhandled Exception:
System.NotImplementedException: The method or operation is not implemented.
at System.IO.Pipes.AnonymousPipeServerStream..ctor (System.IO.Pipes.PipeDirection direction, System.IO.HandleInheritability inheritability, System.Int32 bufferSize, System.IO.Pipes.PipeSecurity pipeSecurity) [0x00031] in <7505d9a21cfc4fc7b41cb4768918fdb4>:0
at System.IO.Pipes.AnonymousPipeServerStream..ctor (System.IO.Pipes.PipeDirection direction, System.IO.HandleInheritability inheritability, System.Int32 bufferSize) [0x00000] in <7505d9a21cfc4fc7b41cb4768918fdb4>:0
at System.IO.Pipes.AnonymousPipeServerStream..ctor (System.IO.Pipes.PipeDirection direction, System.IO.HandleInheritability inheritability) [0x00000] in <7505d9a21cfc4fc7b41cb4768918fdb4>:0
at (wrapper remoting-invoke-with-check) System.IO.Pipes.AnonymousPipeServerStream..ctor(System.IO.Pipes.PipeDirection,System.IO.HandleInheritability)
at MsBuildPipeLogger.AnonymousPipeLoggerServer..ctor (System.Threading.CancellationToken cancellationToken) [0x00000] in <56c3d20ea88740ccbb8467d8ac6e1ab2>:0
at Buildalyzer.ProjectAnalyzer.BuildTargets (Buildalyzer.Environment.BuildEnvironment buildEnvironment, System.String targetFramework, System.String[] targetsToBuild, Buildalyzer.AnalyzerResults results) [0x0001c] in <77d865e836a946fa9f4b5c781e80bf3a>:0
at Buildalyzer.ProjectAnalyzer.Build (System.String targetFramework, Buildalyzer.Environment.BuildEnvironment buildEnvironment) [0x00027] in <77d865e836a946fa9f4b5c781e80bf3a>:0
at Buildalyzer.ProjectAnalyzer.Build (System.String targetFramework, Buildalyzer.Environment.EnvironmentOptions environmentOptions) [0x0001d] in <77d865e836a946fa9f4b5c781e80bf3a>:0
at Buildalyzer.ProjectAnalyzer.Build (Buildalyzer.Environment.EnvironmentOptions environmentOptions) [0x00000] in <77d865e836a946fa9f4b5c781e80bf3a>:0
at MessagePack.CodeGenerator.RoslynExtensions.GetCompilationFromProject (System.String csprojPath, System.Int32 verbosityLevel, System.Collections.Generic.Dictionary2[TKey,TValue] additionalProperties, System.Collections.Generic.IEnumerable1[T] conditionalSymbols) [0x004e7] in <9cb73f6c053a49038fbb2c51cc5ecabb>:0
at MessagePack.CodeGenerator.TypeCollector..ctor (System.String csProjPath, System.Int32 verbosityLevel, System.Collections.Generic.Dictionary2[TKey,TValue] additionalProperties, System.Collections.Generic.IEnumerable1[T] conditinalSymbols, System.Boolean disallowInternal, System.Boolean isForceUseMap) [0x006c5] in <9cb73f6c053a49038fbb2c51cc5ecabb>:0
at MessagePack.CodeGenerator.Program.Main (System.String[] args) [0x00086] in <9cb73f6c053a49038fbb2c51cc5ecabb>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.NotImplementedException: The method or operation is not implemented.
at System.IO.Pipes.AnonymousPipeServerStream..ctor (System.IO.Pipes.PipeDirection direction, System.IO.HandleInheritability inheritability, System.Int32 bufferSize, System.IO.Pipes.PipeSecurity pipeSecurity) [0x00031] in <7505d9a21cfc4fc7b41cb4768918fdb4>:0
at System.IO.Pipes.AnonymousPipeServerStream..ctor (System.IO.Pipes.PipeDirection direction, System.IO.HandleInheritability inheritability, System.Int32 bufferSize) [0x00000] in <7505d9a21cfc4fc7b41cb4768918fdb4>:0
at System.IO.Pipes.AnonymousPipeServerStream..ctor (System.IO.Pipes.PipeDirection direction, System.IO.HandleInheritability inheritability) [0x00000] in <7505d9a21cfc4fc7b41cb4768918fdb4>:0
at (wrapper remoting-invoke-with-check) System.IO.Pipes.AnonymousPipeServerStream..ctor(System.IO.Pipes.PipeDirection,System.IO.HandleInheritability)
at MsBuildPipeLogger.AnonymousPipeLoggerServer..ctor (System.Threading.CancellationToken cancellationToken) [0x00000] in <56c3d20ea88740ccbb8467d8ac6e1ab2>:0
at Buildalyzer.ProjectAnalyzer.BuildTargets (Buildalyzer.Environment.BuildEnvironment buildEnvironment, System.String targetFramework, System.String[] targetsToBuild, Buildalyzer.AnalyzerResults results) [0x0001c] in <77d865e836a946fa9f4b5c781e80bf3a>:0
at Buildalyzer.ProjectAnalyzer.Build (System.String targetFramework, Buildalyzer.Environment.BuildEnvironment buildEnvironment) [0x00027] in <77d865e836a946fa9f4b5c781e80bf3a>:0
at Buildalyzer.ProjectAnalyzer.Build (System.String targetFramework, Buildalyzer.Environment.EnvironmentOptions environmentOptions) [0x0001d] in <77d865e836a946fa9f4b5c781e80bf3a>:0
at Buildalyzer.ProjectAnalyzer.Build (Buildalyzer.Environment.EnvironmentOptions environmentOptions) [0x00000] in <77d865e836a946fa9f4b5c781e80bf3a>:0
at MessagePack.CodeGenerator.RoslynExtensions.GetCompilationFromProject (System.String csprojPath, System.Int32 verbosityLevel, System.Collections.Generic.Dictionary2[TKey,TValue] additionalProperties, System.Collections.Generic.IEnumerable1[T] conditionalSymbols) [0x004e7] in <9cb73f6c053a49038fbb2c51cc5ecabb>:0
at MessagePack.CodeGenerator.TypeCollector..ctor (System.String csProjPath, System.Int32 verbosityLevel, System.Collections.Generic.Dictionary2[TKey,TValue] additionalProperties, System.Collections.Generic.IEnumerable1[T] conditinalSymbols, System.Boolean disallowInternal, System.Boolean isForceUseMap) [0x006c5] in <9cb73f6c053a49038fbb2c51cc5ecabb>:0
at MessagePack.CodeGenerator.Program.Main (System.String[] args) [0x00086] in <9cb73f6c053a49038fbb2c51cc5ecabb>:0

_

@buihuuloc
Copy link

I got the same problem here on MacOS

Unhandled Exception: System.AggregateException: One or more errors occurred. (One or more errors occurred. (No such file or directory)) (No such file or directory) ---> System.ComponentModel.Win32Exception: No such file or directory
   at System.Diagnostics.Process.StartCore(ProcessStartInfo startInfo)
   at System.Diagnostics.Process.Start()
   at Buildalyzer.Environment.ProcessRunner.Start()
   at Buildalyzer.Environment.DotnetPathResolver.GetInfo(String projectPath, String dotnetExePath)
   at Buildalyzer.Environment.DotnetPathResolver.ResolvePath(String projectPath, String dotnetExePath)
   at Buildalyzer.Environment.EnvironmentFactory.CreateCoreEnvironment(EnvironmentOptions options)
   at Buildalyzer.Environment.EnvironmentFactory.GetBuildEnvironment(String targetFramework, EnvironmentOptions options)
   at Buildalyzer.ProjectAnalyzer.Build(String targetFramework, EnvironmentOptions environmentOptions)
   at MessagePack.CodeGenerator.RoslynExtensions.<>c__DisplayClass3_0.<GetWorkspace>b__0(ProjectAnalyzer p) in C:\GitHubRepositories\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Utils\RoslynExtensions.cs:line 83
   at System.Linq.Parallel.SelectQueryOperator`2.SelectQueryOperatorResults.GetElement(Int32 index)
   at System.Linq.Parallel.QueryResults`1.get_Item(Int32 index)
   at System.Linq.Parallel.PartitionedDataSource`1.ListContiguousIndexRangeEnumerator.MoveNext(T& currentElement, Int32& currentKey)
   at System.Linq.Parallel.WhereQueryOperator`1.WhereQueryOperatorEnumerator`1.MoveNext(TInputOutput& currentElement, TKey& currentKey)
   at System.Linq.Parallel.StopAndGoSpoolingTask`2.SpoolingWork()
   at System.Linq.Parallel.SpoolingTaskBase.Work()
   at System.Linq.Parallel.QueryTask.BaseWork(Object unused)
   at System.Linq.Parallel.QueryTask.<>c.<.cctor>b__10_0(Object o)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location where exception was thrown ---
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot)
   --- End of inner exception stack trace ---
   at System.Linq.Parallel.QueryTaskGroupState.QueryEnd(Boolean userInitiatedDispose)
   at System.Linq.Parallel.SpoolingTask.SpoolStopAndGo[TInputOutput,TIgnoreKey](QueryTaskGroupState groupState, PartitionedStream`2 partitions, SynchronousChannel`1[] channels, TaskScheduler taskScheduler)
   at System.Linq.Parallel.MergeExecutor`1.Execute()
   at System.Linq.Parallel.MergeExecutor`1.Execute[TKey](PartitionedStream`2 partitions, Boolean ignoreOutput, ParallelMergeOptions options, TaskScheduler taskScheduler, Boolean isOrdered, CancellationState cancellationState, Int32 queryId)
   at System.Linq.Parallel.PartitionedStreamMerger`1.Receive[TKey](PartitionedStream`2 partitionedStream)
   at System.Linq.Parallel.WhereQueryOperator`1.WrapPartitionedStream[TKey](PartitionedStream`2 inputStream, IPartitionedStreamRecipient`1 recipient, Boolean preferStriping, QuerySettings settings)
   at System.Linq.Parallel.UnaryQueryOperator`2.UnaryQueryOperatorResults.ChildResultsRecipient.Receive[TKey](PartitionedStream`2 inputStream)
   at System.Linq.Parallel.UnaryQueryOperator`2.UnaryQueryOperatorResults.GivePartitionedStream(IPartitionedStreamRecipient`1 recipient)
   at System.Linq.Parallel.UnaryQueryOperator`2.UnaryQueryOperatorResults.GivePartitionedStream(IPartitionedStreamRecipient`1 recipient)
   at System.Linq.Parallel.QueryOperator`1.GetOpenedEnumerator(Nullable`1 mergeOptions, Boolean suppressOrder, Boolean forEffect, QuerySettings querySettings)
   at System.Linq.Parallel.QueryOpeningEnumerator`1.OpenQuery()
   at System.Linq.Parallel.QueryOpeningEnumerator`1.MoveNext()
   at System.Linq.ParallelEnumerable.ToList[TSource](ParallelQuery`1 source)
   at MessagePack.CodeGenerator.RoslynExtensions.GetWorkspace(AnalyzerManager manager, EnvironmentOptions envOptions) in C:\GitHubRepositories\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Utils\RoslynExtensions.cs:line 81
   at MessagePack.CodeGenerator.RoslynExtensions.GetWorkspaceWithPreventBuildEvent(AnalyzerManager manager) in C:\GitHubRepositories\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Utils\RoslynExtensions.cs:line 67
   at MessagePack.CodeGenerator.RoslynExtensions.GetCompilationFromProject(String csprojPath, String[] preprocessorSymbols) in C:\GitHubRepositories\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Utils\RoslynExtensions.cs:line 26
   at MessagePack.CodeGenerator.TypeCollector..ctor(String csProjPath, IEnumerable`1 conditinalSymbols, Boolean disallowInternal, Boolean isForceUseMap) in C:\GitHubRepositories\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\CodeAnalysis\TypeCollector.cs:line 212
   at MessagePack.CodeGenerator.Program.Main(String[] args) in C:\GitHubRepositories\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Program.cs:line 89

neuecc added a commit that referenced this issue Jan 6, 2019
avoiding problem which empty proxy class is created in linux and mac(#355)
@neuecc
Copy link
Member

neuecc commented Jan 6, 2019

I've merged PR, but check above error reports.

@itn3000
Copy link
Contributor

itn3000 commented Jan 7, 2019

I've tested on following env and seems to work fine.

this is my test env and script

@buihuuloc
Copy link

Hi there,
How can I build the new mpc file?

@neuecc
Copy link
Member

neuecc commented Jan 7, 2019

I've added binary to releases page.
Please try it. https://github.com/neuecc/MessagePack-CSharp/releases/tag/v.1.7.3.6

@odysoftware
Copy link

I have also tested the new mpc on MacOS with .NET core 2.1 project and working great.
Also hats off to finally update messagepack to work with .net standard 2.0 in unity - its working like a charm.

Thanks a lot 👍

@kyubuns
Copy link
Contributor Author

kyubuns commented Jan 11, 2019

I still have same result.

>./osx-x64/mpc -i /Users/kyubuns/code/MessagePack-CSharp/sandbox/SharedData/SharedData.csproj -o ~/Desktop/Test.cs
Project Compilation Start:/Users/kyubuns/code/MessagePack-CSharp/sandbox/SharedData/SharedData.csproj
Microsoft (R) Build Engine version 15.9.20+g88f5fadfbe for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

/usr/local/share/dotnet/sdk/2.2.102/MSBuild.dll -distributedlogger:Microsoft.DotNet.Tools.MSBuild.MSBuildLogger,/usr/local/share/dotnet/sdk/2.2.102/dotnet.dll*Microsoft.DotNet.Tools.MSBuild.MSBuildForwardingLogger,/usr/local/share/dotnet/sdk/2.2.102/dotnet.dll -maxcpucount -verbosity:m /v:n /bl:/Users/kyubuns/code/MessagePack-CSharp/sandbox/SharedData/__buildtemp/build.binlog /p:IntermediateOutputPath=/Users/kyubuns/code/MessagePack-CSharp/sandbox/SharedData/__buildtemp /p:ProviderCommandLineArgs=true /p:GenerateResourceMSBuildArchitecture=CurrentArchitecture /p:DesignTimeBuild=true /p:BuildProjectReferences=false /p:SkipCompilerExecution=true /p:DisableRarCache=true /p:AutoGenerateBindingRedirects=false /p:CopyBuildOutputToOutputDirectory=false /p:CopyOutputSymbolsToOutputDirectory=false /p:SkipCopyBuildProduct=true /p:AddModules=false /p:UseCommonOutputDirectory=true /p:GeneratePackageOnBuild=false /p:RunPostBuildEvent=false /p:SolutionDir=/Users/kyubuns/code/MessagePack-CSharp/sandbox/SharedData/SharedData.csproj /t:ResolveAssemblyReferencesDesignTime;ResolveProjectReferencesDesignTime;ResolveComReferencesDesignTime;Compile /Users/kyubuns/code/MessagePack-CSharp/sandbox/SharedData/SharedData.csproj
Build started 1/11/19 9:49:26 AM.
     1>Project "/Users/kyubuns/code/MessagePack-CSharp/sandbox/SharedData/SharedData.csproj" on node 1 (ResolveAssemblyReferencesDesignTime;ResolveProjectReferencesDesignTime;ResolveComReferencesDesignTime;Compile target(s)).
     1>/usr/local/share/dotnet/sdk/2.2.102/Microsoft.Common.CurrentVersion.targets(1179,5): error MSB3644: The reference assemblies for framework ".NETFramework,Version=v4.6.1" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend. [/Users/kyubuns/code/MessagePack-CSharp/sandbox/SharedData/SharedData.csproj]
     1>Done Building Project "/Users/kyubuns/code/MessagePack-CSharp/sandbox/SharedData/SharedData.csproj" (ResolveAssemblyReferencesDesignTime;ResolveProjectReferencesDesignTime;ResolveComReferencesDesignTime;Compile target(s)) -- FAILED.
Deferred Messages

         Detailed Build Summary
         ======================


         ============================== Build Hierarchy (IDs represent configurations) =====================================================
         Id                  : Exclusive Time   Total Time   Path (Targets)
         -----------------------------------------------------------------------------------------------------------------------------------
         0                   : 0.322s           0.479s       /Users/kyubuns/code/MessagePack-CSharp/sandbox/SharedData/SharedData.csproj (ResolveAssemblyReferencesDesignTime, ResolveProjectReferencesDesignTime, ResolveComReferencesDesignTime, Compile)
         | 1                 : 0.078s           0.078s       /Users/kyubuns/code/MessagePack-CSharp/src/MessagePack/MessagePack.csproj (GetTargetFrameworks)
         . 2                 : 0.078s           0.078s       /Users/kyubuns/code/MessagePack-CSharp/src/MessagePack/MessagePack.csproj (GetTargetPath)

         ============================== Node Utilization (IDs represent configurations) ====================================================
         Timestamp:            1        Duration   Cumulative
         -----------------------------------------------------------------------------------------------------------------------------------
         636827645665118780:   0        0.228s     0.228s ####
         636827645667402490:   1        0.078s     0.306s #
         636827645668181830:   0        0.055s     0.361s #
         636827645668730300:   2        0.078s     0.439s #
         636827645669509410:   0        0.042s     0.481s
         -----------------------------------------------------------------------------------------------------------------------------------
         Utilization:          100.0    Average Utilization: 100.0

Build FAILED.

       "/Users/kyubuns/code/MessagePack-CSharp/sandbox/SharedData/SharedData.csproj" (ResolveAssemblyReferencesDesignTime;ResolveProjectReferencesDesignTime;ResolveComReferencesDesignTime;Compile target) (1) ->
       (GetReferenceAssemblyPaths target) ->
         /usr/local/share/dotnet/sdk/2.2.102/Microsoft.Common.CurrentVersion.targets(1179,5): error MSB3644: The reference assemblies for framework ".NETFramework,Version=v4.6.1" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend. [/Users/kyubuns/code/MessagePack-CSharp/sandbox/SharedData/SharedData.csproj]

    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:00.49
execute `dotnet msbuild` failed, retry with `msbuild`
Project Compilation Complete:00:00:04.6108751

Method Collect Start
Method Collect Complete:00:00:00.0012670
Output Generation Start
[Out]/Users/kyubuns/Desktop/Test.cs
String Generation Complete:00:00:00.0067723

I have latest .NET Core SDK.

.NET Core SDK (reflecting any global.json):
 Version:   2.2.102
 Commit:    96ff75a873

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  10.14
 OS Platform: Darwin
 RID:         osx.10.14-x64
 Base Path:   /usr/local/share/dotnet/sdk/2.2.102/

itn3000 added a commit to itn3000/MessagePack-CSharp that referenced this issue Jan 11, 2019
@itn3000
Copy link
Contributor

itn3000 commented Jan 11, 2019

I investigated and same result in sandbox/SharedData/SharedData.csproj on linux , and I found suspicious point.
At least, output was fixed in linux.
Could you try it? @kyubuns

@kyubuns
Copy link
Contributor Author

kyubuns commented Jan 11, 2019

Thanks! But I still have same result on macOS.
I try Console.WriteLine(propargs) under your fix code.

/p:IntermediateOutputPath="/Users/kyubuns/code/MessagePack-CSharp/sandbox/SharedData/__buildtemp/" /p:ProviderCommandLineArgs="true" /p:GenerateResourceMSBuildArchitecture="CurrentArchitecture" /p:DesignTimeBuild="true" /p:BuildProjectReferences="false" /p:SkipCompilerExecution="true" /p:DisableRarCache="true" /p:AutoGenerateBindingRedirects="false" /p:CopyBuildOutputToOutputDirectory="false" /p:CopyOutputSymbolsToOutputDirectory="false" /p:SkipCopyBuildProduct="true" /p:AddModules="false" /p:UseCommonOutputDirectory="true" /p:GeneratePackageOnBuild="false" /p:RunPostBuildEvent="false" /p:SolutionDir="/Users/kyubuns/code/MessagePack-CSharp/sandbox/SharedData/SharedData.csproj/"

@itn3000
Copy link
Contributor

itn3000 commented Jan 11, 2019

hmm, it seems to be difficult to resolve problem.
I added following changes for debugging.

  • output msbuild's stdout even if success
  • copy msbuild's binary log(build.binlog) to current directory

Could you try again?

@kyubuns
Copy link
Contributor Author

kyubuns commented Jan 11, 2019

I try the code.

dotnet bin/Debug/netcoreapp2.1/mpc.dll -i /Users/kyubuns/code/MessagePack-CSharp/sandbox/SharedData/SharedData.csproj -o ~/Desktop/Test.cs > output.txt

output.txt
buildlog.zip - output.txt & build.binlog

@jkampitakis
Copy link

Our game depends heavily on this fix...
We can't make it to work using MacOSX, same as @kyubuns ...

We are willing to pay for someone to fix that and close the issue...

@mikkoairaksinen
Copy link

@jkampitakis Our current workaround for the MacOSX compatibility issues is using a Parallels Desktop installation on the MacOS machine and running mpc.exe (older version, not the newest) from there. It's not pretty (and would probably be hard to run as part of a CI pipeline) but it does the trick if you really need it.

@jkampitakis
Copy link

@mikkoairaksinen Ok. we can try that...Are you using version 1.7.3 from https://github.com/neuecc/MessagePack-CSharp/releases/tag/v1.7.3 ?

@mikkoairaksinen
Copy link

Yes. Haven't tried yet if 1.7.3.6 would work with Parallels, but I'd imagine there should be no problems there. I will try to update some time in the near future and can report back on the results.

@jkampitakis
Copy link

Using VirtualBox with Windows10 installation and v1.7.3 we don't have an empty .cs file anymore but it's all wrong... The mapped classes aren't there, it just scans all the classes declared in the .csproj file and gives us useless generated data (I am attaching the files)
We also tried the v1.7.3.5 ( https://github.com/neuecc/MessagePack-CSharp/releases/download/v.1.7.3.5/MessagePackUniversalCodeGenerator.zip - win-x64 folder) that gives us the following error:

MessagePackGenerated.txt
Assembly-CSharp.csproj.txt

### Unhandled Exception: System.AggregateException: One or more errors occurred. (One or more errors occurred. (The system cannot find the file specified)) (The system cannot find the file specified) ---> System.ComponentModel.Win32Exception: The system cannot find the file specified
at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start()
at Buildalyzer.Environment.ProcessRunner.Start()
at Buildalyzer.Environment.DotnetPathResolver.GetInfo(String projectPath, String dotnetExePath)
at Buildalyzer.Environment.DotnetPathResolver.ResolvePath(String projectPath, String dotnetExePath)
at Buildalyzer.Environment.EnvironmentFactory.CreateCoreEnvironment(EnvironmentOptions options)
at Buildalyzer.Environment.EnvironmentFactory.GetBuildEnvironment(String targetFramework, EnvironmentOptions options)
at Buildalyzer.ProjectAnalyzer.Build(String targetFramework, EnvironmentOptions environmentOptions)
at MessagePack.CodeGenerator.RoslynExtensions.<>c__DisplayClass3_0.b__0(ProjectAnalyzer p) in C:\GitHubRepositories\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Utils\RoslynExtensions.cs:line 83
at System.Linq.Parallel.SelectQueryOperator2.SelectQueryOperatorResults.GetElement(Int32 index) at System.Linq.Parallel.QueryResults1.get_Item(Int32 index)
at System.Linq.Parallel.PartitionedDataSource1.ListContiguousIndexRangeEnumerator.MoveNext(T& currentElement, Int32& currentKey) at System.Linq.Parallel.WhereQueryOperator1.WhereQueryOperatorEnumerator1.MoveNext(TInputOutput& currentElement, TKey& currentKey) at System.Linq.Parallel.StopAndGoSpoolingTask2.SpoolingWork()
at System.Linq.Parallel.SpoolingTaskBase.Work()
at System.Linq.Parallel.QueryTask.BaseWork(Object unused)
at System.Linq.Parallel.QueryTask.RunTaskSynchronously(Object o)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location where exception was thrown ---
at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot)
--- End of inner exception stack trace ---
at System.Linq.Parallel.QueryTaskGroupState.QueryEnd(Boolean userInitiatedDispose)
at System.Linq.Parallel.SpoolingTask.SpoolStopAndGo[TInputOutput,TIgnoreKey](QueryTaskGroupState groupState, PartitionedStream2 partitions, SynchronousChannel1[] channels, TaskScheduler taskScheduler)
at System.Linq.Parallel.DefaultMergeHelper2.System.Linq.Parallel.IMergeHelper<TInputOutput>.Execute() at System.Linq.Parallel.MergeExecutor1.Execute()
at System.Linq.Parallel.MergeExecutor1.Execute[TKey](PartitionedStream2 partitions, Boolean ignoreOutput, ParallelMergeOptions options, TaskScheduler taskScheduler, Boolean isOrdered, CancellationState cancellationState, Int32 queryId)
at System.Linq.Parallel.PartitionedStreamMerger1.Receive[TKey](PartitionedStream2 partitionedStream)
at System.Linq.Parallel.WhereQueryOperator1.WrapPartitionedStream[TKey](PartitionedStream2 inputStream, IPartitionedStreamRecipient1 recipient, Boolean preferStriping, QuerySettings settings) at System.Linq.Parallel.UnaryQueryOperator2.UnaryQueryOperatorResults.ChildResultsRecipient.Receive[TKey](PartitionedStream2 inputStream) at System.Linq.Parallel.UnaryQueryOperator2.UnaryQueryOperatorResults.GivePartitionedStream(IPartitionedStreamRecipient1 recipient) at System.Linq.Parallel.UnaryQueryOperator2.UnaryQueryOperatorResults.GivePartitionedStream(IPartitionedStreamRecipient1 recipient) at System.Linq.Parallel.QueryOperator1.GetOpenedEnumerator(Nullable1 mergeOptions, Boolean suppressOrder, Boolean forEffect, QuerySettings querySettings) at System.Linq.Parallel.QueryOpeningEnumerator1.OpenQuery()
at System.Linq.Parallel.QueryOpeningEnumerator1.MoveNext() at System.Linq.ParallelEnumerable.ToList[TSource](ParallelQuery1 source)
at MessagePack.CodeGenerator.RoslynExtensions.GetWorkspace(AnalyzerManager manager, EnvironmentOptions envOptions) in C:\GitHubRepositories\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Utils\RoslynExtensions.cs:line 81
at MessagePack.CodeGenerator.RoslynExtensions.GetWorkspaceWithPreventBuildEvent(AnalyzerManager manager) in C:\GitHubRepositories\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Utils\RoslynExtensions.cs:line 67
at MessagePack.CodeGenerator.RoslynExtensions.GetCompilationFromProject(String csprojPath, String[] preprocessorSymbols) in C:\GitHubRepositories\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Utils\RoslynExtensions.cs:line 26
at MessagePack.CodeGenerator.TypeCollector..ctor(String csProjPath, IEnumerable`1 conditinalSymbols, Boolean disallowInternal, Boolean isForceUseMap) in C:\GitHubRepositories\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\CodeAnalysis\TypeCollector.cs:line 212
at MessagePack.CodeGenerator.Program.Main(String[] args) in C:\GitHubRepositories\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Program.cs:line 89

@mikkoairaksinen
Copy link

There might be an issue in the csproj file you pass as input to the mpc.exe. Ours is very simple, basically looks like this:

<?xml version="1.0" encoding="utf-8"?>
<Project>
    <ItemGroup>
        <Reference Include="UnityEngine.CoreModule">
            <HintPath>Library/UnityAssemblies/UnityEngine.CoreModule.dll</HintPath>
        </Reference>
        <Compile Include="Assets/External/MessagePack/Attributes.cs" />
        <Compile Include="Assets/Scripts/**/Shared/**/*.cs" />
    </ItemGroup>
</Project>

@itn3000
Copy link
Contributor

itn3000 commented Jan 23, 2019

I have been investigated about this problem, and successed reproducing.
my branch for investigation is here.

I found TypeCollector.targetTypes.Length is 0 even if compilation included valid MessagePackObject attribute.
It is because Compilation.GetTypeByMetadataName("[assembly name]") returns null,
but I still don't understand why null is returned.

I will continue the investigation.

@itn3000
Copy link
Contributor

itn3000 commented Jan 29, 2019

I might find the cause of this issue.

The issue is occured in following conditions.

  • MessagePack is referenced as <ProjectReference/>
  • MessagePack/bin/$(Configuration)/$(TargetFramework)/MessagePack.dll is missing

If in above conditions, msbuild task is finished as success, but GetTypeByMetadataName returns null in ReferenceSymbols.ctor.

I think if GetTypeByMetadataName returns null, mpc should exit as error.

@hiradyazdan
Copy link

hiradyazdan commented Apr 22, 2019

@neuecc @itn3000 what is the status of this issue?

@mikkoairaksinen
Copy link

mikkoairaksinen commented Apr 23, 2019

For anyone still struggling with mac compatibility, here is the minimal dummy csproj I have managed to make work with the latest MsgPack version:

MessagePackResolverDummyProject.csproj

<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <ItemGroup>
        <Compile Include="../../Assets/External/MessagePack/Attributes.cs" />
        <Compile Include="../../Assets/Scripts/**/Shared/**/*.cs" /> 
    </ItemGroup>
    <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

Replace the second path with whatever path you need to include all your code that must be visible. Run mpc with
./mpc/osx-x64/mpc -i MessagePackResolverDummy.csproj -o [YOUR_PATH_HERE]

Some random observations:

  • Running this will for whatever reason always try to use .NET Framework instead of .NET Core and always produce an error and then immediately succeeding. You'll see something like this:
Build FAILED.

(ResolveAssemblyReferencesDesignTime;ResolveProjectReferencesDesignTime;ResolveComReferencesDesignTime;Compile target) (1) ->
       (GetReferenceAssemblyPaths target) ->
         /usr/local/share/dotnet/sdk/2.2.102/Microsoft.Common.CurrentVersion.targets(1179,5): error MSB3644: The reference assemblies for framework ".NETFramework,Version=v4.0" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend. 

Time Elapsed 00:00:00.32
execute `dotnet msbuild` failed, retry with `msbuild`
Project Compilation Complete:00:00:06.1113588

Method Collect Start
Method Collect Complete:00:00:00.1633694
  • Also, weirdly enough, if you try to run this from within the Unity Editor it will always fail. We have a custom Unity dropdown menu option we use to process the data model of the game and it runs the mpc as a part of it's execution. For mac, this will refuse to work no matter what but works just fine if you run it from the command line.

@jkampitakis
Copy link

@mikkoairaksinen Thanks a lot!

I can confirm your solution is working and that we have exactly the same errors / problems as you 📟

@KonstantinPlaytino
Copy link

Same issue here, any progress?

@cmdevwork
Copy link

@mikkoairaksinen try replacing the PATH env variable of the process to match that of your command line.

ProcessStartInfo procInfo = new ProcessStartInfo();
procInfo.EnvironmentVariables["PATH"] = "<your_command_line_path>"

@DataGreed
Copy link

DataGreed commented Jul 1, 2019

So is there any way to build a Unity game using this library for iOS? I have both windows machine and a macbook

@hiradyazdan
Copy link

hiradyazdan commented Jul 1, 2019

@DataGreed why do you think there is none?

@DataGreed
Copy link

@hiradyazdan because I did not find any code generator version working on macOS

@hiradyazdan
Copy link

hiradyazdan commented Jul 4, 2019

@DataGreed there were some issues, but I suspect it is mainly to do with what script/dll you use to build. I use below now and it works fine now:

MessagePackUniversalCodeGenerator/osx-x64/mpc.dll -i "whatever.csproj" -o "MessagePackGenerated.cs"

using the dll solved my issue at least. Let me know if this works for you.

Note: make sure to run it against dotnet only, and not mono as it's not supported.

@kyubuns
Copy link
Contributor Author

kyubuns commented Jul 16, 2019

#355 (comment)
I still have same error on origin/master ( 6f5f80e )
I build mpc.dll from source code.

> dotnet /Users/kyubuns/code/MessagePack-CSharp/bin/MessagePack.UniversalCodeGenerator/Debug/netcoreapp2.1/mpc.dll -i Game/Serializable.csproj -o test.cs
Project Compilation Start:Game/Serializable.csproj
Unhandled Error:System.IO.FileNotFoundException: Could not find file '/Users/kyubuns/code/Hoge/Game/Temp/bin/Debug/MessagePack.dll'.
File name: '/Users/kyubuns/code/Hoge/Game/Temp/bin/Debug/MessagePack.dll'
   at Interop.ThrowExceptionForIoErrno(ErrorInfo errorInfo, String path, Boolean isDirectory, Func`2 errorRewriter)
   at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String path, OpenFlags flags, Int32 mode)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
   at Roslyn.Utilities.FileUtilities.OpenFileStream(String path) in /_/src/Compilers/Core/Portable/FileSystem/FileUtilities.cs:line 402
   at Microsoft.CodeAnalysis.MetadataReference.CreateFromFile(String path, MetadataReferenceProperties properties, DocumentationProvider documentation) in /_/src/Compilers/Core/Portable/MetadataReference/MetadataReference.cs:line 232
   at MessagePack.CodeGenerator.RoslynExtensions.GetWorkspaceFromBuild(Build build, String[] preprocessorSymbols) in /Users/kyubuns/code/MessagePack-CSharp/src/MessagePack.UniversalCodeGenerator/Utils/RoslynExtensions.cs:line 248
   at MessagePack.CodeGenerator.RoslynExtensions.GetCompilationFromProject(String csprojPath, String[] preprocessorSymbols) in /Users/kyubuns/code/MessagePack-CSharp/src/MessagePack.UniversalCodeGenerator/Utils/RoslynExtensions.cs:line 283
   at MessagePack.CodeGenerator.TypeCollector..ctor(String csProjPath, IEnumerable`1 conditinalSymbols, Boolean disallowInternal, Boolean isForceUseMap) in /Users/kyubuns/code/MessagePack-CSharp/src/MessagePack.UniversalCodeGenerator/CodeAnalysis/TypeCollector.cs:line 186
   at MessagePack.CodeGenerator.Program.Main(String[] args) in /Users/kyubuns/code/MessagePack-CSharp/src/MessagePack.UniversalCodeGenerator/Program.cs:line 31

@hiradyazdan
Copy link

@kyubuns have you referenced messagepack.dll in your csproj?

@kyubuns
Copy link
Contributor Author

kyubuns commented Jul 16, 2019

@hiradyazdan
Serializable.csproj has reference to MessagePack.csproj for MessagePackObjectAttribute, KeyAttribute.
There are created by assembly definition in Unity.

  • Assets/Plugins/MessagePack/MessagePack.asmdef
  • Assets/Scripts/Serializable/Serializable.asmdef

@hiradyazdan
Copy link

hiradyazdan commented Jul 16, 2019

@kyubuns when using asmdefs, make sure you're not referencing MessagePack.dll in assembly definition references anywhere as your error says it can't find the messsagepack.dll.

One thing you need to know is that this is "pre code generation" and may not necessarily contain your built asmdef project as well.

Also, only add your MessagePack source codes to a directory (e.g. library) in Assets directory, as messagepack needs to be used with its source than dll in unity.

@kyubuns
Copy link
Contributor Author

kyubuns commented Jul 16, 2019

@hiradyazdan
I found this in MessagePack.csproj (generated by unity)

<OutputPath>Temp\bin\Debug\</OutputPath>

The path is lie. I overwrite to "Library/ScriptAssemblies/".
It looked like it worked.

Then I had other error.

Project Compilation Start:Game/Serializable.csproj
Unhandled Error:System.InvalidOperationException: failed to get metadata of System.Threading.Tasks.Task`1
   at MessagePack.CodeGenerator.TypeCollector.ReferenceSymbols..ctor(Compilation compilation) in /Users/kyubuns/code/MessagePack-CSharp/src/MessagePack.UniversalCodeGenerator/CodeAnalysis/TypeCollector.cs:line 917
   at MessagePack.CodeGenerator.TypeCollector..ctor(String csProjPath, IEnumerable`1 conditinalSymbols, Boolean disallowInternal, Boolean isForceUseMap) in /Users/kyubuns/code/MessagePack-CSharp/src/MessagePack.UniversalCodeGenerator/CodeAnalysis/TypeCollector.cs:line 193
   at MessagePack.CodeGenerator.Program.Main(String[] args) in /Users/kyubuns/code/MessagePack-CSharp/src/MessagePack.UniversalCodeGenerator/Program.cs:line 31

I think this error was also up in this thread, do you know anything?

@hiradyazdan
Copy link

I don't think you have to change your output path. I would suggest build your project without asmdefs and and isolate your problem to main unity project template and then your current platform and then retry.

Also, probably would be worth to learn more about asmdefs first before jumping right into them.

@kyubuns
Copy link
Contributor Author

kyubuns commented Jul 17, 2019

Even myself, asmdef is only used for other benefits.
I solved this problem by creating a new csproj without unity.
Thanks for your advice.

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

No branches or pull requests