Skip to content

What is needed for ActivatorUtilities.CreateInstance to work with .NET Native? #3375

Open
@gewarren

Description

@gewarren

Issue moved from dotnet/docs#18729


From @mc0re on Monday, June 1, 2020 5:47:26 PM

The following code runs fine without Native compilation, but fails with it. What do I miss?

var services = new ServiceCollection();
services
    .AddAutoMapper(typeof(DtoMappingProfile))
    .AddLogging(configure => configure.AddSerilog(dispose: true))
    .AddSingleton<IHashCalculator, HashCalculator>()
    .AddSingleton<IMyHttpClient, MyHttpClient>()
    .AddSingleton<IPropertySet>(ApplicationData.Current.LocalSettings.Values)
    ;

// This is a field in the page class
mServices = services.BuildServiceProvider();
ActivatorUtilities.CreateInstance<AuthViewModel>(mServices)

AuthViewModel has the following contructor:

public AuthViewModel(IMyHttpClient client, IPropertySet settings)

Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions