Before I tested this line on a web application in core 5.
services.AddIdentity<Operator, IdentityRole>().AddEntityFrameworkStores<StorageContext>().AddDefaultTokenProviders();
This works fine in startup class.
Now I want to know how to implement it in windows form, Core 7. Because I just get this error -
'IServiceCollection' does not contain a definition for 'AddIdentity'
and no accessible extension method 'AddIdentity' accepting a first
argument of type 'IServiceCollection' could be found (are you missing
a using directive or an assembly reference?)
Am I missing assemblies? what are they?
this is my code now -
static IHostBuilder CreateHostBuilder()
{
return Host.CreateDefaultBuilder()
.ConfigureServices((context, services) =>
{
services.AddScoped<IStorageRepository, StorageRepository>();
services.AddDbContext<StorageContext>(option =>
{
option.EnableSensitiveDataLogging(true);
option.UseSqlServer(configuration["Data:Storage:ConnectionString"]);
});
services.AddIdentity<Operator, IdentityRole>().AddEntityFrameworkStores<StorageContext>().AddDefaultTokenProviders();
});
}
Does this AddIdentity class works in Winforms?
Just try to install Microsoft.AspNetCore.Identity package.
I had the same problem, just try to add this nugget package Microsoft.AspNetCore.Identity.UI. I add it and it start see it
Related
I have this startup.cs file that adds the different services to my application. One of the services I need to add is AddStackExchangeRedisCache but I am getting an error that says
"IServiceCollection does not contain a definition for AddStackExchangeRedisCache and no accessible extension method AddStackExchangeRedisCache accepting a first argument of type IServiceCollection could be found (are you missing a using directive or an asssembly reference?)?"
I have the following stack exchange redis refernce in my CSPROJ
<PackageReference Include="StackExchange.Redis" Version="2.6.66" />
And the method where I am trying to add the service is as follows.
public void ConfigureServices(IServiceCollection services) {
services.AddStackExchangeRedisCache(options =>
{
// some code here
}
}
Install Microsoft.Extensions.Caching.StackExchangeRedis nuget package.
I am upgrading from 5.3.2 to version 5.5.3 and the following code does not compile. I get the errors
'IReceiveEndpointConfigurator' does not contain a definition for 'BindMessageExchanges' and no accessible extension method 'BindMessageExchanges' accepting a first argument of type 'IReceiveEndpointConfigurator' could be found (are you missing a using directive or an assembly reference?)
'IReceiveEndpointConfigurator' does not contain a definition for 'Bind' and no accessible extension method 'Bind' accepting a first argument of type 'IReceiveEndpointConfigurator' could be found (are you missing a using directive or an assembly reference?)
It seems that p is IReceiveEndpointConfigurator and not IRabbitMqReceiveEndpointConfigurator anymore. There seems to be changes on the overloaded methods or extension methods.
What overloaded method should I use instead? The code is used in testscenarios to hook up temporary queues/exchanges. _host is of type IRabbitMqHost
_handle = _host.ConnectReceiveEndpoint(p =>
{
p.BindMessageExchanges = false;
p.Handler<T>(context =>
{
_receivedMessage = context.Message;
_messageReceived.Set();
return Task.CompletedTask;
});
p.Bind<T>(z =>
{
z.ExchangeType = "direct";
z.RoutingKey = _routingKey;
});
});
The method is right there:
https://github.com/MassTransit/MassTransit/blob/develop/src/MassTransit.RabbitMqTransport/IRabbitMqHost.cs#L47
Are you specifying a queue name?
I'm currently trying to create a Logger so I can inject it in Unit Tests. I'm following https://stackoverflow.com/a/43425633/1057052, and it used to work! I then moved the project and reestablished the dependencies, and now I'm getting
'ServiceCollection' does not contain a definition for 'AddLogging' and
no accessible extension method 'AddLogging' accepting a first argument
of type 'ServiceCollection' could be found (are you missing a using
directive or an assembly reference?)
There must be something silly I'm missing. Currently under ASP.NET Core 2.2, and I believe I have assigned the correct dependencies.
https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.dependencyinjection?view=aspnetcore-2.2
https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.dependencyinjection.loggingservicecollectionextensions.addlogging?view=aspnetcore-2.2
I've been reinstalling for the past hour our so! Can't nail what the problem is
Here's the code:
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace Planificacion.UnitTest.Config
{
public class LoggerTestConfig
{
private LoggerTestConfig()
{
}
// https://stackoverflow.com/a/43425633/1057052
public static ILogger<T> GetLoggerConfig<T>() where T : class
{
var serviceProvider = new ServiceCollection()
.AddLogging()
.BuildServiceProvider();
var factory = serviceProvider.GetService<ILoggerFactory>();
return factory.CreateLogger<T>();
}
}
}
The image highlights that the dependency injection dll is referenced, but desired LoggingServiceCollectionExtensions.AddLogging Method as shown in the links provided, indicates
Namespace: Microsoft.Extensions.DependencyInjection
Assembly: Microsoft.Extensions.Logging.dll <----NOTE THIS
Which is not referenced as shown in the image.
Add a reference to the Microsoft.Extensions.Logging.dll assembly stated above.
i was working on a console application and the word "From" wasn't a problem
ex var Best = db.Select<TopSellingGraph>(
db.From<products>
.Join<SalesOrderDetail>());
but when i start to use the servicestack api i always go into this problem
the error message is Error 1 'System.Data.IDbConnection' does not contain a definition for 'From' and no extension method 'From' accepting a first argument of type 'System.Data.IDbConnection' could be found (are you missing a using directive or an assembly reference?)
and i put in the apphost this code
var conString = ConfigurationManager.ConnectionStrings["AdventureWorks"].ConnectionString;
var conFactory = new OrmLiteConnectionFactory(conString, SqlServerDialect.Provider, true);
container.Register<IDbConnectionFactory>(c => conFactory);
i did exactly like the git-hub course
https://github.com/ServiceStack/ServiceStack.OrmLite
anyone have any idea ?
Most of OrmLite's APIs are extension methods over ADO.NET's IDbConnection interfaces which are made available when using the ServiceStack.OrmLite namespace:
using ServiceStack.OrmLite;
Tools like ReSharper help identify, add and can alleviate the burden of dealing with namespaces in C#.
I discovered NHaml some days ago and it's a great project.
When I try to use MVC2 Html helpers like Html.LabelFor(), Html.TextBoxFor(); the views won't compile.
Example:
error CS1061: 'System.Web.Mvc.HtmlHelper' does not contain a definition for 'LabelFor' and no extension method 'LabelFor' accepting a first argument of type 'System.Web.Mvc.HtmlHelper' could be found (are you missing a using directive or an assembly reference?)
0185: textWriter.Write(" ");
0185: textWriter.Write(Convert.ToString(Html.LabelFor(model => model.Username)));
0187: textWriter.WriteLine();
error CS1061: 'System.Web.Mvc.HtmlHelper' does not contain a definition for 'TextBoxFor' and no extension method 'TextBoxFor' accepting a first argument of type 'System.Web.Mvc.HtmlHelper' could be found (are you missing a using directive or an assembly reference?)
0194: textWriter.Write(" ");
0194: textWriter.Write(Convert.ToString(Html.TextBoxFor(model => model.Username)));
0196: textWriter.WriteLine();
I tried to add assemblies and namespaces in the nhaml's Web.config section but it doesn't change anything.
I'm using :
System.Web.Mvc 2.0
.NET Framework 3.5 SP1
Nhaml 1.5.0.2 from git trunk (and tried other builds)
My NHaml configuration is:
<nhaml autoRecompile="true" templateCompiler="CSharp3" encodeHtml="false" useTabs="false" indentSize="2">
It looks like you have an assembly reference problem.
You are probably referencing the MVC 1.0 assemblies, instead of 2.0 assemblies?
The problem is the view class contains a non-generic HtmlHelper. Or some new extension methods requires the ViewData.Model's type.
To correct this problem, change the property and instantiation in NHaml.Web.Mvc/NHamlMvcView.cs.
//public HtmlHelper Html { get; protected set; } // line 42
public HtmlHelper<TModel> Html { get; protected set; }
//Html = new HtmlHelper( viewContext, this ); // line 37
Html = new HtmlHelper<TModel>( viewContext, this );
Rebuild and use :)
As far as I can see the new MVC helpers are not supported, actually only a limited amount of HtmlHelpers are namely LinkExtensions. As a wild guess, you can possibly try to adding the LabelExtensions to the setup of the NHaml viewengine in the NHaml.Web.Mvc/NHamlMvcViewEngine.cs file (since you do have the source) and check if that works.
private void InitializeTemplateEngine()
{
// snip
_templateEngine.Options.AddReference( typeof( LabelExtensions ).Assembly.Location ); // Line 50
}