OrleansContrib / Orleans.Indexing-1.5

MIT License
27 stars 6 forks source link

Code Gen Fails #4

Open alfkonee opened 5 years ago

alfkonee commented 5 years ago

Hello there I'm tring to use the OrleansV2.Fork.Indexing Repo and Everytime I try to run I get this

-- Code Generation FAILED --

  Exc level 0: System.TypeLoadException: Access is denied: 'Orleans.GrainState`1[Orleans.Indexing.IndexWorkflowQueueEntry]'.
     at OrleansGeneratedCode.OrleansCodeGen2b7062df33FeaturePopulator.Populate(SerializerFeature feature)
     at Orleans.ApplicationParts.AssemblyAttributeFeatureProvider`1.PopulateFeature(IEnumerable`1 parts, TFeature feature) in D:\build\agent\_work\17\s\src\Orleans.Core\ApplicationParts\AssemblyAttributeFeatureProvider.cs:line 44
     at Orleans.ApplicationParts.ApplicationPartManager.PopulateFeature[TFeature](TFeature feature) in D:\build\agent\_work\17\s\src\Orleans.Core\ApplicationParts\ApplicationPartManager.cs:line 49
     at Orleans.ApplicationPartManagerExtensions.CreateAndPopulateFeature[TFeature](IApplicationPartManager applicationPartManager) in D:\build\agent\_work\17\s\src\Orleans.Core\ApplicationParts\ApplicationPartManagerExtensions.cs:line 60
     at Orleans.CodeGenerator.RoslynCodeGenerator..ctor(IApplicationPartManager partManager, ILoggerFactory loggerFactory) in D:\build\agent\_work\17\s\src\Orleans.CodeGeneration\RoslynCodeGenerator.cs:line 43
     at Orleans.CodeGeneration.CodeGenerator.GenerateSourceForAssembly(Assembly grainAssembly, LogLevel logLevel)
     at Orleans.CodeGeneration.CodeGenerator.GenerateCodeInternal(CodeGenOptions options)
     at Orleans.CodeGeneration.CodeGenerator.GenerateCode(CodeGenOptions options)
     at Orleans.CodeGeneration.Program.Main(String[] args)

Can anyone point me to some info on how to solve this??

I looked up the code for the failing class and it seems to be internal Could that be the reason???

ReubenBond commented 5 years ago

@alfkonee is seems like it could be a permissions issue, since you're getting an "Access is denied" error while trying to load a particular type.

Try ensuring that the user you're building as has access to all files in your build output.

If you have more information about your environment, that might be useful

alfkonee commented 5 years ago

