Bot Framework v4.4.3 Update Skill Manifest Template - c#

The document here says update skill manifest but does not specify how to add a new skill in the manifest file.
I have the following in the main dialog:
case MasterCollectionsLuis.Intent.PlayVideo:
{
turnResult = await dc.BeginDialogAsync(nameof(Water.PlayVideo.PlayVideoDialog));
break;
}
And have a base for PlayVideo and the Dialog itself as shown by the example SampleDialog and SampleDialogBase.
When I load the manifest file at http://localhost:1205/api/skill/manifest:
An unhandled exception occurred while processing the request.
InvalidOperationException: Unable to resolve service for type 'MasterCollections.Dialogs.Water.PlayVideo.PlayVideoDialog' while attempting to activate 'MasterCollections.Dialogs.MainDialog'.
Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateArgumentCallSites(Type serviceType, Type implementationType, CallSiteChain callSiteChain, ParameterInfo[] parameters, bool throwIfCallSiteNotFound)

Dependency Injection error
That error is to do with the dependency injection pipeline, without setting your Startup.cs file my best guess is that you haven't wired up PlayVideoDialog in there.
In your Startup.cs file you will have a section where you register your Dialogs against the dependency injection service provider like so:
services.AddTransient<CancelDialog>();
services.AddTransient<EscalateDialog>();
services.AddTransient<MainDialog>();
You simply need to add another line each time you add a new Dialog:
services.AddTransient<MyNewDialog>();
In your case you would have PlayVideoDialog in place of MyNewDialog.
Also make sure that you are not passing a PlayVideoDialog parameter into the constructor of MainDialog as this is not how Dialogs work, you should instead call the AddDialog(new PlayVideoDialog(...)) method inside the constructor of MainDialog.
Skills manifest question
I haven't created a skill myself but there is additional documentation which may or may not be helpful about adding skill support, adding skills, and the skills manifest file itself.
In the documentation that you linked it states:
this has been pre-populated with the Skill ID and name and a sample action which you can modify at this stage if required
which leads me to believe you can manually modify this file to fit your requirements, but you don't have to modify it if there are no changes required.

Related

Fluxor Blazor error on assembly scanning and registration

I've followed the steps of setting up a Fluxor library.
Added
var currentAssembly = typeof(Program).Assembly; builder.Services.AddFluxor(options => options.ScanAssemblies(currentAssembly));
into the Program.cs. Then added <Fluxor.Blazor.Web.StoreInitializer/> into App.Razor
Stater is decorated with [FeatureState] attribute. Everything according to documention. But the application fails to start with the message :
ArgumentException: An item with the same key has already been added. Key: Store.Account.AccountTopUpState
Seems like the problem exists in Fluxor assembly scanning ...
Are you also creating a class deriving from Feature<AccountTopUpState>? If so, remove the [FeatureState] attribute. I believe the attribute was added as an alternative to the Feature base class approach, and you should choose one approach or the other, but not both.

Blazor Error: "There is no registered service of type" -- other StackOverflow questions do not solve

