object does not contain a definition for Database and no extension method Database accepting a first argument of type object could be found (are you missing a using directive or an assembly reference?)
UserStore userStore = new UserStore();
userStore.Context.Database.Connection = System.Configuration.ConfigurationManager.
ConnectionStrings["CartDBConnectionString"].ConnectionString;
UserManager<IdentityUser> manager = new UserManager<IdentityUser>(userStore);
Based on the image you supplied you are missing a reference to the following library:
Microsoft.AspNet.Identity.EntityFramework
You can often figure out which Library you are missing by looking up (in MSDN) the object that is giving you the error. In your case (according to your image) the object was IdentityUser . If you do a look up:
IdentityUser
It will point you to the missing assembly I indicated above.
You (first) need to create a reference to this library for you project:
Adding Reference
then add it to your code with the Using Keyword:
using directive
or
Using KeyWord
The error message you posted:
'object' does not contain a definition for 'Database' and no extension
method 'Database' accepting a first argument of type 'object' could be
found (are you missing a using directive or an assembly reference?)
is a little ambiguous and implies another bad/missing reference but I would need to see the code that is triggering that message.
Related
I'm attempting to register the following:
services.AddScoped(typeof(IReadRepository<>), typeof(EfRepository<,>));
However I'm receiving this error message:
Error: Arity of open generic service type 'Harmony.Data.Common.Abstractions.IReadRepository1[T]' does not equal arity of open generic implementation type 'Harmony.Data.SqlServer.EfRepository2[T,TContext]'. (Parameter 'descriptors')
For the resolved to type, the first type param is to be passed as the type argument to IReadRepository. The second param is of type DbContext which has already been registered.
Is there some other trick I'm missing here?
Thank you!
I understand that C# is a staticly typed language and I already read the answers to this SO posting:
initialize a class by string variable in c#?
My question is a bit different, however. I'm working with a T4 template that provides me with the name of a class as a string parameter. I would give the template code here but what's important is that the type is in a string, so it's the same as having this statement in any C# module:
string s = "MyNamespace.Customer.Model";
Using that string, I need to get the type into a Type variable. Normally, I would use this code when I have access to the actual type:
Type typeModel = typeof(MyNamespace.Customer.Model);
How would I be able to obtain the Type given a string? In other words, my code would ideally look something like this (I know this doesn't work because "s" is a string):
Type typeModel = typeof(s);
(I do know what assembly the type is in, by the way, so I can use that information; also, the assembly containing the Type in question is referenced by the template, for what that's worth...)
Note: I do not want to create an object instance of the Type so please don't suggest a solution that requires using Activator.CreateInstance unless that's the only solution...
Thank you for any ideas you can provide.
The method Type.GetType(string typeName) does what you want, but if you only provide the FullName (namespace and name) of the type, it will only resolve types from the current assembly or mscorlib.
You would need to supply an AssemblyQualifiedName if you want to resolve types outside the current assembly. The problem of course is that multiple assemblies can contain different types with the same name and namespace (thanks Steven Liekens):
string aqn = Assembly.CreateQualifiedName(assemblyName, namespaceAndNameOfType);
Type t = Type.GetType(aqn);
If you don't know the assembly beforehand, you could deal with this by:
Loading all assemblies from the current AppDomain.BaseDirectory, or
Using AppDomain.GetAssemblies() for the currently loaded assemblies
And then iterating over each assembly's GetTypes() method.
Error 2 The type or namespace name 'ConnectionOptions' could not be found (are you missing a using directive or an assembly reference?)
C:\Users\user\Documents\Visual Studio 2010\WebSites\Service\App_Code\PService.cs 55 10 C:\...\Service\
when trying to use the code in
[WebMethod]
public ConnectionOptions remoteconnection(string MyComputerName, string ip)
{
ConnectionOptions connOptions = new ConnectionOptions();
return connOptions ;
}
While the same code when copied in webApplication gives no error.I have included using system.Management in both the files..
You define namespace of System.Managment but that’s no enough. Definning simply let
you access class without full name (using namespace). To enable ASP.NET
to know type a reference to the assembly that holds that type is
necessary. Add reference by using "Add reference" sub menu under
"project" menu.
And then check System.Management item and add the reference your project.
I am currently using the following line of code in a web server control to get a reference to the loaded System.Web assembly:
var assembly = AppDomain.CurrentDomain.GetAssemblies()
.Single(i => i.FullName.Contains("System.Web,"));
I am a bit concerned that there could be an occasion where the Single method call fails because (1) the assembly can't be found, or (2) more than one assembly is returned. In the debugger, it looks like there is only one assembly that matches the selector (I've included the comma after System.Web as all of the others show as "System.Web.Whatever"), but this doesn't mean that the FullName of all assemblies loaded will never contain this text).
Is there a better way to identify the reference that I'm looking for so I know that it will always find it correctly?
Thanks.
The best way would be to use a type that you know is in the System.Web assembly, e.g.:
var assembly = typeof(System.Web.HttpContext).Assembly;
When declaring a code-behind method as private (such as an event handler), the compiler ignores it and outputs:
"Compiler Error Message: CS1061: 'ASP.default_aspx' does not contain a definition for 'OnLoginUser' and no extension method 'OnLoginUser' accepting a first argument of type 'ASP.default_aspx' could be found (are you missing a using directive or an assembly reference?)"
In practice, OnLoginUsed does exist, and when the identifier is changed to "public\protected" everything works just fine.
The question is why it is impossible to declare such method as private? after all, it's being called internally by other members of the class.
10x!
Your ASPX page is not the same class as your code behind page. It inherits it and therefore it cannot see the private members. This is why they must be protected or public.