Microsoft.Azure.ActiveDirectory.GraphClient requires incorrect version of dependencies - nuget

In Asp.Net Core solution targeted to 4.6.1 full Framework I am using 2.1.1 Microsoft.Azure.ActiveDirectory.GraphClient.dll
In MSTest tests library TestMethods I am getting exception:
System.IO.FileLoadException: Could not load file or assembly
'Microsoft.Data.Services.Client, Version=5.6.3.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)
The wild thing that nuspec requires version 5.6.4, but DLL actually references 5.6.3.
Extract from dotPeek:
// Assembly Microsoft.Azure.ActiveDirectory.GraphClient, Version=2.1.10.0, Culture=neutral, PublicKeyToken=null
// Assembly references:
// Microsoft.Data.Services.Client, Version=5.6.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
// Microsoft.Data.Edm, Version=5.6.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
// Microsoft.Data.OData, Version=5.6.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
.nuget\packages\Microsoft.Azure.ActiveDirectory.GraphClient\2.1.1\Microsoft.Azure.ActiveDirectory.GraphClient.nuspec
<dependencies>
<dependency id="Microsoft.Data.Services.Client" version="5.6.4" />
<dependency id="Microsoft.Data.Edm" version="5.6.4" />
<dependency id="Microsoft.Data.OData" version="5.6.4" />
<dependency id="System.Spatial" version="5.6.4" />
</dependencies>
I've tried to install Microsoft.Data.Services.Client 5.6.3, but NuGet reported that Microsoft.Data.Odata requires 5.6.4
I've tried to install Microsoft.Data.Odata 5.6.3, but NuGet reported that Microsoft.Azure.ActiveDirectory.GraphClient require 5.6.4
I tried to use assemblyBinding, but it doesn't work for me (I've tried suggestions from assemblybinding does not work in mstest)
Any suggestions how to make Microsoft.Data.Services.Client loaded?
Can I somehow overwrite nuspec dependencies?
Update: I've created isolated library with single TestMethod, that has the problem.
The FIX:
The problem was that in app.config in assemblyBinding/ bindingRedirect I've used File Version instead of Assembly Version, which is different for this assembly
(File Version=5.6.4.62175, but Assembly Version=5.6.4.0). Correct configuration is
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.Data.Services.Client" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.6.4.0" newVersion="5.6.4.0" />
</dependentAssembly>
</assemblyBinding>

