I have tried to follow the steps described in this link in order to pull out my identity class from the web application into its own class library.
http://www.umbraworks.net/bl0g/rebuildall/2013/10/22/Moving_ASP_NET_Identity_model_into_another_assembly
I do as follows:
Created a web form project and named it 3TierExample.
Created new class class library called 3TierExample.Model.
Installed Microsoft ASP.NET Identity EntityFramework package from NuGet into 3TierExample.Model
Moved identityModel.cs to the new class library (3TierExample.Model)
Added a reference to 3TierExample.Model in 3TierExample
Then for the identityModel.cs I use the following references:
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
using Microsoft.Owin.Security;
using System.Web;
using System;
using _3TierExample.Models;
My namespace is as follows:
namespace _3TierExample.Models{…}
However when I finish I get the following errors:
I:..\3TierExample\3TierExample\Default.aspx: ASP.NET runtime error: Could not load file or assembly 'Microsoft.AspNet.Identity.Core, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference.
(Exception from HRESULT: 0x80131040)
I:...\3TierExample\3TierExample\Default.aspx 1 1 3TierExample
Metadata file 'I:..\3TierExample\3TierExample.Model\bin\Debug\3TierExample.Model.dll' could not be found
The type or namespace name 'HttpRequest' could not be found (are you missing a using directive or an assembly reference?) I:...\3TierExample
The type or namespace name 'HttpResponse' could not be found (are you missing a using directive or an assembly reference?) I:...\3TierExample
If I go to the web project I see that the reference to the newly created class library is there, so I don’t know how is it possible to get the first error (No 3). Then, the second error happens as a consequence, I think, of not finding the assembly reference. Why? The reference is there!?
Can anybody help?
Thank you in advance!!
There is an assembly conflicts.
When you create project, it could be having old version Asp.net Identity assemblies. You installed latest Asp.net Identity Packages in your class lib proj. If you want to separate Asp.net Identity Context from the main project, you don't need that framework in your web proj.
you can set No Authentication while creating your web project, which make sure there will not be conflicts when reference to Asp.net Identity Class Lib Project. You may require to copy IdentityModels.cs from sample Web Project in order to use in Class Lib Proj.
Related
I have added a Microsoft.Owin.Security.OpenIdConnect.dll externally(tried both methods using Package Manager Console and using add reference ) to my ASP.NET MVC Application, but still get the same error.
The type or namespace name 'OpenIdConnect' does not exist in the namespace 'Microsoft.Owin.Security' (are you missing an assembly reference?)
I have attached AccountController.cs, packages.config and references
Any help.
You can try with deleting Package folder from source directory (Location: .sln file), then try to resotre packages.
Steps to restore nuget packages:
Right click on solution file.
Select Nuget restore NuGet Package option
I found the solution from Microsoft site
https://learn.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2012/0e92xd7b(v=vs.110)
Possible causes for this error include the following:
An assembly that contains the definition of a type was not referenced in the compilation; use /reference (Import Metadata) to specify the assembly
You passed a variable name to the typeof operator.
You tried to reference an assembly that is not part of your target .NET Framework profile. For more information, see Troubleshooting .NET Framework Targeting Errors.
In my case, the issue is that an assembly that is not part of my target .NET Framework profile.
My ASP.NET 5 Web api project fails to build when adding a reference to System.Web
Steps to reproduce problem:
Create a new ASP.NET Project
Select the ASP.NET 5 Web API template
Right click references and add System.Web
Add using System.Web; to some class
Exact error code:
CS0234 The type or namespace name 'Web' does not exist in the namespace 'System' (are you missing an assembly reference?) Stackoverflow.DNX Core 5.0 D:\Git\Stackoverflow\src\Stackoverflow\Startup.cs 10 Active
What I tried to do next is add:
"dnxcore50": {
"frameworkAssemblies": {
"System.Web": "4.0.0.0"
}
}
To the project.json file under the "Frameworks" tag after restoring packages this resulted in an unresolved dependency issue.
The solution DNX SDK version is: 1.0.0-rc1-update1 (which is the only option listed in my Visual Studio)
After a quick google search for any workaround left me empty handed.
Asp.Net 5 is no longer based on System.Web and there is not .net core compatible implementation of it. But there are many nuget packages so probably you will find the expected feature.
For example:
Instead of System.Web.Mvc, you need to add Microsoft.AspNet.Mvc nuget package to your project and you will be able to use the controller base class.
I have spent literally a 1 1/2 days Googling for a solution to this issue to no avail.
I am unable to reference a compiled SQLCLR assembly from code, in another project. I can add the reference to the other project, but when I try to add a "using" directive to include the referenced component in code, I receive a "The type or namespace name 'Database1' could not be found (are you missing a using directive or an assembly reference?)"
Here's what I've done:
Using VS 2012/2013 I have created a blank solution.
Added a new SQL Server Database project (Database1) targeting SQL Server 2012, and the .Net 4.5 Framework (NOT the Client Profile).
Added a new command line/winform/web app/whatever project (TestConsoleApplication1) to the solution, that ALSO targets the .Net 4.5 Framework (NOT the Client Profile).
Added references to the Database1 assembly (have tried project reference as well), and the System.Data assembly to the TestConsoleApplication1 project.
Added using directive for the System.Data assembly to the default class which was automatically added when I created the TestConsoleApplication1 project.
Attempted to add a using directive for the Database1 assembly to the default class which was automatically added when I created the TestConsoleApplication1 project.
When attempting to add the using directive for the Database1 assembly, the assembly name did not appear in intellisense, and typing in the assembly name resulted in the "red squiggle" under Database1.
Attempted to build the project, results in the "The type or namespace name 'Database1' could not be found (are you missing a using directive or an assembly reference?)" Error.
Checked, double, triple, quadruple...n-tuple-checked that both projects target the same .Net Framework version (4.5).
Database1 has no code, and here is the code for the "client" app (TestConsoleApplication1):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Database1; //Marked as design-time error, and throws ERROR on build
namespace TestConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
}
}
}
Does anybody have any idea why I can add a reference to the SQLCLR assembly, but the "client" project code appears unable to actually "see" nor access the referenced assembly?
Your .net console project can not reference the .Net assembly that is within the SQLCLR project as it will be embedded in the database when you publish it. It does combile to a DLL but would be dependant on the Microsoft Sql Server libs and would normally run under the same connection context vs a defined connection string to talk back to the database. Both projects could reference a third, shared assembly, then add SQLCLR .net code directly in the database project that simply calls the shared code as a wrapper.
The type or namespace name 'DataServiceKeyAttribute' does not exist in
the namespace 'System.Data.Services.Common' (are you missing an
assembly reference?)
This is the error that I have been getting and its driving me crazy. I am trying to build a web portal and I am following this tutorial.
Now after extensive search I am done and out. My target Framework is .Net Framework4 and there are some assemblies, specially the one from CRM sdk with version 5.0.
Could this be an issue?
This Type is defined in the .NET Framework Assembly Microsoft.Data.Services.Client. Ensure that this assembly is referenced by your project and it should work fine.
I am trying to write a simple Gui to produce a random password.
The code I am trying to use is:
using System.Web.Security;
Password_txtBx.Text = Membership.GeneratePassword(12, 1);
I am getting the error: "The name 'Membership' does not exist in the current context"
I have changed the code to this:
Password_txtBx.Text = System.Web.Security.Membership.GeneratePassword(12, 1);
The error message I get then is: "The type or namespace 'SecurityMembership' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)"
I have referenced System.Web.Security in both examples above. Is there any way to fix my problem?
Add a reference to System.Web (References -> RightClick -> AddReference -> .NET - > System.Web)
Now add a using (or Imports if using VB) for System.Web.Security
You may need to change Profile to .Net (instead of .Net Client Profile)
Are you sure that is the exact code/error message?
The error message you posted:
"The type or namespace 'SecurityMembership' does not exist in the namespace 'System.Web' (are you missing an assembly reference?"
implies you are trying to access SecurityMembership class. There is no such thing. You should add a dot after Security. Also, the class is defined in System.Web.dll, not System.Web.Security.dll. Note that System.Web assembly is not available in .NET Framework Client Profile. To be able to use that, you need to target full .NET Framework. You can change the target profile of the project in Project Properties.
There are other ways to generate random passwords that do not require you to add a dependency on System.Web.dll assembly (since you are doing this in a Windows Forms environment). Additionally, you can use System.Security.Cryptography classes to generate cryptographically secure random numbers.
Add using System.Web.Security; namespace in .cs file.