@ReubenBond I'm experimenting with Orleans for the first ime in a while Currently I'm using the following Libraries Orleans.Extensibility.IdentityServer Microsoft.Orleans.Indexing (Self Build as I couldn't find the nuget even in the CI) and the ADONET Persistence Library with Mysql Db

Here's my SiloBuilder

var builder = new SiloHostBuilder()
                    .UseLocalhostClustering() //TODO Configure Cluster Networking
                    .Configure<ClusterOptions>(options =>
                    {
                        options.ClusterId = "dev"; //TODO: Use Config
                        options.ServiceId = "ElyfeCentralServer"; //TODO Use Config
                    })
                    .ConfigureApplicationParts(config =>
                    {
                        config.AddApplicationPart(typeof(IUserProfileGrain).Assembly); //This is from the IdentityServer Extention Library
                        config.AddApplicationPart(typeof(UserGrain).Assembly).WithReferences();
                        config.AddApplicationPart(typeof(RoomGrain).Assembly).WithReferences();
                    })

                    .AddAdoNetGrainStorageAsDefault(options =>
                    {
                        options.ConnectionString = configString;
                        options.Invariant = "MySql.Data.MySqlClient";

                        options.UseJsonFormat = true;
                    })
                    .AddAdoNetGrainStorageAsDefault(options =>
                    {
                        options.ConnectionString = "IndexingStorageProvider";
                        options.Invariant = "MySql.Data.MySqlClient";

                        options.UseJsonFormat = true;
                    })
                    .UseIndexing()
                     .UseDashboard(options => { options.Port = 8085; })
                    .ConfigureLogging(logging => logging.AddConsole());
                var host = builder.Build();
                await host.StartAsync();
                Console.WriteLine("Silo Strarted....\nPress Enter to Terminate.");
                Console.ReadLine();

I had the .WithReferences() Extension on this config.AddApplicationPart(typeof(IUserProfileGrain).Assembly) but that was givinv me the Error Above when run but after the removal the Error Went away but now I'm facing a new Error forn the UseIndexing() Extension Detailed Below

System.MethodAccessException: Attempt by method 'Orleans.Indexing.SiloBuilderExtensions.UseIndexing(Microsoft.Extensions.DependencyInjection.IServiceCollection, System.
Action`1<Orleans.Configuration.OptionsBuilder`1<Orleans.Indexing.IndexingOptions>>)' to access method 'Orleans.Configuration.ServiceCollectionExtensions.AddFromExisting
<Orleans.Indexing.IIndexFactory,Orleans.Indexing.IndexFactory>(Microsoft.Extensions.DependencyInjection.IServiceCollection)' failed.                                    
   at Orleans.Indexing.SiloBuilderExtensions.UseIndexing(IServiceCollection services, Action`1 configureAction) in D:\Sources\OrleansV2.Fork.Indexing\src\Orleans.Indexi
ng\Hosting\SiloBuilderExtensions.cs:line 35                                                                                                                             
   at Orleans.Indexing.SiloBuilderExtensions.<>c__DisplayClass1_0.<UseIndexing>b__0(IServiceCollection services) in D:\Sources\OrleansV2.Fork.Indexing\src\Orleans.Index
ing\Hosting\SiloBuilderExtensions.cs:line 25                                                                                                                            
   at Orleans.Hosting.ServiceProviderBuilder.BuildServiceProvider(HostBuilderContext context) in D:\build\agent\_work\17\s\src\Orleans.Core\Hosting\ServiceProviderBuild
er.cs:line 25                                                                                                                                                           
   at Orleans.Hosting.SiloHostBuilder.Build() in D:\build\agent\_work\17\s\src\Orleans.Runtime\Hosting\Generic\SiloHostBuilder.cs:line 43                               
   at Elyfe.Orleans.Server.Program.RunMainAsync(String[] args) in D:\Sources\Elyfe\src\Servers\Elyfe.Orleans.Server\Program.cs:line 60

Dev Env Visual Studio 2017 15.8.4 Dotnet Env

.NET Core SDK (reflecting any global.json):
 Version:   2.1.402
 Commit:    3599f217f4

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.17134
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\2.1.402\

Host (useful for support):
  Version: 2.1.4
  Commit:  85255dde3e

.NET Core SDKs installed:
  2.1.202 [C:\Program Files\dotnet\sdk]
  2.1.400 [C:\Program Files\dotnet\sdk]
  2.1.401 [C:\Program Files\dotnet\sdk]
  2.1.402 [C:\Program Files\dotnet\sdk]
ReubenBond commented 5 years ago

There's a LoaderExceptions property on the TypeLoadException which might give more information.

alfkonee commented 5 years ago

the Inner Exception of both scenarios is null ie with the .WithRefrences() and without

alfkonee commented 5 years ago

From my little investigation internal classes aren't accesible during the Codegen for this Library @ReubenBond Could you investigate and confirm

I hope I'm not doing anything wrong cus I really want to help test this and make an effort to make it production ready

ReubenBond commented 5 years ago

Internal types are not accessible during codegen when codegen is executed at runtime, but they are accessible when it's executed at build time (because the generated code lives in the same project). That shouldn't be the cause for this, though - the exception might come from Windows... maybe filesystem permissions. Does it happen if you run as Administrator?

alfkonee commented 5 years ago

I still get the MethodAccessException Even in Admin Mode

System.MethodAccessException: Attempt by method 'Orleans.Indexing.SiloBuilderExtensions.UseIndexing(Microsoft.Extensions.DependencyInjection.IServiceCollection, System.Action`1<Orleans.Configuration.OptionsBuilder`1<Orleans.Indexing.IndexingOptions>>)' to access method 'Orleans.Configuration.ServiceCollectionExtensions.AddFromExisting<Orleans.Indexing.IIndexFactory,Orleans.Indexing.IndexFactory>(Microsoft.Extensions.DependencyInjection.IServiceCollection)' failed.
   at Orleans.Indexing.SiloBuilderExtensions.UseIndexing(IServiceCollection services, Action`1 configureAction) in D:\Sources\OrleansV2.Fork.Indexing\src\Orleans.Indexing\Hosting\SiloBuilderExtensions.cs:line 35
   at Orleans.Indexing.SiloBuilderExtensions.<>c__DisplayClass1_0.<UseIndexing>b__0(IServiceCollection services) in D:\Sources\OrleansV2.Fork.Indexing\src\Orleans.Indexing\Hosting\SiloBuilderExtensions.cs:line 25
   at Orleans.Hosting.ServiceProviderBuilder.BuildServiceProvider(HostBuilderContext context) in D:\build\agent\_work\17\s\src\Orleans.Core\Hosting\ServiceProviderBuilder.cs:line 25
   at Orleans.Hosting.SiloHostBuilder.Build() in D:\build\agent\_work\17\s\src\Orleans.Runtime\Hosting\Generic\SiloHostBuilder.cs:line 43
   at Elyfe.Orleans.Server.Program.RunMainAsync(String[] args) in D:\Sources\Elyfe\src\Servers\Elyfe.Orleans.Server\Program.cs:line 70