In my .Net CORE 5 (imported support files v5.0.12) Blazor PWA VS-2019 solution, I "had" a working 'Customer'-(data/app)service and Blazor pages to List and CRUD the Customer records (works as expected). I created similar 'Vehicle' files for both the SERVER-project and the CLIENT-project (of course changing the model field-references).
There are NO compilation errors yet, when I try to show the "VehicleList" page, this error appears in the Output-window:
crit:
Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
Unhandled exception rendering component: Cannot provide a value for property '_vehicleService' on type
'MyCore5AppPWA.Client.Pages.VehicleList'. There is no registered
service of type 'MyCore5AppPWA.Client.Services.IVehicleService'.
System.InvalidOperationException: Cannot provide a value for property
'_vehicleService' on type 'MyCore5AppPWA.Client.Pages.VehicleList'.
There is no registered service of type
'MyCore5AppPWA.Client.Services.IVehicleService'. at
Microsoft.AspNetCore.Components.ComponentFactory.<>c__DisplayClass6_0.g__Initialize|2(IServiceProvider
serviceProvider, IComponent component)
Please note the above notation of "...c__DisplayClass6_0..." that is curious to me (not knowing the significance of this).
I have read many of the similar questions/answers related to the subject of this post that do not correct the error.
Here is a snippet from the Startup.cs file:
public void ConfigureServices(IServiceCollection services) {
_ = services.AddDbContext<AppDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DbConnection")));
services.AddScoped<ICustomerRepository, CustomerRepository>();
services.AddScoped<IVehicleRepository, VehicleRepository>();
services.AddControllersWithViews();
services.AddRazorPages();
services.AddScoped<WeatherForecastService>();
}
Here is the snippet from the "VehicleList.razor' code file.
//html... declarations.
#layout MainLayout
#page "/vehiclelist"
#using MyCore5AppPWA.Client.Services;
#using MyCore5AppPWA.Shared
//...html omitted...//
#code {
[Inject]
private IVehicleService _vehicleService { get; set; }
[Inject]
private NavigationManager navigationManager { get; set; } ...other code...
I also have in the SERVER-project/Controllers subfolder a "CustomerController.cs" and a "VehicleController.cs".
Since I am rather new to Blazor/Core-5/PWA, I conclude that I am missing something regarding adding new service(s) to the PWA projects.
Your comments and suggestions are very welcome. thanks John
You are injecting a IVehicleService in your VehicleList.razor file. But it doesn't seem like you've registered any implementation of this interface in your DI container?
There is no registered service of type 'MyCore5AppPWA.Client.Services.IVehicleService
Something like
services.AddScoped<IVehicleService, YourImplementation>();
should solve it.
Note that you need to register it with the correct lifetime (Singleton, Scoped or Transient) depending on your implementation.
Dependency injection issues typically surface at runtime because the class consuming these services won’t know they aren’t registered to the container until they request them at runtime. In your case the exception is saying you forgot to register an implementation of IVehicleService. You can register it like any other service by calling .AddScoped<> to your ConfigureServices method.
Thanks to #JOSEFtw for his helpful replies. This led me to the solution to this question.
The Blazor PWA web-app has a SERVER project and a CLIENT-SIDE project. The question stated and #JOSEFtw pointed out that the 'issue' was with the 'Client.Services.IVehicleService' not being registered.
After my comments-thread with #JOSEFtw I thought that something that #JOSEFtw was trying to tell me was not in my realm of consciousness. I made "searches' into the VS-2019 source-files which showed that the client-services are registered in the CLIENT-project's Program.cs file. I discovered this by searching for "CustomerService" text and I found it there. The problem was solved by adding the "IVehicleService, VehicleService" references to the Program.cs file as follows:
builder.Services.AddHttpClient<IVehicleService, VehicleService>(client => {
client.BaseAddress = new Uri(builder.HostEnvironment.BaseAddress);
});
I mistakenly thought that the 'repository' interface and implementation classes were registered in the SERVER'S Startup.cs which had the newly added Vehicle-repository references, was all that was necessary to register the services (even client-side services -- me stupid). But I did not know about the Program.cs file for the registration of the client-side registration as a separate registration process.
My lower knowledge of Blazor PWA and C# contributed to this question and comments with #JOSEFtw. Of course we all learn from our mistakes. Thanks to all.

Simple Injector: Unable to register generic types in the constructor when registering a collection

I have a list of Funcs which contains the types and their arguments which i need to register to the container:
var LogCreaters = new List<Func<ILogFormat, FolderLocation, ILogWriter>>
{
(fmt,path)=> new NlogWriter(new NlogConfiguration(fmt,path.logging)),
(fmt,path)=> new DisplayWriter(fmt)
}
This is how I'm trying to register the collection:
container.Collection.Register<ILogWriter>(LogCreaters);
Followed by:
foreach (var item in LogCreater)
{
container.Collection.Append<ILogWriter>(
() => item(LogFormat, FolderLocation), LifeSpan.Scoped);
}
But container.Verify() throws the following exception:
The configuration is invalid. Creating the instance for type Logger
failed. The constructor of type NlogWriter contains the parameter with
name 'config' and type NlogConfiguration, but NlogConfiguration is not
registered. For NlogConfiguration to be resolved, it must be
registered in the container.
What I'm guessing is that the type NlogWriter is registered in the container but it's constructor arguments are not getting registered in the process. How would i be able to register the LogCreators along with their constructors and the types in the constructor arguments to the container in my current scenario.
I asked this question recently about how to register a collection, in which my question was answered but i guess i wasnt able to explain my current scenario properly, hence i'm posting this again with more detail.
TIA.

Using a "shared" type on a WCF/MVC project with two services ("cannot convert from...")

