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

code generation fails with dotnet 2.1 rc1 #4585

Closed
gamemachine opened this Issue May 12, 2018 · 10 comments

Comments

Projects
None yet
7 participants
@gamemachine
Copy link

gamemachine commented May 12, 2018

This is a console app.

Orleans-CodeGen - Generating file C:\Games\aigame\Game\Server\obj\Debug\netcoreapp2.1\Server.orleans.g.cs
1>-- Code Generation FAILED --
1>
1>Exc level 0: System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
1> at System.ModuleHandle.ResolveType(RuntimeModule module, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type)
1> at System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
1> at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
1> at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord, MetadataImport scope, Assembly& lastAptcaOkAssembly, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, Object[] attributes, IList derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg)
1> at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent)
1> at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeAssembly assembly, RuntimeType caType)
1> at System.Attribute.GetCustomAttributes(Assembly element, Type attributeType, Boolean inherit)
1> at System.Reflection.CustomAttributeExtensions.GetCustomAttributes[T](Assembly element)
1> at Orleans.ApplicationParts.AssemblyAttributeFeatureProvider1.PopulateFeature(IEnumerable1 parts, TFeature feature) in D:\build\agent_work\18\s\src\Orleans.Core\ApplicationParts\AssemblyAttributeFeatureProvider.cs:line 41
1> at Orleans.ApplicationParts.ApplicationPartManager.PopulateFeature[TFeature](TFeature feature) in D:\build\agent_work\18\s\src\Orleans.Core\ApplicationParts\ApplicationPartManager.cs:line 49
1> at Orleans.ApplicationPartManagerExtensions.CreateAndPopulateFeature[TFeature](IApplicationPartManager applicationPartManager) in D:\build\agent_work\18\s\src\Orleans.Core\ApplicationParts\ApplicationPartManagerExtensions.cs:line 60
1> at Orleans.CodeGenerator.RoslynCodeGenerator..ctor(IApplicationPartManager partManager, ILoggerFactory loggerFactory) in D:\build\agent_work\18\s\src\Orleans.CodeGeneration\RoslynCodeGenerator.cs:line 43
1> at Orleans.CodeGeneration.CodeGenerator.GenerateSourceForAssembly(Assembly grainAssembly, LogLevel logLevel)
1> at Orleans.CodeGeneration.CodeGenerator.GenerateCodeInternal(CodeGenOptions options)
1> at Orleans.CodeGeneration.CodeGenerator.GenerateCode(CodeGenOptions options)
1> at Orleans.CodeGeneration.Program.Main(String[] args)
1>C:\Users\chris.nuget\packages\microsoft.orleans.orleanscodegenerator.build\2.0.3\build\Microsoft.Orleans.OrleansCodeGenerator.Build.targets(76,5): error MSB3073: The command ""dotnet" "C:\Users\chris.nuget\packages\microsoft.orleans.orleanscodegenerator.build\2.0.3\build..\tasks\netcoreapp2.0\Orleans.CodeGeneration.Build.dll" "@obj\Debug\netcoreapp2.1\codegen\Server.orleans.g.args.txt"" exited with code 3.
1>Done building project "Server.csproj" -- FAILED.

@sergeybykov sergeybykov added this to the Triage milestone May 14, 2018

@finsharp

This comment has been minimized.

Copy link

finsharp commented May 31, 2018

@gamemachine have you made any progress on this issue? Any new findings?

@nockawa

This comment has been minimized.

Copy link

nockawa commented May 31, 2018

I was curious and willing to try and help a little so I took a quick look.

My understanding is that the CodeGeneration.Build heavily relies on reflection and has to load many assemblies to do its work. Thing is it's trying to load System.Runtime.dll of .net core 2.1 which leads to the exception because there's already a System.Runtime.dll loaded, but with the version of the .net core 2.0.7 (the one that was used to build the CodeGeneration.Build.

So far the NuGet package has two plaforms exposed:

  • net461 for .net Framework
  • netcoreapp20 for .net core 2.0

My bet is we would need a netcoreapp21 folder with a version of the application compiled with .net core 2.1, that would certainly resolve the version mismatch issue that triggers the exception.

I took a look at the Microsoft.Orleans.OrleansCodeGenerator.Build.targets build target, you can see there are two paths depending from the $(MSBuildIsCore) variable to create the two existing platform.

Creating a third platform is way beyond my MSBuid skills and I don't even know if it's possible to build side-by-side dll of .net core 2.0 and 2.1 in the same Visual Studio solution... Even building Orleans.CodeGeneration.Build in .net core 2.1 won't be straightforward, looks like the whole Orleans solution is capped for 2.0 max.

Quick, stupid workaround
Don't use build time code generation, the runtime one should be fine has it would be loaded and executed with version 2.1 of the system assemblies...

@gamemachine

This comment has been minimized.

Copy link
Author

gamemachine commented Jun 1, 2018

Unfortunately I can't remember the specifics of where it failed. But removing build time code gen I did try and it didn't work. Although invariably that problem whatever it was is likely easier to fix.

@gamemachine

This comment has been minimized.

Copy link
Author

gamemachine commented Jun 1, 2018

So I just upgraded to 2.1 release and tried again without code generation. Same error as before now I remember what it was. Calling GetGrain with Orleans client throws an error saying 'Cannot find an implementation class for grain interface'.

@gamemachine

This comment has been minimized.

Copy link
Author

gamemachine commented Jun 1, 2018

Ok so that was my bad I just didn't have it configured correctly for runtime code gen.

@gamemachine

This comment has been minimized.

Copy link
Author

gamemachine commented Jun 1, 2018

Although runtime generation doesn't appear to use WithReferences, so it looks like you need to call AddApplicationPart for every grain and type that needs to be serialized?

@vmendi

This comment has been minimized.

Copy link

vmendi commented Jun 6, 2018

We hit the same problem. We are going to go back to .net core 2.0 while we wait for a solution here.

@benjaminpetit

This comment has been minimized.

Copy link
Contributor

benjaminpetit commented Jun 6, 2018

It seems that building OrleansCodegeneration.Build targeting the 2.1 runtime seems to fix the issue at build time. Still testing to see if there is no issue when the silo is up and running.

@nockawa

This comment has been minimized.

Copy link

nockawa commented Jun 7, 2018

@benjaminpetit yes, it should be as the right version of the DLL are then used for the CodeGen...
Is there any drawback to rely on runtime generation instead of build-time? instead of the time overhead at each run?

@sergeybykov

This comment has been minimized.

Copy link
Member

sergeybykov commented Jun 13, 2018

Resolved via #4673.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.