ReubenBond commented 5 years ago

@alfkonee This seems like a (Code Access Security](https://docs.microsoft.com/en-us/dotnet/framework/misc/code-access-security-basics) issue. Could you tell me how your project is set up and what the runtime environment is?

I was under the impression that you're running on .NET Core - are you?

alfkonee commented 5 years ago

I'm using .Net Core as shown in my previous post

@ReubenBond I'm experimenting with Orleans for the first ime in a while Currently I'm using the following Libraries Orleans.Extensibility.IdentityServer Microsoft.Orleans.Indexing (Self Build as I couldn't find the nuget even in the CI) and the ADONET Persistence Library with Mysql Db

Here's my SiloBuilder

var builder = new SiloHostBuilder()
                    .UseLocalhostClustering() //TODO Configure Cluster Networking
                    .Configure<ClusterOptions>(options =>
                    {
                        options.ClusterId = "dev"; //TODO: Use Config
                        options.ServiceId = "ElyfeCentralServer"; //TODO Use Config
                    })
                    .ConfigureApplicationParts(config =>
                    {
                        config.AddApplicationPart(typeof(IUserProfileGrain).Assembly); //This is from the IdentityServer Extention Library
                        config.AddApplicationPart(typeof(UserGrain).Assembly).WithReferences();
                        config.AddApplicationPart(typeof(RoomGrain).Assembly).WithReferences();
                    })

                    .AddAdoNetGrainStorageAsDefault(options =>
                    {
                        options.ConnectionString = configString;
                        options.Invariant = "MySql.Data.MySqlClient";

                        options.UseJsonFormat = true;
                    })
                    .AddAdoNetGrainStorageAsDefault(options =>
                    {
                        options.ConnectionString = "IndexingStorageProvider";
                        options.Invariant = "MySql.Data.MySqlClient";

                        options.UseJsonFormat = true;
                    })
                    .UseIndexing()
                     .UseDashboard(options => { options.Port = 8085; })
                    .ConfigureLogging(logging => logging.AddConsole());
                var host = builder.Build();
                await host.StartAsync();
                Console.WriteLine("Silo Strarted....\nPress Enter to Terminate.");
                Console.ReadLine();

I had the .WithReferences() Extension on this config.AddApplicationPart(typeof(IUserProfileGrain).Assembly) but that was givinv me the Error Above when run but after the removal the Error Went away but now I'm facing a new Error forn the UseIndexing() Extension Detailed Below

System.MethodAccessException: Attempt by method 'Orleans.Indexing.SiloBuilderExtensions.UseIndexing(Microsoft.Extensions.DependencyInjection.IServiceCollection, System.
Action`1<Orleans.Configuration.OptionsBuilder`1<Orleans.Indexing.IndexingOptions>>)' to access method 'Orleans.Configuration.ServiceCollectionExtensions.AddFromExisting
<Orleans.Indexing.IIndexFactory,Orleans.Indexing.IndexFactory>(Microsoft.Extensions.DependencyInjection.IServiceCollection)' failed.                                    
   at Orleans.Indexing.SiloBuilderExtensions.UseIndexing(IServiceCollection services, Action`1 configureAction) in D:\Sources\OrleansV2.Fork.Indexing\src\Orleans.Indexi
ng\Hosting\SiloBuilderExtensions.cs:line 35                                                                                                                             
   at Orleans.Indexing.SiloBuilderExtensions.<>c__DisplayClass1_0.<UseIndexing>b__0(IServiceCollection services) in D:\Sources\OrleansV2.Fork.Indexing\src\Orleans.Index
ing\Hosting\SiloBuilderExtensions.cs:line 25                                                                                                                            
   at Orleans.Hosting.ServiceProviderBuilder.BuildServiceProvider(HostBuilderContext context) in D:\build\agent\_work\17\s\src\Orleans.Core\Hosting\ServiceProviderBuild
er.cs:line 25                                                                                                                                                           
   at Orleans.Hosting.SiloHostBuilder.Build() in D:\build\agent\_work\17\s\src\Orleans.Runtime\Hosting\Generic\SiloHostBuilder.cs:line 43                               
   at Elyfe.Orleans.Server.Program.RunMainAsync(String[] args) in D:\Sources\Elyfe\src\Servers\Elyfe.Orleans.Server\Program.cs:line 60

Dev Env Visual Studio 2017 15.8.4 Dotnet Env

.NET Core SDK (reflecting any global.json):
 Version:   2.1.402
 Commit:    3599f217f4

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.17134
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\2.1.402\

Host (useful for support):
  Version: 2.1.4
  Commit:  85255dde3e

.NET Core SDKs installed:
  2.1.202 [C:\Program Files\dotnet\sdk]
  2.1.400 [C:\Program Files\dotnet\sdk]
  2.1.401 [C:\Program Files\dotnet\sdk]
  2.1.402 [C:\Program Files\dotnet\sdk]

I read the doc you posted but I don't think that's the issue. Cus fromwhat I know internal classes are not accessible outside the libraries they are defined cus on the internal definition. And the orleans code gen occurs for this library outside of the library after the initail build of the library in my Project.

Is there a way to bypass this behaviour cus I know it wll not be possible to generate Grain Definitions before the code is written for the grains. So I'd suggeest maybe making the internal Classes need for Codegen Public?

ReubenBond commented 5 years ago

From your exception message, it looks like you're running Orleans versions from build machines, but this repository is currently a fork of Orleans which modifies some internals of Orleans (there's some history behind why - and that situation will be resolved soon).

That means you need to use the packages built by the code in this repository and not from NuGet.

If you run build.cmd from the root the packages should be created and you can use them as a local source or upload them to MyGet.

This is something which we are in the process of rectifying.

alfkonee commented 5 years ago

@ReubenBond You were right my Silo Project wasn't updated to the same build version as my Interfaces and Grains. After the Update everything works fine

Will be waiting for the update that Brings all these bits to the public Nuget Do you have any tentative timeline for when this will happen