What is the appsetting.json version of <defaultProxy>? - web-config

What is the .Net Core appsettings.json version of
<defaultProxy useDefaultCredentials="true">
<proxy autoDetect="True"
proxyaddress="http://localhost:8888/"
usesystemdefault="False" bypassonlocal="False" />
</defaultProxy>
?

Using a tool at http://www.utilities-online.info/xmltojson
I got the following. I didn't test this.
{
"defaultProxy": {
"-useDefaultCredentials": "true",
"proxy": {
"-autoDetect": "True",
"-proxyaddress": "http://localhost:8888/",
"-usesystemdefault": "False",
"-bypassonlocal": "False"
}
}
}

Related

Where do I put an NLog config file if the NLog code is in a NuGet package?

I'm using Visual Studio 2022, .NET 6.0, C#. A co-worker has created a NuGet library that is a helper function for NLog. It creates the logger object and calls the Log method. What I can't figure out is where to put the NLog.config file. Where do you put the NLog file in a situation like this?
Here's how the reference to the library is set up in the Test App:
Here's how it's called in the Test App:
// Test App
logger.Log(LogLevel.Debug, message, args);
I've tried putting the NLog.config file in these places:
C:\Test\
C:\Test\Debug
C:\Test\Debug\net6.0
Here's my config file:
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
autoReload="true"
throwExceptions="false"
internalLogLevel="Off" internalLogFile="c:\temp\nlog-internal.log">
<!-- optional, add some variables
https://github.com/nlog/NLog/wiki/Configuration-file#variables
-->
<variable name="myvar" value="myvalue"/>
<!--
See https://github.com/nlog/nlog/wiki/Configuration-file
for information on customizing logging rules and outputs.
-->
<targets>
<target xsi:type="File" name="f" fileName="${basedir}/logs/${shortdate}.log" layout="${longdate} ${uppercase:${level}} ${message}" />
</targets>
<rules>
<!-- Write all events with minimal level of Debug (So Debug, Info, Warn, Error and Fatal, but not Trace) to "f" -->
<logger name="*" minlevel="Debug" writeTo="f" />
</rules>
</nlog>
I've also tried adding it to appsettings.json.
Here's my appsettings.json code:
{
"ConnectionStrings": {
"TheSQLConnectionString": ""
},
"NLog": {
"targets": {
"console": {
"type": "File",
"name": "f",
"fileName": "nlogtest.log"
}
},
"rules": [
{
"logger": "*",
"minLevel": "Trace",
"writeTo": "f"
}
]
}
}
Here's how the NuGet Library is set up:
// NuGet Library
public class NLogHelper : Microsoft.Extensions.Logging.ILogger
{
...
public void Log<TState>(
LogLevel logLevel,
EventId eventId,
TState state,
Exception exception,
Func<TState, Exception, string> formatter)
{
if (!IsEnabled(logLevel))
{
return;
}
var nlog = LogManager.GetCurrentClassLogger();
switch (logLevel)
{
case LogLevel.Trace:
nlog.Log(NLog.LogLevel.Trace, exception, $"{formatter(state, exception)}");
break;
case LogLevel.Debug:
nlog.Log(NLog.LogLevel.Debug, exception, $"{formatter(state, exception)}");
break;
case LogLevel.Information:
nlog.Log(NLog.LogLevel.Info, exception, $"{formatter(state, exception)}");
break;
case LogLevel.Warning:
nlog.Log(NLog.LogLevel.Warn, exception, $"{formatter(state, exception)}");
break;
case LogLevel.Error:
nlog.Log(NLog.LogLevel.Error, exception, $"{formatter(state, exception)}");
break;
case LogLevel.Critical:
nlog.Log(NLog.LogLevel.Fatal, exception, $"{formatter(state, exception)}");
break;
}
...
}
Think the NLogHelper from your custom Nuget-Library should be replaced with NLogLoggerFactory from NLog.Extensions.Logging.
Then at program startup then you should register NLog as Logging-Provider using AddNLog:
using NLog.Extensions.Logging;
private static void Main()
{
var logger = LoggerFactory.Create(builder => builder.AddNLog()).CreateLogger("Hello");
logger.LogInformation("Program has started.");
Console.ReadKey();
}
If having registered NLog as LoggingProvider using AddNLog with the Microsoft HostBuilder, then NLog will automatically load its configuration from appsettings.json (Retrieved from HostBuilder-Configuration). See also: https://github.com/NLog/NLog.Extensions.Logging/wiki/NLog-configuration-with-appsettings.json (Ex. can also load appsettings.json manually with ConfigurationBuilder)
NLog will automatically load its configuration from NLog.config, if you add the xml-file to your host-application-project, with file-properties Copy If newer. See also: https://github.com/NLog/NLog/wiki/Tutorial
Instead of having NLog-configuration in external files, then you can also configure NLog from code:
NLog.LogManager.Setup().LoadConfiguration(builder => {
builder.ForLogger().WriteToConsole()
});

.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.

CAS Delegated Authentication and AttributeReleasePolicies

We were able to integrate CAS 5.2.6 using delegated authentication with Azure AD (Saml Idp)
The integrated is working fine when the client webapp is deployed on Tomcat-9
The same client WAR fails in JBoss-EAP or Wildfly because of SaxParing exception
This is because Jboss is using xercesImpl for parsing Xml which fails when the xml element is numeric.
So, a standard solution will be to use AttributeResolver configuration on CAS server side to ensure that we map the attribute to standard names (vs numeric names)
Attached herewith the SAML response and CAS Client Response
<samlp:Response
Destination="https://somedomain.cloudapp.azure.com:8443/cas/login?client_name=MY_SAML"
ID="_6a00b756-53f4-4702-b329-7a6af0145fa0" InResponseTo="_d5nkosrzkcj29rlldngsuozq3uwtb5znanfm616"
IssueInstant="2018-10-04T13:22:05.275Z" Version="2.0"
xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol">
<Issuer xmlns="urn:oasis:names:tc:SAML:2.0:assertion">https://sts.windows.net/522b3803-a001-4675-b3b5-1d727d43585a/</Issuer>
<samlp:Status><samlp:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Success"/></samlp:Status>
<Assertion ID="_337eded3-a927-4674-b78a-77259cfbf784" IssueInstant="2018-10-04T13:22:05.275Z"
Version="2.0" xmlns="urn:oasis:names:tc:SAML:2.0:assertion">
<Issuer>https://sts.windows.net/522b3803-a001-4675-b3b5-1d727d43585a/</Issuer>
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
<SignedInfo><CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/><SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/>
<Reference URI="#_337eded3-a927-4674-b78a-77259cfbf784">
<Transforms><Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/><Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/></Transforms><DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
<DigestValue>BkenglDOQwAFlKJ3hLrZ4vUzAg9gOD9EFUjGKH9hsI4=</DigestValue>
</Reference>
</SignedInfo>
<SignatureValue>...</SignatureValue>
<KeyInfo>
<X509Data>
<X509Certificate>...</X509Certificate>
</X509Data>
</KeyInfo>
</Signature>
<Subject>
<NameID Format="urn:oasis:names:tc:SAML:2.0:nameid-format:persistent">nX16LJA-9igFhluTHQGlDUOK0CNPy_XfliMDJ3iud88</NameID>
<SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer"><SubjectConfirmationData InResponseTo="_d5nkosrzkcj29rlldngsuozq3uwtb5znanfm616"
NotOnOrAfter="2018-10-04T13:27:05.275Z"
Recipient="https://somedomain.cloudapp.azure.com:8443/cas/login?client_name=MY_SAML"/></SubjectConfirmation>
</Subject>
<Conditions NotBefore="2018-10-04T13:17:05.275Z" NotOnOrAfter="2018-10-04T14:17:05.275Z">
<AudienceRestriction>
<Audience>spn:8b4fcc4d-6781-4da0-acc9-0c28a3317695</Audience>
</AudienceRestriction>
</Conditions>
<AttributeStatement>
<Attribute Name="http://schemas.microsoft.com/identity/claims/tenantid">
<AttributeValue>522b3803-a001-4675-b3b5-1d727d43585a</AttributeValue>
</Attribute>
<Attribute Name="http://schemas.microsoft.com/identity/claims/objectidentifier">
<AttributeValue>8fa1e8a3-41b8-440e-91cf-fafa246ab571</AttributeValue>
</Attribute>
<Attribute Name="http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name">
<AttributeValue>xxxxx#AAAA.onmicrosoft.com</AttributeValue>
</Attribute>
<Attribute Name="http://schemas.microsoft.com/identity/claims/displayname">
<AttributeValue>Firstname Lastname</AttributeValue>
</Attribute>
<Attribute Name="http://schemas.microsoft.com/identity/claims/identityprovider">
<AttributeValue>https://sts.windows.net/522b3803-a001-4675-b3b5-1d727d43585a/</AttributeValue>
</Attribute>
<Attribute Name="http://schemas.microsoft.com/claims/authnmethodsreferences">
<AttributeValue>http://schemas.microsoft.com/ws/2008/06/identity/authenticationmethod/password</AttributeValue>
<AttributeValue>http://schemas.microsoft.com/claims/multipleauthn</AttributeValue>
</Attribute>
</AttributeStatement>
<AuthnStatement AuthnInstant="2018-10-04T09:50:06.611Z"
SessionIndex="_337eded3-a927-4674-b78a-77259cfbf784">
<AuthnContext>
<AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:Password</AuthnContextClassRef>
</AuthnContext>
</AuthnStatement>
</Assertion>
CAS Client Response
<cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'>
<cas:authenticationSuccess>
<cas:user>nX16LJA-9igFhluTHQGlDUOK0CNPy_XfliMDJ3iud88</cas:user>
<cas:attributes>
<cas:isFromNewLogin>true</cas:isFromNewLogin>
<cas:687474703a2f2f736368656d61732e6d6963726f736f66742e636f6d2f6964656e746974792f636c61696d732f6f626a6563746964656e746966696572>8fa1e8a3-41b8-440e-91cf-fafa246ab571</cas:687474703a2f2f736368656d61732e6d6963726f736f66742e636f6d2f6964656e746974792f636c61696d732f6f626a6563746964656e746966696572>
<cas:authenticationDate>2018-10-04T13:22:05.643Z[Etc/UTC]</cas:authenticationDate>
<cas:clientName>MY_SAML</cas:clientName>
<cas:successfulAuthenticationHandlers>ClientAuthenticationHandler</cas:successfulAuthenticationHandlers>
<cas:687474703a2f2f736368656d61732e6d6963726f736f66742e636f6d2f6964656e746974792f636c61696d732f646973706c61796e616d65>Firstname Lastname</cas:687474703a2f2f736368656d61732e6d6963726f736f66742e636f6d2f6964656e746974792f636c61696d732f646973706c61796e616d65>
<cas:notBefore>2018-10-04T13:17:05.275Z</cas:notBefore>
<cas:credentialType>ClientCredential</cas:credentialType>
<cas:687474703a2f2f736368656d61732e6d6963726f736f66742e636f6d2f636c61696d732f617574686e6d6574686f64737265666572656e636573>http://schemas.microsoft.com/ws/2008/06/identity/authenticationmethod/password</cas:687474703a2f2f736368656d61732e6d6963726f736f66742e636f6d2f636c61696d732f617574686e6d6574686f64737265666572656e636573>
<cas:687474703a2f2f736368656d61732e6d6963726f736f66742e636f6d2f636c61696d732f617574686e6d6574686f64737265666572656e636573>http://schemas.microsoft.com/claims/multipleauthn</cas:687474703a2f2f736368656d61732e6d6963726f736f66742e636f6d2f636c61696d732f617574686e6d6574686f64737265666572656e636573>
<cas:687474703a2f2f736368656d61732e6d6963726f736f66742e636f6d2f6964656e746974792f636c61696d732f74656e616e746964>522b3803-a001-4675-b3b5-1d727d43585a</cas:687474703a2f2f736368656d61732e6d6963726f736f66742e636f6d2f6964656e746974792f636c61696d732f74656e616e746964>
<cas:687474703a2f2f736368656d61732e786d6c736f61702e6f72672f77732f323030352f30352f6964656e746974792f636c61696d732f6e616d65>myuserID#MYDOMAIN.onmicrosoft.com</cas:687474703a2f2f736368656d61732e786d6c736f61702e6f72672f77732f323030352f30352f6964656e746974792f636c61696d732f6e616d65>
<cas:authenticationMethod>ClientAuthenticationHandler</cas:authenticationMethod>
<cas:687474703a2f2f736368656d61732e6d6963726f736f66742e636f6d2f6964656e746974792f636c61696d732f6964656e7469747970726f7669646572>https://sts.windows.net/522b3803-a001-4675-b3b5-1d727d43585a/</cas:687474703a2f2f736368656d61732e6d6963726f736f66742e636f6d2f6964656e746974792f636c61696d732f6964656e7469747970726f7669646572>
<cas:notOnOrAfter>2018-10-04T14:17:05.275Z</cas:notOnOrAfter>
<cas:longTermAuthenticationRequestTokenUsed>false</cas:longTermAuthenticationRequestTokenUsed>
<cas:sessionindex>_337eded3-a927-4674-b78a-77259cfbf784</cas:sessionindex>
</cas:attributes>
</cas:authenticationSuccess>
So, we need to map this attribute - 687474703a2f2f736368656d61732e786d6c736f61702e6f72672f77732f323030352f30352f6964656e746974792f636c61696d732f6e616d65 to a standard attribute name via AttributeResolver
We have tried the following configuration but its not working out
"attributeReleasePolicy" : {
"#class" : "org.apereo.cas.services.ReturnMappedAttributeReleasePolicy",
"allowedAttributes" : {
"#class" : "java.util.TreeMap",
"name" : "username",
"displayname" : "userdisplayname",
"someattrname" : "groovy { return attributes['name']}"
}
}
So, anyone who was able to map the attributeNames via AttributeReleasePolicies ?
Any help related to this configuration will be really helpful
This issue is resolved. We had to give the complete path of the attribute and not just part of the name
{
"#class" : "org.apereo.cas.services.RegexRegisteredService",
"serviceId" : "^(https|imaps)://.*"
"name" : "SOME-NAME",
"id" : 200,
"description" : "This configuration is for app",
"evaluationOrder" : 10000
"logoutType" : "BACK_CHANNEL",
"logoutUrl" : "https://login.microsoftonline.com/522b3803-a001-4675-b3b5-1d727d43585a/saml2"
"attributeReleasePolicy" : {
"#class" : "org.apereo.cas.services.ReturnMappedAttributeReleasePolicy",
"allowedAttributes" : {
"#class" : "java.util.TreeMap",
"userid" : "groovy { return attributes['http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name']}"
"displayname" : "groovy { return attributes['http://schemas.xmlsoap.org/ws/2005/05/identity/claims/displayname']}"
}
}
}
So, post this configuration change, now the SAML Response is returning meaningful names
<cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'>
<cas:authenticationSuccess>
<cas:user>Elsbhy4pa-ZLcZ7OWNZ-0vKWjqzV4F7UfVYjRJTCjDY</cas:user>
<cas:attributes>
<cas:credentialType>ClientCredential</cas:credentialType>
<cas:isFromNewLogin>false</cas:isFromNewLogin>
<cas:authenticationDate>2018-10-05T09:20:07.216Z[Etc/UTC]</cas:authenticationDate>
<cas:authenticationMethod>ClientAuthenticationHandler</cas:authenticationMethod>
<cas:clientName>SOME_CLIENT</cas:clientName>
<cas:displayname>FirstName Lastname</cas:displayname>
<cas:successfulAuthenticationHandlers>ClientAuthenticationHandler</cas:successfulAuthenticationHandlers>
<cas:longTermAuthenticationRequestTokenUsed>false</cas:longTermAuthenticationRequestTokenUsed>
<cas:userid>myusername#MYDOMAIN.onmicrosoft.com</cas:userid>
</cas:attributes>
</cas:authenticationSuccess>
</cas:serviceResponse>

CamelCase resgitraiton of eureka app using REST API

I'm using eureka server,Config server and zuul server,and registering a rest service using Eureka REST API provided at
Eureka REST Operations
eureka url to register : http://localhost:8761/eureka/apps/DemoClient
with post body as below :
{
"instance": {
"instanceId":"localhost:DemoClient58181",
"hostName": "localhost",
"app": "DemoClient",
"ipAddr": "localhost",
"vipAddress": "DemoClient",
"secureVipAddress": "DemoClient",
"status": "UP",
"port": {"$": "58181", "#enabled": "true"},
"healthCheckUrl": "http://localhost:58181/healthcheck",
"statusPageUrl": "http://localhost:58181/status",
"homePageUrl": "http://localhost:58181",
"dataCenterInfo": {
"#class": "com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo",
"name": "MyOwn"
}
}
}
i can see the app registered as below
<application>
<name>DEMOCLIENT</name>
<instance>
<instanceId>localhost:58181</instanceId>
<hostName>localhost</hostName>
<app>DEMOCLIENT</app>
<ipAddr>localhost</ipAddr>
<status>UP</status>
<overriddenstatus>UNKNOWN</overriddenstatus>
<port enabled="true">58181</port>
<securePort enabled="false">7002</securePort>
<countryId>1</countryId>
<dataCenterInfo class="com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo">
<name>MyOwn</name>
</dataCenterInfo>
<leaseInfo>
<renewalIntervalInSecs>30</renewalIntervalInSecs>
<durationInSecs>90</durationInSecs>
<registrationTimestamp>1523540991583</registrationTimestamp>
<lastRenewalTimestamp>1523540991583</lastRenewalTimestamp>
<evictionTimestamp>0</evictionTimestamp>
<serviceUpTimestamp>1523538580531</serviceUpTimestamp>
</leaseInfo>
<metadata class="java.util.Collections$EmptyMap"/>
<homePageUrl>http://localhost:58181</homePageUrl>
<statusPageUrl>http://localhost:58181/status</statusPageUrl>
<healthCheckUrl>http://localhost:58181/healthcheck</healthCheckUrl>
<vipAddress>DemoClient</vipAddress>
<secureVipAddress>DemoClient</secureVipAddress>
<isCoordinatingDiscoveryServer>false</isCoordinatingDiscoveryServer>
<lastUpdatedTimestamp>1523540991583</lastUpdatedTimestamp>
<lastDirtyTimestamp>1523540991075</lastDirtyTimestamp>
<actionType>ADDED</actionType>
</instance>
</application>
when request with url http://localhost:58080/democlient/sayhello is accessed
but http://localhost:58080/DemoClient/sayhello is not accessed
when i add route configuration in zuul as
zuul:
ignoredServices: '*'
routes:
DemoClient:
path: /DemoClient/**
serviceId: DEMOCLIENT
then the CameCase route works.
Is there any way, how i can access route registering with CamelCase via REST api and not specifying route configuration in zuul.

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

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.