Principal issue
This piece of code works differently on 1.0.0-beta7-15532 in Windows and Debian. dnx --version: Microsoft .NET Execution environment Version: 1.0.0-beta7-15532 Type: CLR Architecture: x64 OS Name: Windows OS Version: 6.1.7601.65536
Microsoft .NET Execution environment Version: 1.0.0-beta7-15532 Type: Mono Architecture: x64 OS Name: Linux
Code:
namespace PrincipalBugTest2
{
public class Program
{
public void Main(string[] args)
{
string content = "DEMO:\n";
var identity = new System.Security.Principal.GenericIdentity("satan");
identity.AddClaim(new System.Security.Claims.Claim("id", "666", System.Security.Claims.ClaimValueTypes.Integer));
identity.AddClaim(new System.Security.Claims.Claim("token", "babadeda", System.Security.Claims.ClaimValueTypes.String));
System.Security.Claims.ClaimsPrincipal pri = new System.Security.Principal.GenericPrincipal(identity, null);
foreach (var claim in pri.Claims) {
content += claim.Type + ": " + claim.Value + "\n";
}
System.Console.WriteLine(content);
}
}
}
project.json:
{
"version": "1.0.0-*",
"description": "PrincipalBugTest2 Console Application",
"dependencies": {
},
"commands": {
"PrincipalBugTest2": "PrincipalBugTest2"
},
"frameworks": {
"dnx451": { }
}
}
Windows output:
DEMO:
http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name: satan
id: 666
token: babadeda
Linux output:
DEMO:
If we change this line
System.Security.Claims.ClaimsPrincipal pri = new System.Security.Principal.GenericPrincipal(identity, null);
to
System.Security.Claims.ClaimsPrincipal pri = new System.Security.Claims.ClaimsPrincipal(identity);
it produces similar output on Windows and Debian
@brentschmaltz?
Your Linux demo is probably failing with an exception that it can't print before the process exits. Try wrapping it in a try/catch to print the exception.
I did wrap it in try/catch and it produced no different output than the previous one.
try {
string content = "DEMO:\n";
var identity = new System.Security.Principal.GenericIdentity("satan");
identity.AddClaim(new System.Security.Claims.Claim("id", "666", System.Security.Claims.ClaimValueTypes.Integer));
identity.AddClaim(new System.Security.Claims.Claim("token", "babadeda", System.Security.Claims.ClaimValueTypes.String));
System.Security.Claims.ClaimsPrincipal pri = new System.Security.Principal.GenericPrincipal(identity, null);
foreach (var claim in pri.Claims) {
content += claim.Type + ": " + claim.Value + "\n";
}
System.Console.WriteLine(content);
}
catch (System.Exception ex) {
System.Console.WriteLine(ex.Message.ToString());
}
... and I closed it by accident.
@BrennanConroy This looks suspiciously like your null ref coreclr bug. Can you repro this?
He isn't running on CoreCLR
I don't know what the correct behavior is, but if the windows behavior is correct then its a mono bug, see https://github.com/mono/mono/blob/b7a308f660de8174b64697a422abfc7315d07b8c/mcs/class/corlib/System.Security.Principal/GenericPrincipal.cs#L46-L58 they set m_identity but that isn't a member in the base class so it isn't used when getting claims