Can't Add System.IdentityModel package/reference - c#

Long story short I want to create authentication for my WCF service.
Target framework: .NET 4.5.
I'm following this User Name Password Validator.
I'm trying to inherit from UserNamePasswordValidator class but VS2013 keep giving me this error :
My code:
public class UserNamePassValidator : System.IdentityModel.UserNamePasswordValidator
{
}
The error i'm getting:
Error 1 The type or namespace name 'IdentityModel' does not exist in the namespace 'System' (are you missing an assembly reference?)
I've tried a couple of diffrent ways to solve this: (none of them help me)
I've installed Windows Identity Foundation and the WIF SDK.
I've add dll manually with this path: C:\Program Files\Reference Assemblies\Microsoft\Windows Identity Foundation\v3.5\ Microsoft.IdentityModel.dll
I try to search for that package in the Nuget Package Manager but nothing come up, only System.IdentityModel.Token (I reference it too but it didn't help).
What am i missing here ? its probably something obvious that I don't see...

If the Target Framework is 4.5, then there is no package to download in order to use WIF. System.IdentityModel is fully integrated to Framework 4.5 and it is the type used by WIF when targeting Framework 4.5 and higher.
Also, you should inherit from this type: System.IdentityModel.Selectors.UserNamePasswordValidator:
public class UserNamePassValidator : System.IdentityModel.Selectors.UserNamePasswordValidator
{
public override void Validate(string userName, string password)
{
return;
}
}​
You can refer to the links below:
1- UserNamePasswordValidator
2- What do I need to build a claims-aware wcf service in VS 2013

Related

IResult (from Asp) not found in standard 2.0 project

I created a DLL project targeting .net standard 2.0.
With NuGet I added a reference to Microfosft.AspNetCore.Http. (2.2.2)
I created this class:
using System;
using Microsoft.AspNetCore.Http;
namespace netstdlib
{
public class Class1
{
public IResult DoGet()
{
return null;
}
}
}
When I build I get
Build started...
1>------ Build started: Project: netstdlib, Configuration: Debug Any CPU ------
1>D:\PROJECTS\experiment\CS framework test\netstdlib\Class1.cs(10,25,10,32): error CS0246:
The type or namespace name 'IResult' could not be found (are you missing a using
directive or an assembly reference?)
1>Done building project "netstdlib.csproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 2 up-to-date, 0 skipped ==========
It seems to me it should find IResult in the library I'm using. What's wrong?
The IResult interface in the Microsoft.AspNetCore.Http namespace was added in ASP.NET Core 6, so you need to update if you want to use it.
See documentation: IResult Interface.
Thanks to Camilo for pointing out why IResult can't work. I did find a way that will work:
HttpResponseMessage as produced by HttpClient.GetAsync is usable in .net core. Whether or not these classes are usable in .net framework I didn't try, but I can use HttpResponseMessage to extract data in a Standard dll, and return that data to a .net framework project.

After upgrading to .net6 from .net4.8 FederatedAuthentication.FederationConfiguration does not exists

I just upgraded my .net4.8 web app to .net6 using upgrade assistant among the other errors I get, in my SignIn function I cannot use the following:
WsFederationConfiguration config = FederatedAuthentication.FederationConfiguration.WsFederationConfiguration;
I get the error:
'FederatedAuthentication' does not contain a definition for 'FederationConfiguration'
It seems like FederationConfiguration is no longer supported in .net6. What is the best alternative?

Error on SSIS Script Task to load data from MongoDB to SQL Server: Could not load file or assembly MongoDB.Driver.Core

I want to create a Script Task to load data from MongoDB to SQL Server.
I am using Visual Studio 2017 and target SQL Server version is 2017.
The default target .NET Version of the script task based on the above is 4.5, therefore I got the 2.3 version, which was the latest to target 4.5
In order to get the dlls, I first used NuGet to download the packages and then copied the following dlls:
MongoDB.Driver.dll
MongoDB.Driver.Core.dll
MongoDB.Bson.dll
I followed instructions from here:
http://codeingaddiction.blogspot.com/2011/06/how-to-add-strong-name-to-existing-dll_16.html
In order to produce strong named dlls.
Finally, I added the dlls on GAC on the following path
C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools
I then created a script task and manually added the 3 dlls.
My test code is the following:
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Pipeline.Wrapper;
using Microsoft.SqlServer.Dts.Runtime.Wrapper;
using MongoDB.Bson;
using MongoDB.Driver;
using MongoDB.Driver.Core;
using MongoDB.Bson.Serialization;
[Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute]
public class ScriptMain : UserComponent
{
public override void PreExecute()
{
base.PreExecute();
}
public override void PostExecute()
{
base.PostExecute();
}
public override void CreateNewOutputRows()
{
MongoClient client = new MongoClient("mongodb://dgm-mongodbdev-01.development.dc.opap:27017");
IMongoDatabase database = client.GetDatabase("sportsbetting-staging");
IMongoCollection<BsonDocument> collection = database.GetCollection<BsonDocument>("event");
collection.Find<BsonDocument>(null).Limit(3);
Console.WriteLine(collection);
}
}
Trying to build gives the following error:
Severity Code Description Project File Line Suppression State
Error The type 'IAsyncCursorSource<>' is defined in an assembly that is not referenced. You must add a reference to assembly 'MongoDB.Driver.Core, Version=2.3.0.157, Culture=neutral, PublicKeyToken=null'.
MongoDb Core Driver does not have any additional dependencies that I may have missed. For 4.5 version of .NET the only dependency is MongoDB.Bson which is added as a reference.
The only article I have found for SSIS script task is this:
https://arcanecode.com/2014/01/14/importing-mongodb-data-using-ssis-2012/
Which is obsolete because it used the version 1.x of the driver.
Any ideas? The message seems misleading because it seems clear that I am not missing any dependency.
Finally, my answer was provided on the following post:
How to fix "Referenced assembly does not have a strong name" error?
Apparently,
MongoDB.Driver.Core.dll
MongoDB.Driver.dll
Have reference to
MongoDB.Bson.dll
Therefore, the public key token had to be added on the il files before re-assembling

Consume the OData service in C# doesn't work

I tried to understand this tutorial: http://odata.github.io/odata.net/#OData-Client-Code-Generation-Tool
I can generate the proxy without any problems. Just as it is described.
But at chapter "Consume the OData service" it doesn't work. I have named the application and the proxy exactly as shown in the tutorial. How can I make odata available in namespace Microsoft?
Screenshot
Error CS0234 The type or namespace name 'OData' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?) TrippinApp C:\TrippinApp\Program.cs 6 Active
Error CS0246 The type or namespace name 'DefaultContainer' could not be found (are you missing a using directive or an assembly reference?) TrippinApp C:\TrippinApp\Program.cs 16 Active
Error CS0246 The type or namespace name 'DefaultContainer' could not be found (are you missing a using directive or an assembly reference?) TrippinApp C:\TrippinApp\Program.cs 16 Active
I used:
Microsoft Visual Studio 2017 (Trial)
Microsoft.Data.Edm v5.8.3
Microsoft.Data.Odata v5.8.3
Microsoft.Data.Services.Client v5.8.3
System.Spatial v.5.8.3
WCF Data Services 5.6 Tools (are installed)
continuation:
#Evandro Paula:Thank you for your help! I have come a little further thanks to your help. But unfortunately I have not come to the goal yet.
I installed/updated:
Microsoft Visual Studio 2017 (15.7.1) (Trial)
Microsoft.Data.Edm v5.8.3 (I have not found a more recent one)
Microsoft.Data.Odata v5.8.3 (I have not found a more recent one)
Microsoft.Data.Services.Client v5.8.3 (I have not found a more recent one)
Microsoft.OData.Client v7.4.4 (installed)
Microsoft.OData.Core v7.4.4 (installed)
Microsoft.OData.Edm v7.4.4 (installed)
Microsoft.Spatial v7.4.4 (installed)
System.Spatial v.5.8.3 (I have not found a more recent one)
WCF Data Services 5.6 Tools (are installed)
Screenshot of NuGet
Now the results look like this:
Compiling works with Proxy (TrippinProxy.cs), but without Odata example. (Screenshot)
As soon as I copy the code from the tutorial, compiling does't work anymore. (Screenshot)
using System;
using Microsoft.OData.SampleService.Models.TripPin;
namespace TrippinApp
{
class Program
{
static void Main(string[] args)
{
DefaultContainer dsc = new DefaultContainer(
new Uri("http://services.odata.org/V4/(S(fgov00tcpdbmkztpexfg24id))/TrippinServiceRW/"));
var me = dsc.Me.GetValue();
Console.WriteLine(me.UserName);
}
}
}
source: http://odata.github.io/odata.net/#OData-Client-Code-Generation-Tool
Now the Namespace Microsoft.OData is found. But not Microsoft.OData.SampleService (Screenshot)
I need a little example. How can I initialize the proxy and add a product (CreateProduct)? Or how can I get the example from the tutorial up and running?
First, update the packages you mentioned on your question to their latest version. It looks like Visual Studio didn't use the latest version in your case. I'm using Visual Studio 2017 Enterprise Edition (version 15.7.3) for this test.
Microsoft.OData.Client (version 7.4.4)
Microsoft.OData.Core (version 7.4.4)
Microsoft.OData.Edm (version 7.4.4)
Microsoft.Spatial (version 7.4.4)
Once the packages are up to date, you will observe the following build error, which is related to issue https://github.com/OData/lab/issues/80:
Severity Code Description Project File Line Suppression State
Error CS0234 The type or namespace name 'EdmxReader' does not exist in the namespace 'Microsoft.OData.Edm.Csdl' (are you missing an assembly reference?) ODataClient C:\temp\NET\ODataClient\Connected Services\TrippingService\TrippingProxy.cs 510 Active
The resolution for this issue is available at https://github.com/juliopinto15/lab/commit/deb1254301a775eb6771b0bed672dd3f56f37cfe.
Just change the proxy (e.g. TrippingProxy.cs) generated code line below as part of method LoadModelFromString():
return global::Microsoft.OData.Edm.Csdl.EdmxReader.Parse(reader);
to
return global::Microsoft.OData.Edm.Csdl.CsdlReader.Parse(reader);
In my case, I deleted the NuGet cache folder, and it compiles now.
%LOCALAPPDATA%\Nuget\v3-cache
I worked with the same example (TripPinService) and got the same error. It looks like there is an error in the sample.
Instead of:
var context = new DefaultContainer(new Uri(serviceRoot));
You need to write:
var context = new Default.Container(new Uri(serviceRoot));
After that code runs without errors

RavenDB.Client.Embedded disappears after I try to build it

I'm following tutorial, installed RanvenDB embeeded and write:
public static IDocumentStore archives =
new EmbeddableDocumentStore { DataDirectory = "~/DataStore" };
then I let VS to find where is EmbeddableDocumentStore so and I add:
using Raven.Client.Embedded;
No errors yet and everything looks fine. Then I build:
Archives.cs(10,20): error CS0234: The type or namespace name
'Embedded' does not exist in the namespace 'Raven.Client' (are you
missing an assembly reference?)
Compile complete -- 1 errors, 0 warnings
And now it's error and there is no Embedded...
If I remove package.config and run install Ravendb Embedded again it will become green (with no errors) again but just after I run build...
How to repair it?
(tested different version : same result)
Make sure that you are building for the FULL .NET framework, and not just the client profile.

Categories

Resources