I've two WCF services connected to my client. I want to use a User-object, retrieved from service #1, and use this as paramter for service #2. Here is my MVC-Controller TournamentController.cs code:
private readonly GCTournamentServiceClient _tournamentClient = new GCTournamentServiceClient();
public ActionResult Join(int id)
{
GCUserServiceClient userClient = new GCUserServiceClient();
// Get current user
var currentUser = userClient.GetUser(0);
if (currentUser != null)
{
// Get selected tournament
var selectedTournament = _tournamentClient.GetTournament(id);
// Check if there are available seats in the tournament
if (selectedTournament.Seats > selectedTournament.RegistredUsers.Count)
{
// Check if user exist amoung registred users
if (!selectedTournament.RegistredUsers.Contains(currentUser))
{
selectedTournament?.RegistredUsers.Add(currentUser);
}
}
}
}
The error Visual Studio prompt me with:
Argument 1: cannot convert from 'GConnect.Clients.WebClient.GCUserService.User' to 'GConnect.Clients.WebClient.GCTournamentService.User'
So the problem is currentUser, which has the type GCUserService.User. I'm unable to use this as parameter for RegistredUsers
The error itself makes perfect sense, however, I'm not quite sure how I'm suppose to convert this type (properly). Some articles states, that a "shared"-service has to be created, which holds the User-type. I just can't believe, that a solution like that, should be necessary.
I might have misunderstood some basic stuff here (working with WCF and MVC), but please enlighten me, if that's the case.
So the problem is currentUser, which has the type GCUserService.User.
I'm unable to use this as parameter for RegistredUsers
There are 2 approaches to solve this problem:
1)
Create a class library project (Visual Studio) and add the User class in that project, compile it and add its assembly's (.dll) reference to both services and the client (your MVC application). Next retrieve that user object as you are already doing it
var currentUser = userClient.GetUser(0);
GetUser will return the type of User that is defined in a separate assembly which is added as reference as suggested above. The TournamentService will also reference the same assembly and the RegistredUsers.Add(User userToadd) method will take the same User object and WCF runtime should be able to serialise/desterilise it.
2)
In your MVC client application, new up the User object that is acceptable by the TournamentService.RegistredUsers.Add method. Populate its properties from the currentUser and pass in that object as parameter to RegistredUsers.Add method.
Best Practice
Ideally, I would recommend the first approach which is more work but a better practice and that your User class is maintained centrally and code is reused.
Hope this helps!

Simple Injector and default AccountContoller dependency issue

I have problem with Simple Injector in my Web Api project. I user default AccountController generated by VS.
public AccountController(ApplicationUserManager userManager,
ISecureDataFormat<AuthenticationTicket> accessTokenFormat)
In my configuration file I register:
var container = new Container();
// This is an extension method from the integration package.
container.RegisterWebApiFilterProvider(config);
container.RegisterWebApiControllers(config);
container.Register<IInitializeService, InitializeService>();
container.Register<IFolderRepository, FolderRepository>();
container.Register<IUserRepository, UserRepository>();
container.Register<ILogger, Logger>();
//Authentication Wrap
container.Register<IUserStore<User, Guid>, ApplicationUserStore>();
container.Register<IDataSerializer<AuthenticationTicket>, TicketSerializer>();
container.Register<ISecureDataFormat<AuthenticationTicket>,
SecureDataFormat<AuthenticationTicket>>();
container.Register<IDataProtector>(
() => new DpapiDataProtectionProvider().Create("ASP.NET Identity"));
container.Verify();
// 4. Register the container as MVC3 IDependencyResolver.
DependencyResolver.SetResolver(new SimpleInjectorWebApiDependencyResolver(container));
config.DependencyResolver = new SimpleInjectorWebApiDependencyResolver(container);
I though that Simple Injector will be smart enough to handle all build in dependences responsible for default identity and i wont need to register them manually, but I'm getting exceptions if I wont register them.
Still getting an exception:
The constructor of type SecureDataFormat contains the parameter of type ITextEncoder with name 'encoder' that is not registered. Please ensure ITextEncoder is registered in the container, or change the constructor of SecureDataFormat.
Is there any way to handle that automatically?
I implemented a Web Api and I wrote this code.
This works for me
container.RegisterWebApiRequest<ISecureDataFormat<AuthenticationTicket>, SecureDataFormat<AuthenticationTicket>>();
container.RegisterWebApiRequest<ITextEncoder, Base64UrlTextEncoder>();
container.RegisterWebApiRequest<IDataSerializer<AuthenticationTicket>, TicketSerializer>();
container.RegisterWebApiRequest<IDataProtector>(() => new Microsoft.Owin.Security.DataProtection.DpapiDataProtectionProvider().Create("ASP.NET Identity"));
How is the container supposed to know which implementation of ITextEncoder you want to use in the constructor of SecureDataFormat?
You have to tell it which one to use. I think the rules basically go something like this:
if an interface is required (by a constructor) then it needs to know which implementation to use. If a concrete class is required it will automatically build an instance of that class (assuming it can resolve all the types that class needs).
As your SecureDataForms needs an interface you have to register one, otherwise its only option would be to 'guess' at which implementation you want and this could then go wrong silently if more than one implementation existed.
I just came up against this issue. I'm using ninject but you'll get the idea. Here is my binding:
kernel.Bind<ITextEncoder>().To<Base64UrlTextEncoder>();
According to the source, the only thing I ever see being used to new up an instance of SecureDataFormat is Base64UrlTextEncoder. So it seemed like a safe bet to use, but it's certainly not clear to me at first glance how to appropriately use this constructor overload.

Categories

Resources