-
Notifications
You must be signed in to change notification settings - Fork 33
Description
As per the discussion in this thread and specifically using jods4:net8 PR branch
Will open an new issue so not to clutter the other thread
During startup Im having the following exception (which is not from our code but from Orleans)

Full stacktrace
Grace.DependencyInjection.Exceptions.LocateException: 'Could not locate Type System.String
1 Importing System.Collections.Generic.IEnumerable`1[Orleans.Runtime.Hosting.NamedService`1[Orleans.GrainDirectory.IGrainDirectory]]
2 Importing Orleans.Runtime.Hosting.NamedService`1[Orleans.GrainDirectory.IGrainDirectory][]
3 Importing Orleans.Runtime.Hosting.NamedService`1[Orleans.GrainDirectory.IGrainDirectory]
4 Importing System.String for constructor parameter name
'
Alto seeing the code its seems "intended" as its marked as required and no default
Usage in Microsoft Orleans (not our source)
return serviceProvider.GetServices<NamedService<IGrainDirectory>>() ?? Enumerable.Empty<NamedService<IGrainDirectory>>();
Registration in Microsoft Orleans (not our source)
UPDATE NOTE: this doesn't get invoked when debugging
public static IServiceCollection AddGrainDirectory<T>(this IServiceCollection collection, string name, Func<IServiceProvider, string, T> implementationFactory)
where T : IGrainDirectory
{
collection.AddSingleton(sp => new NamedService<IGrainDirectory>(name, implementationFactory(sp, name)));
// Check if the grain directory implements ILifecycleParticipant<ISiloLifecycle>
if (typeof(ILifecycleParticipant<ISiloLifecycle>).IsAssignableFrom(typeof(T)))
{
collection.AddSingleton(s => (ILifecycleParticipant<ISiloLifecycle>)s.GetGrainDirectory(name));
}
return collection;
}
This is our config for grace (though tried to comment the Behaviors but still the same)
var graceConfig = new InjectionScopeConfiguration
{
Behaviors =
{
AllowInstanceAndFactoryToReturnNull = true,
}
};
Not sure if we need to configure something specifically, or its a bug
To isolate the issue, I added a very basic test to test similar what they are doing however that succeeds

test source
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Specification;
using System;
using System.Linq;
using Xunit;
namespace Grace.DependencyInjection.Extensions.Tests
{
public class GraceContainerTests : DependencyInjectionSpecificationTests
{
protected override IServiceProvider CreateServiceProvider(IServiceCollection serviceCollection)
{
return new DependencyInjectionContainer(x => x.Behaviors.AllowInstanceAndFactoryToReturnNull = true)
.Populate(serviceCollection);
}
[Fact]
public void GetServices()
{
var services = new ServiceCollection()
.AddSingleton(sp => new NamedService<IHeroesIndex> { Name = "name", Value = new HeroesIndex() })
;
var providers = CreateServiceProvider(services);
var q = providers.GetServices<NamedService<IHeroesIndex>>() ?? Enumerable.Empty<NamedService<IHeroesIndex>>();
Assert.NotEmpty(q);
}
}
}
public class NamedService<T>
{
public string Name { get; set; }
public T Value { get; set; }
}
public interface IHeroesIndex
{
}
public class HeroesIndex : IHeroesIndex
{
}
Also replicated the issue with a basic Orleans sample (and also isolate it from our stuff)
- Clone https://github.com/stephenlautier/dotnet.samples/blob/feature/grace-sample/orleans/Adventure/README.md
- Link Grace projs to your branch
- Simply run
AdventureServer
You should get the above exception on launch