1

Application works as it should be on Debug mode.

On Release mode I am getting exception saying

Exception thrown: 'Autofac.Core.Registration.ComponentNotRegisteredException' in Autofac.dll

Additional information: The requested service 'Microsoft.Extensions.Options.IOptions`1[[TIKSN.GroceryChecklist.Models.Configuration.HockeyAppConfiguration, Models, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' has not been registered. To avoid this exception, either register a component to provide the service, check for service registration using IsRegistered(), or use the ResolveOptional() method to resolve an optional dependency.

This is the line that throws exception

var hockeyAppOptions = serviceProvider.GetRequiredService<IOptions<HockeyAppConfiguration>>();

But this option is configured and works fine in Debug mode.

services.Configure<HockeyAppConfiguration>(option =>
        {
            option.AppID = "my key";

        });

I also tried to add type registration line in Default.rd.xml file but it did not work neither.

<Type Name="Microsoft.Extensions.Options.IOptions{TIKSN.GroceryChecklist.Models.Configuration.HockeyAppConfiguration}" Dynamic="Required Public" />
Community
  • 1
  • 1
TIKSN
  • 615
  • 1
  • 6
  • 24

1 Answers1

1

I found a solution. I added this line and run on Debug mode.

Debug.WriteLine($"hockeyAppOptions.Type is {hockeyAppOptions.GetType().FullName}");

Output were

hockeyAppOptions.Type is Microsoft.Extensions.Options.OptionsManager`1[[TIKSN.GroceryChecklist.Models.Configuration.HockeyAppConfiguration, Models, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]

So I replaced previous like in RD.XML with

<Type Name="Microsoft.Extensions.Options.OptionsManager{TIKSN.GroceryChecklist.Models.Configuration.HockeyAppConfiguration}" Dynamic="Required Public" />

And it worked.

TIKSN
  • 615
  • 1
  • 6
  • 24
  • Hello! Very happy to see you're not blocked. Presumably we (the .NET Native compiler) can do a better job here. Alternately, there may be a small edit to Autofac that can give help us do the right analysis. I'll make a note to investigate some options and follow up with Autofac if necessary. – MattWhilden Sep 09 '16 at 23:28