I am building a mobile app for android with Xamarin and I want to use paypal for the user to pay us. After the payment I want to sent the confirmation to our server to check that the payment is good and complet and made the modification relating to the purchased.
I used the Android SDK to create a Java Binding Library. I used the tutorial at: https://github.com/paypal/PayPal-Android-SDK/blob/master/docs/single_payment.md
PaymentConfirmation confirm =
data.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);
I turned it into C# as so:
PaymentConfirmation confirm =
data.GetParcelableExtra(PaymentActivity.ExtraResultConfirmation);
This give me an exception saying that there exist an explicit cast so I add it:
PaymentConfirmation confirm =
(PaymentConfirmation)data.GetParcelableExtra(PaymentActivity.ExtraResultConfirmation)
This gives the following exception: System.InvaliCastException: Cannot cast from source type to destination type.
I have tried all I could think of so I'm looking for help.
A functional partial project may be found here:
https://github.com/PhilSim22/PartialProject/tree/master
I am under a nondisclosure agreement so everything not related to the issue have been stripped out. sorry for the inconveniant.
I found the answer. I had to use a JAVA cast instead of a normal cast. here is my solution:
var confirmObj = data.GetParcelableExtra (PaymentActivity.ExtraResultConfirmation);
PaymentConfirmation confirm = Android.Runtime.Extensions.JavaCast<PaymentConfirmation> (confirmObj);
im you don't find the solution maybe the component parse.com can help you:
https://parse.com/tutorials/integrating-with-third-party-services
With any invalid cast exception, the first thing I would try would be to store the result you wish to cast into a temporary variable, and look at its type, either in Debug mode or through logging.
Therefore I would do something like this:
object temp = data.GetParcelableExtra(PaymentActivity.ExtraResultConfirmation);
Console.WriteLine(temp.GetType().FullName);
Console.WriteLine("Can Assign: {0}", typeof(PaymentConfirmation).IsAssignableFrom(temp.GetType()));
This way, you could see if the returned type matches the casted type PaymentConfirmation.
Can you share the full class name of the source and destination classes?
Related
I have a background in C++ and recently I started working in C#.
I have written following pieces of code (in Visual Studio):
var list_Loads = database.GetData<Load>().ToList();
var test_list = list_Loads.Where(o => (o.Name.Substring(0, 3) == "123")).ToList();
When I run the program and I move my mouse over both lists, first I get the count, which is very useful, but when I ask for the entries, this is what I get:
0 : namespace.Load
1 : namespace.Load
2 : namespace.Load
...
Not very useful, as you can imagine :-)
So my question: how can I show the Name attributes of those objects?
I thought: no problem. I have a background in native visualisers, so it should be rather easy to turn this into useful information, but then it comes:
In order to alter the way that those objects are represented, there is the first proposal to add a [DebuggerDisplay] "tag" to the definition of that class in source code.
However, as those classes are part of a framework I'm just referring to, I don't have access to the source code and hence I can't modify this.
Then I found another solution, which comes down to: "Write an entire C# project, debug, test and install it and it might work" (see documentation on "Custom visualisers of data" on the Microsoft website).
I almost choked in my coffee: writing an entire project, just for altering the view of an object??? (While, in C++, you just create a simple .natvis file, mention the classname and some configuration, launch .nvload and that's it.
Does anybody know a simple way to alter the appearance of C# object, without needing to pass through the whole burden of creating an entire C# project?
By the way, when I try to load a natvis file in Visual Studio immediate window, this is what I get:
.nvload "C:\Temp_Folder\test.natvis"
error CS1525: Invalid expression term '.'
What am I doing wrong?
Thanks in advance
OP (my emphasis):
In order to alter the way that those objects are represented, there is the first proposal to add a [DebuggerDisplay] "tag" to the definition of that class in source code.
However, as those classes are part of a framework I'm just referring to, I don't have access to the source code and hence I can't modify this.
Does anybody know a simple way to alter the appearance of C# object, without needing to pass through the whole burden of creating an entire C# project?
If you just want to specify [DebuggerDisplay] on a type, you don't have to have access to the source code. You can make use of [assembly:DebuggerDisplay()] and control how a type appears in the debugger. The only downside is that [assembly:DebuggerDisplay()] naturally only affects the current assembly whose code your mouse is hovering over. If you wish to use the customised display in other assemblies that you own, then you must repeat the [assembly:DebuggerDisplay()] definition.
Here's an easy before-and-after example with DateTime. I picked DateTime because we generally don't have access to the source code and it has some interesting properties:
var items = new List<DateTime>
{
DateTime.Now.AddDays(-2),
DateTime.Now.AddDays(-1),
DateTime.Now
};
...which on my machine defaults to:
Maybe I'm fussy and I just want to see:
Day of the week and
Day of the year
...I can do that via:
using System.Diagnostics;
[assembly: DebuggerDisplay("{DayOfWeek} {DayOfYear}", Target = typeof(DateTime))]
...which results in:
Example:
namespace DebuggerDisplayTests
{
public class DebuggerDisplayTests
{
public DebuggerDisplayTests()
{
var items = new List<DateTime>
{
DateTime.Now.AddDays(-2),
DateTime.Now.AddDays(-1),
DateTime.Now
};
}
}
.
.
.
}
Overrides
[assembly:DebuggerDisplay()] can also be used as a means to override pre-existing [DebuggerDisplay] on a 3-rd party type. Don't like what style they have chosen? Is the type showing far too much information? Change it with [assembly:DebuggerDisplay()].
I'm using the latest C# SAML2 library (4.3.1), and have been able to use it successfully with Okta; however, when trying to integrate with another identity provider, I'm getting the following error:
ArgumentException: IDX13300: 'System.String' must be an absolute Uri, was: 'System.Uri'
It seems to be complaining about the saml:AuthnContextDeclRef attribute, which has the value:
ncid/secure/form/30min/uri
I'm not sure, but I think maybe this attribute is expected to be an absolute Uri by the library. The customer says this value comes from their contract and is the same for everyone, so it can't be changed. They have other applications successfully integrated (they mentioned some are using ComponentSpace). Is there any setting I can change or fix you can provide for this to work? I've looked through the available settings and nothing looks like it is relevant. The only thing I can think to do at this point is to try another SAML library.
UPDATE:
So I was able to track the issue down to the Declaration Reference attribute not being an absolute Uri. This validation is in the Microsoft.IdentityModel.Tokens.Saml2.Saml2AuthenticationContext class which represents a portion of the Saml2 token. I agree that the best solution would be to change the Declaration Reference to an absolute Uri, but since the customer says they can't or won't change the value, I needed a solution.
I was able to download the ITFoxtec.Identity.Saml2 source code and make a few tweaks so it uses a custom Saml2Serializer that overrides the ReadAuthenticationContext method and skips the part that sets the Declaration Reference on the Authentication Context. ITFoxtec doesn’t use this property… in fact, it has code that sets it to null if it has a value, so preventing the property from getting set in the first place shouldn’t cause any issues, and it allows the SAML token to be read without triggering the validation error.
It sounds correct that the AuthnContextDeclRef value should be an absolute Uri.
Her an example of how to set a AuthnContextClassRef value:
RequestedAuthnContext = new RequestedAuthnContext
{
Comparison = AuthnContextComparisonTypes.Minimum,
AuthnContextClassRef = new string[]
{
//"https://data.gov.dk/concept/core/nsis/loa/Low"
"https://data.gov.dk/concept/core/nsis/loa/Substantial",
//"https://data.gov.dk/concept/core/nsis/loa/High"
},
}
I have a small WinRT client app to my online service (Azure Web Service). The server sends a JSON encoded object with (with potential additional metadata) to the client and the client's responsibility would be to deserialize this data properly into classes and forward it to appropriate handlers.
Currently, the objects received can be deserialized with a simple
TodoItem todo = JsonConvert.DeserializeObject<TodoItem>(message.Content);
However, there can be multiple types of items received. So what I am currently thinking is this:
I include the type info in the header serverside, such as "Content-Object: TodoItem"
I define attributes to TodoItem on the client side (see below)
Upon receiving a message from the server, I find the class using the attribute I defined.
I call the deserialization method with the resolved type
(Example of the attribute mentioned in 2.)
[BackendObjectType="TodoItem"]
public class TodoItem
My problem with this approach however is the Type to Generics in the deserialization as I can't call:
Type t = ResolveType(message);
JsonConvert.DeserializeObject<t>(message.Content);
I tried finding some solutions to this and getting method info for the DeserializeObject and calling it using reflection seemed to be the way to go. However, GetMethod() does not exist in WinRT and I was not able to find an alternative I could use to retrieve the generic version of the DeserializeObject (as fetching by the name gives me the non-generic overload). I don't mind using reflection and GetMethod as I can cache (?) the methods and call them every time a message is received without having to resolve it every time.
So how do I achieve the latter part and/or is there another way to approach this?
Alright, I feel like this was not really a problem at all to begin with as I discovered the DeserializeObject(string, Type, JsonSerializerSettings) overload for the method. It works splendidly. However, I would still like to hear some feedback on the approach. Do you think using attributes as a way to resolve the type names is reasonable or are there better ways? I don't want to use the class names directly though, because I don't want to risk any sort of man-in-the-middle things be able to initialize whatever.
Just a few minutes ago we have posted the alternative way to do what you want. Please look here, if you will have any questions feel free to ask:
Prblem in Deserialization of JSON
Try this
http://json2csharp.com/
Put your Json string here it will generate a class
then
public static T DeserializeFromJson<T>(string json)
{
T deserializedProduct = JsonConvert.DeserializeObject<T>(json);
return deserializedProduct;
}
var container = DeserializeFromJson<ClassName>(JsonString);
I know I can retrieve the predefined properties of files via RetrievePropertiesAsync() method. But now I want to add one more my own custom property like description, is it possible ? I tried this code, but getting exception
protected async override void OnNavigatedTo(NavigationEventArgs e)
{
StorageFile file = await KnownFolders.MusicLibrary.GetFileAsync("video.mp4");
List<string> propertiesName = new List<string>();
propertiesName.Add("CustomProperty");
string a = "Come and knock on our door. We've been waiting for you. Where the kisses are hers and hers and his, three's company, too! Come and dance on our floor. Take a step that is new. We've a lovable space that needs your face, three's company, too! You'll see that life is a ball again and laughter is callin' for you. Down at our rendezvous, three's company, too! The year is 1987 and NASA launches the last of America's deep space probes. In a freak mishap, Ranger 3 and its pilot Captain William 'Buck' Rogers are blown out of their trajectory into an orbit which freezes his life support system and returns Buck Rogers to Earth five hundred years later.";
IDictionary<string, object> extraProperties = await file.Properties.RetrievePropertiesAsync(propertiesName);
extraProperties.Add((new KeyValuePair<string, object>("CustomProperty", a)));
await file.Properties.SavePropertiesAsync(extraProperties);
}
An exception of type 'System.ArgumentException' occurred in App2.exe but was not handled in user code
WinRT information: The specified property name (CustomProperty) is invalid. The property may not be registered on the system.
Additional information: The parameter is incorrect.
P.S. : I want something like this
The errors seem to indicate that the property needs to be defined in the property system to be retrieved. Quick MSDN search shows it could be done using the PSRegisterPropertySchema function but it is only available to desktop apps.
This topic describes registering custom properties in more detail. Since there are already plenty of built-in properties and WinRT in Windows 8 as it is focuses on the fundamentals of it is unlikely that this would be possible from a Windows Store app. That means you could register the property with a desktop app, but your store app could not rely on its existence if it were to pass certification. The documentation for StorageItemContentProperties mentions using QueryOptions to query for properties defined by other apps which is what you could try using if you want to search for properties defined by some other applications.
Note Properties that are get or set using a property handler that is
defined by another app (like Microsoft Word) may not be accessible.
Instead, you can try to get these properties using a file query that
is backed by the system index. For more information, see
QueryOptions.
Apologies if I've framed the question incorrectly but I'm not sure where it fits in exactly.
I am executing a powershell script from C# which returns a collection of type PSObject. The data I want is contained in the field BaseObject and when debugging it tells me its type is (PowerShellInside.NetCmdlets.Commands.MessageInfoObject) and I can see all the information there. So my question is assuming that a 3rd party vendor assembly is not available to be referenced, what is the correct approach to retrieving data from this object say
(PowerShellInside.NetCmdlets.Commands.MessageInfoObject).Subject
Do you create your own version of this class omitting what you dont need or is there some neat dynamic typing that can be done.
I'm not a POSH developer so I'll take this from the C# angle.
I'll assume PSObject is the equivalent of System.Object and MessageInfoObject is the type returned from the script... I'd say using something like the following should work:
dynamic msgInfo = ExecutePOSHScript(...);