I am testing using Visual Studio 2017, and install the package Microsoft.Azure.ActiveDirectory.GraphClient with version 2.1.1. I also check the dependency version of Microsoft.Data.Services.Client is version 5.6.3 as you mentioned.
However, I also checked the version of Microsoft.Data.Services.Client.dll in the bin folder is 5.6.4.0 and it works well for me. Please use this version to see whether it is helpful.
And here is the part of deps.json file for your reference:
{
"runtimeTarget": {
"name": ".NETFramework,Version=v4.6.1/win7-x86",
"signature": "d7dc1119a66d1c2bf3e9f2c55e2b0432742f00d1"
},
"compilationOptions": {
"defines": [
"TRACE",
"DEBUG",
"NET461"
],
"languageVersion": "",
"platform": "x86",
"allowUnsafe": false,
"warningsAsErrors": false,
"optimize": false,
"keyFile": "",
"emitEntryPoint": true,
"xmlDoc": false,
"debugType": "portable"
},
"targets": {
".NETFramework,Version=v4.6.1": {
"consoleapp1/1.0.0": {
"dependencies": {
"Microsoft.AspNetCore.Server.Kestrel": "1.0.3",
"Microsoft.Azure.ActiveDirectory.GraphClient": "2.1.1"
},
"compile": {
"ConsoleApp1.exe": {}
}
},
...
"microsoft.azure.activedirectory.graphclient/2.1.1": {
"dependencies": {
"Microsoft.Data.Edm": "5.6.4",
"Microsoft.Data.OData": "5.6.4",
"Microsoft.Data.Services.Client": "5.6.4",
"System.Spatial": "5.6.4"
},
"compile": {
"lib/portable-net4+sl5+win+wpa+wp8/Microsoft.Azure.ActiveDirectory.GraphClient.dll": {}
}
},
"microsoft.data.edm/5.6.4": {
"compile": {
"lib/net40/Microsoft.Data.Edm.dll": {}
}
},
"microsoft.data.odata/5.6.4": {
"dependencies": {
"Microsoft.Data.Edm": "5.6.4",
"System.Spatial": "5.6.4"
},
"compile": {
"lib/net40/Microsoft.Data.OData.dll": {}
}
},
"microsoft.data.services.client/5.6.4": {
"dependencies": {
"Microsoft.Data.OData": "5.6.4"
},
"compile": {
"lib/net40/Microsoft.Data.Services.Client.dll": {}
}
},
...
}
}
}
Update
For the redirecting assembly in a unit test project, add the config like steps below:
1 .add a config file testAssemblyName.dll.config(eg. my project's name is ConsoleApp1.Test then the config file should be ConsoleApp1.Test.dll.config) with content below:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.Data.Services.Client" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.6.4.0" newVersion="5.6.4.0" />
</dependentAssembly>
</assemblyBinding>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.Data.OData" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.6.4.0" newVersion="5.6.4.0" />
</dependentAssembly>
</assemblyBinding>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.Data.Edm" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.6.4.0" newVersion="5.6.4.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
change the property Copy to Output Directory with the value Copy if newer to make sure that the config is copy to the bin/debug folder.
After that the tests run successfully.

Related

.NetCore code with sustainsys-saml2 does nothing

I have an .Net MVC project with SSO working. The SSO config looks like this:
<system.identityModel>
<identityConfiguration saveBootstrapContext="true">
<caches>
<sessionSecurityTokenCache type="Vixion.IdentityModel.Cache.SharedSessionSecurityTokenCache, Vixion.IdentityModel.Cache">
<cacheServiceAddress url="http://tvwapps35434d.kpnis.nl:1008/SessionSecurityTokenCacheService.svc" />
</sessionSecurityTokenCache>
</caches>
<audienceUris>
<add value="http://localhost:24442/" />
</audienceUris>
<securityTokenHandlers>
<remove type="System.IdentityModel.Services.Tokens.MachineKeySessionSecurityTokenHandler, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<add type="System.IdentityModel.Tokens.SessionSecurityTokenHandler, System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<add type="System.IdentityModel.Tokens.Saml2SecurityTokenHandler, System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</securityTokenHandlers>
<certificateValidation certificateValidationMode="None" />
<issuerNameRegistry type="System.IdentityModel.Tokens.ValidatingIssuerNameRegistry, System.IdentityModel.Tokens.ValidatingIssuerNameRegistry">
<authority name="http://vix-make-o:8080">
<keys>
<add thumbprint="5137c779a1e77a0f4a78abd356b0238912637469" />
</keys>
<validIssuers>
<add name="http://vix-make-o:8080" />
</validIssuers>
</authority>
</issuerNameRegistry>
</identityConfiguration>
</system.identityModel>
<system.identityModel.services>
<federationConfiguration>
<cookieHandler requireSsl="false" path="/" />
<wsFederation passiveRedirectEnabled="true" issuer="http://vix-make-o:8080" realm="http://localhost:24442/" requireHttps="false" reply="http://localhost:24442/" />
</federationConfiguration>
</system.identityModel.services>
According to the example here:
https://github.com/Sustainsys/Saml2/tree/master/Sustainsys.Saml2.AspNetCore2
I write this code in a new .NetCore app:
services.AddIdentity<IdentityUser, IdentityRole>()
.AddDefaultTokenProviders();
services.AddDistributedMemoryCache();
services.AddSession(options =>
{
options.Cookie.HttpOnly = true;
});
services.AddMvc()
.AddJsonOptions(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver());
services.AddAuthentication()
.AddSaml2(options =>
{
options.SPOptions.EntityId = new EntityId("http://vix-make-o:8080");
options.IdentityProviders.Add(
new IdentityProvider(
new EntityId("http://vix-make-o:8080/ws_saml_metadata"), options.SPOptions)
{
//LoadMetadata = true
});
});
app.UseAuthentication();
app.UseSession();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
When I start the app, the browser goes straight to the index page. No error, no nothing. When I check with SAML Chrome Panel it shows no traffic at all.
I do not expect my code working, but it should at least do something to give me a hint to how to go further.
Any suggestions are welcome.
Thank you.
S.
Remove the web.config content. It is not used with the ASP.NET Core module.
Set back the LoadMetadata flag, or add the necessary config manually.
Set Saml2 as the default challenge protocol for authentication.
Finally, add an [Authorize] attribute to your controllers that should require authentication to initiate the authentication process.

UWP and FullTrustProcessLauncher missing in namaspeace

I am trying to launch powershell (some lightweight commands that all user can do) command from UWP application using FullTrustProcessLauncher.
Problem is I am getting that this name does not exists in current context.
My manifest is largly default so it looks like :
<?xml version="1.0" encoding="utf-8"?>
<Package
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
xmlns:desktop="http://schemas.microsoft.com/appx/manifest/desktop/windows10"
IgnorableNamespaces="uap mp">
<Dependencies>
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.0.0" MaxVersionTested="10.0.0.0" />
</Dependencies>
<Resources>
<Resource Language="x-generate"/>
</Resources>
<Applications>
<Application Id="App" Executable="$targetnametoken$.exe" EntryPoint="PrototypeProject.App">
<Extensions>
<desktop:Extension Category="windows.fullTrustProcess" Executable="powershell.exe">
<desktop:FullTrustProcess>
<desktop:ParameterGroup GroupId="TestGroup" Parameters="ls"/>
</desktop:FullTrustProcess>
</desktop:Extension>
</Extensions>
</Application>
</Applications>
<Capabilities>
<Capability Name="internetClient" />
<rescap:Capability Name="runFullTrust"/>
</Capabilities>
</Package>
And class I am trying to call it from looks like:
using Windows.ApplicationModel;
using Windows.Foundation;
namespace FullTrustProcess
{
public class Ftp
{
public const string FtpParamGroupId = "TestGroup";
public void RunFtp()
{
IAsyncAction operation = FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync(FtpParamGroupId);
}
}
}
Now am I missing something??
It looks like I was missing - Windows Desktop Extensions for the UWP, in extensions reference

Web.config custom section not being recognized

I am trying to develop an application that uses the package SAML2.dll (which I downloaded with NuGet). To properly configure my application, we must add a few sections in the Web.config file:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
**<section name="saml2" type="SAML2.Config.Saml2Section, SAML2" />**
</configSections>
<connectionStrings>...</connectionStrings>
<appSettings>...</appSettings>
<system.web>...</system.web>
<system.webServer>
<modules>
<remove name="FormsAuthentication" />
</modules>
**<handlers>
<remove name="SAML2.Protocol.Saml20SignonHandler" />
<remove name="SAML2.Protocol.Saml20LogoutHandler" />
<remove name="SAML2.Protocol.Saml20MetadataHandler" />
<add name="SAML2.Protocol.Saml20SignonHandler" verb="*" path="Login.ashx" type="SAML2.Protocol.Saml20SignonHandler, SAML2" />
<add name="SAML2.Protocol.Saml20LogoutHandler" verb="*" path="Logout.ashx" type="SAML2.Protocol.Saml20LogoutHandler, SAML2" />
<add name="SAML2.Protocol.Saml20MetadataHandler" verb="*" path="Metadata.ashx" type="SAML2.Protocol.Saml20MetadataHandler, SAML2" />
</handlers>**
</system.webServer>
<runtime>...</runtime>
<entityFramework>...</entityFramework>
**<saml2>
<serviceProvider id="urn:issuer" server="http://localhost:3301/">
<endpoints>
<endpoint localpath="Login.ashx" type="signon" redirectUrl="~/AuthenticatedHomePage" />
<endpoint localpath="Logout.ashx" type="logout" redirectUrl="~/HomePage" />
<endpoint localpath="Metadata.ashx" type="metadata" />
</endpoints>
<nameIdFormats allowCreate="true">
<add format="urn:oasis:names:tc:SAML:2.0:nameid-format:transient" />
</nameIdFormats>
<authenticationContexts comparison="Exact">
<add context="urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport" referenceType="AuthnContextClassRef" />
</authenticationContexts>
</serviceProvider>
<identityProviders metadata="C:\Users\myUser\Desktop\testMetadata\metadata_Kit_net.xml" />
<metadata>
<contacts>
<contact type="Administrative" company="" givenName="" surName="" email="" phone="" />
</contacts>
<requestedAttributes>
<add name="urn:cn" />
</requestedAttributes>
</metadata>
</saml2>**
</configuration>
The issue is that the session tag has no recognized tags, I'm having 39 messages like (one for each element inside the tag):
impossible to find schema information for the element 'saml2'.
impossible to find schema information for the element 'serviceProvider'.
impossible to find schema information for the element 'id'.
...
I looked into my dll's source code (SAML2.dll) and it seams to have all the tags definitions (as written in the first Web.config part: ):
using System.Configuration;
namespace SAML2.Config
{
/// <summary>
/// SAML2 Configuration Section.
/// </summary>
public class Saml2Section : ConfigurationSection
{
/// <summary>
/// Gets the section name.
/// </summary>
public static string Name { get { return "saml2"; } }
#region Elements
/// <summary>
/// Gets or sets the actions to perform on successful processing.
/// </summary>
/// <value>The actions.</value>
[ConfigurationProperty("actions")]
public ActionCollection Actions
{
get { return (ActionCollection)base["actions"]; }
set { base["actions"] = value; }
}
/// <summary>
/// Gets or sets the identity providers.
/// </summary>
/// <value>The identity providers.</value>
[ConfigurationProperty("identityProviders")]
public IdentityProviderCollection IdentityProviders
{
get { return (IdentityProviderCollection)base["identityProviders"]; }
set { base["identityProviders"] = value; }
}
/// <summary>
/// Gets or sets the metadata.
/// </summary>
/// <value>The metadata.</value>
[ConfigurationProperty("metadata")]
public MetadataElement Metadata
{
get { return (MetadataElement)base["metadata"]; }
set { base["metadata"] = value; }
}
/// <summary>
/// Gets or sets the service provider.
/// </summary>
/// <value>The service provider.</value>
[ConfigurationProperty("serviceProvider")]
public ServiceProviderElement ServiceProvider
{
get { return (ServiceProviderElement)base["serviceProvider"]; }
set { base["serviceProvider"] = value; }
}
...
When I call the URL http://localhost:3301/Login.ashx, I'm having the error:
{"Attribute 'localpath' not recognized. (c:\users\myUser\documents\visual studio 2013\Projects\saml20app\saml20app\web.config line 98)"}, and it points exactly to the line
<endpoint localpath="Login.ashx" type="signon" redirectUrl="~/AuthenticatedHomePage" />
Can someone please help me with this error?
Thanks in advance for your help,
Marc
Got tried of trying to get this to work so I opened the assembly with ILSpy to see what it wanted:
<endpoint localPath="Login.ashx" type="SignOn" redirectUrl="~/AuthenticatedHomePage" />
<endpoint localPath="Logout.ashx" type="Logout" redirectUrl="~/HomePage" />
<endpoint localPath="Metadata.ashx" type="Metadata" />
The type attribute in the example web.config makes it unhappy too. Thankfully it lets you know the enumerated values it expects.
Hope this help.

Enable Migrations Not working

I have an application which has three layers.I am using EntityFramework 6.1 and code first migrations using existing database.The three layers are given below:
1.Presententation Layer:ConceptuCodeFirstMigrationDemo
Simply a Console Application for simplicity
Data Layer Consists of Context and Initializer.The codes are given below:
namespace ConceptuCodeFirstMigrationDemo.Data.DataContext
{
using System;
using System.Data.Entity;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using ConceptuCodeFirstMigrationDemo.Domain;
public partial class ConceptuContext : DbContext,IDisposable
{
public ConceptuContext()
: base("name=ConceptuContext")
{
}
public virtual DbSet<User> Users { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<User>()
.WithRequired(e => e.User)
.HasForeignKey(e => e.CreatedBy)
.WillCascadeOnDelete(false);
}
}
}
ConceptuInitializer.Cs
namespace ConceptuCodeFirstMigrationDemo.Data.DataContext
{
public class ConceptuInitializer: System.Data.Entity.CreateDatabaseIfNotExists<ConceptuContext>
{
}
}
Appconfig:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<entityFramework>
<contexts>
<context type="ConceptuCodeFirstMigrationDemo.Data.DataContext.ConceptuContext, ConceptuCodeFirstMigrationDemo.Data">
<databaseInitializer type="ConceptuCodeFirstMigrationDemo.Data.DataContext.ConceptuInitializer, ConceptuCodeFirstMigrationDemo.Data" />
</context>
</contexts>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
<connectionStrings>
<add name="ConceptuContext" connectionString="data source=AMITABHA-PC;initial catalog=Conceptu;user id=sa;password=lovediya;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
Domain Layer: Consists of entity class for example user
After writing a new class when I try to enable migrations using Enable-Migrations
showing
No context type was found in the assembly 'ConceptuCodeFirstMigrationDemo'.
After I tried the following command:
Enable-Migrations -ContextTypeName ConceptuCodeFirstMigrationDemo.Data.DataContext.ConceptuContext
this shows following error
The context type 'ConceptuCodeFirstMigrationDemo.Data.DataContext.ConceptuContext' was not found in the assembly 'ConceptuCodeFirstMigrationDemo'.
After I tried the following command
Enable-Migrations ConceptuCodeFirstMigrationDemo.Data.DataContext.ConceptuContext
It shows the following error
Enable-Migrations : A positional parameter cannot be found that accepts argument 'ConceptuCodeFirstMigrationDemo.Data.DataContext.Concept
uContext'.
At line:1 char:18
+ Enable-Migrations <<<< ConceptuCodeFirstMigrationDemo.Data.DataContext.ConceptuContext
+ CategoryInfo : InvalidArgument: (:) [Enable-Migrations], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Enable-Migrations
Try this.
Enable-Migrations -ContextTypeName ConceptuCodeFirstMigrationDemo.Data.DataContext.ConceptuContext -ProjectName ConceptuCodeFirstMigrationDemo

ASP.NET Routing in rest service not working in IIS

I created a simple rest service with routing enabled. The routing is properly working when i run it locally i.e using asp.net development server. But when I deploy the application in IIS (IIS 7.5) then it and try to access the method in the service i get the error HTTP 404.0 Not found. Here is my code :
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
public class HelloWorldService
{
[WebGet(UriTemplate = "Date")]
public DateTime Date()
{
return System.DateTime.Now;
}
}
Global.asax:
protected void Application_Start(object sender, EventArgs e)
{
RegisterRoutes();
}
private void RegisterRoutes()
{
RouteTable.Routes.Add(new ServiceRoute("ServiceData", new WebServiceHostFactory(), typeof(HelloWorldService)));
}
Web.config:
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</modules>
</system.webServer>
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<standardEndpoints>
<webHttpEndpoint>
<standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true"/>
</webHttpEndpoint>
</standardEndpoints>
</system.serviceModel>
</configuration>
I also Enabled HTTP Redirection Feature under
Windows Features -> Internet Information Services -> Word Wide Web services -> Common HTTP Features
I also tried Adding handlers like
<handlers>
<add name="UrlRoutingHandler" preCondition="integratedMode" verb="*" path="UrlRouting.axd" type="System.Web.HttpForbiddenHandler, System.Web,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
</handlers>
Also i have tried all the other solutions that were suggested on the web but nothing works. Thanks in advance for any help.
Something is wrong with your RegisterRoutes(). It should be:
private void RegisterRoutes()
{
// Edit the base address of Service1 by replacing the "Service1" string below
RouteTable.Routes.Add(new ServiceRoute("HelloWorldService", new WebServiceHostFactory(), typeof(HelloWorldService)));
}