Backendless API - Create user - c#

I'm trying to use Backendless API on a C# .net 4.5 application, but there is no way to make it work, since I get
"An unhandled exception of type 'System.StackOverflowException'
occurred in weborb.dll."
Code is simple, but doesn't work. The Java sample with Java BE Api worked normally.
public static void init()
{
Backendless.InitApp(APP_ID, SECRET_KEY, VERSION);
}
public static void RegisterUser()
{
BackendlessUser user = new BackendlessUser();
string error;
user.SetProperty("ID", "id");
user.SetProperty("password","12");
try
{
Backendless.UserService.Register(user); //StackOverflow error here
}
catch (BackendlessException exception)
{
error = exception.FaultCode;
}
}

From the linked sample:
static void Main( string[] args )
{
Backendless.InitApp( APP_ID, SECRET_KEY, VERSION_ID );
BackendlessUser loggedInUser = Backendless.UserService.Login( USER_NAME, PASS_WORD );
System.Console.WriteLine( "logged in user - " + loggedInUser.Email );
}

Backendless team solved this for me, link to the sample in the comments.

Related

QuickFix - 'ObjectDisposedException' error on NewOrderSingle

I'm working on FxPro Ctrader broker (FIX 4.4) and I'm trying to make an FixApi in C# using QuickFix/n library (1.7.0.0).
I stucked at 'NewOrderSingle':
After successful logon I'm trying to make an order:
class TradeConnection : MessageCracker, IApplication
{
public void OnLogon(SessionID sessionID)
{
Write.Info("Account TRADE successful logged " + sessionID);
sendOrder();
}
public void sendOrder()
{
NewOrderSingle oc = new NewOrderSingle();
ClOrdID ID = new ClOrdID("1408479");
Symbol symb = new Symbol("1");
Side side = new Side('1');
OrderQty lots = new OrderQty(1000);
OrdType type = new OrdType('1');
TransactTime TransactTime = new TransactTime(DateTime.Now);
TimeInForce TimeInForce = new TimeInForce('3');
oc.SetField(ID);
oc.SetField(symb);
oc.SetField(side);
oc.SetField(lots);
oc.SetField(type);
oc.SetField(TimeInForce);
send(oc);
}
public void send(QuickFix.Message message)
{
Session.SendToTarget(message, sessionID);
}
}
Unfortunately it isn't working and I get error:
A first chance exception of type 'System.ObjectDisposedException' occurred in System.dll
Same error appears #
RequestForPositions and OrderStatusRequest
On same account in api that uses NetworkStream rather than QuickFix lib it works fine.
Problem solved.
Forgot to set field TransactTime which counterparty required:
oc.SetField(TransactTime);

Getting unexpected crash reports inside a try-catch block

I'm using HockeyApp to collect crash data for my app, but for some reason it doesn't provide the stack trace.
What I have is something like that:
MyNamespace!<BaseAddress>+0x5d1287
MyNamespace!<BaseAddress>+0x5f18d5
MyNamespace!<BaseAddress>+0x5f1827
Microsoft.HockeyApp.Extensibility.Windows.UnhandledExceptionTelemetryModule.CoreApplication_UnhandledErrorDetected(Object sender, ApplicationModel.Core.UnhandledErrorDetectedEventArgs e)
so it's kinda hard to find out what's happening.
The exception message is helpful tho, as it says
Element not found. Cannot find credential in Vault
and there's just one place in which I'm using PasswordVault.
The problem here is that I'm using it inside a try/catch block, so I really don't understand why I'm getting this report, and I can't even reproduce it.
This is the full PasswordVaultService class, so that you can see exactly what I'm doing.
public class PasswordVaultService
{
private static readonly PasswordVault Vault = new PasswordVault();
public static string RetrieveSecret(Entry entry)
{
try
{
var results = Vault.FindAllByResource(entry.Name);
if (results.Count == 0) return null;
var result = results[0];
result.RetrievePassword();
return result.Password;
}
catch (Exception)
{
return null;
}
}
public static void StoreSecret(Entry entry, string secret)
{
Vault.Add(new PasswordCredential(entry.Name, entry.Name, secret));
}
public static void DeleteSecret(Entry entry)
{
var results = Vault.FindAllByResource(entry.Name);
if (results.Count == 0) return;
var result = results[0];
Vault.Remove(result);
}
}
I've been getting this error for some time now, and I don't understand what's going on because the class is quite simple. Before posting I've even searched for Vault inside the project and this is the only place where I'm using the PasswordVault.

Cross Thread Operation Not Valid C# Winform

I'm trying to make an Application (similar to whatsapp), well everything is implemented but when ever i try to update any GUI component is give me exception i searched and found we should check invokeRequired and invoke it accordingly this is my code but still the exception is there.
delegate void statuss(string str);
void showstatus(string str)
{
metroLabel2.Visible = true;
metroLabel2.Text = "Status: " + str;
}
private void Wa_OnGetStatus(string from, string type, string name, string status)
{
statuss get = new statuss(showstatus);
get(status);
if (metroLabel2.InvokeRequired)
{
Invoke(get, metroLabel2, status);
}
}

How to get debuginfo to work on compiled delegate

I am working on a pet project: A programing language in the Javascript/Scheme mindset the project can be found here
I have looked through existing Stackoverflow questions such as Making a CLR/.NET Language Debuggable. However most of these solutions deal with generating assemblies. For numerous reasons I would prefer to avoid creating a new assembly.
class Program
{
public static void ThrowingFunction()
{
throw new Exception("Test Exception");
}
static void Main(string[] args)
{
Action thw = ThrowingFunction;
ParameterExpression param = Expression.Parameter(typeof(int), "arg");
SymbolDocumentInfo info = Expression.SymbolDocument("example-script", new Guid("83c65910-8376-11e2-9e96-0800200c9a66"));
Expression<Func<int,int>> exp = Expression.Lambda<Func<int,int>>(
Expression.Block(
Expression.DebugInfo(info,1,1,1,20),
Expression.Invoke(Expression.Constant(thw, typeof(Action))),
Expression.Add(param,Expression.Constant(1))
),
new List<ParameterExpression> { param }
);
Console.WriteLine(exp);
Func<int,int> Fn = exp.Compile(DebugInfoGenerator.CreatePdbGenerator());
try {
Fn(1);
}
catch (Exception e) {
Console.WriteLine(e);
Console.WriteLine(e.InnerException);
}
}
}
The above code works however the debug info does not contain the line information for the lambda instead referring obliquely to lambda_method with no other information in the stack trace.
How can I get the stack trace to also show line information.

Get Line Number and File Information in Code Where code is written in c# [duplicate]

Here is an example of what I want to do:
MessageBox.Show("Error line number " + CurrentLineNumber);
In the code above the CurrentLineNumber, should be the line number in the source code of this piece of code.
How can I do that?
In .NET 4.5 / C# 5, you can get the compiler to do this work for you, by writing a utility method that uses the new caller attributes:
using System.Runtime.CompilerServices;
static void SomeMethodSomewhere()
{
ShowMessage("Boo");
}
...
static void ShowMessage(string message,
[CallerLineNumber] int lineNumber = 0,
[CallerMemberName] string caller = null)
{
MessageBox.Show(message + " at line " + lineNumber + " (" + caller + ")");
}
This will display, for example:
Boo at line 39 (SomeMethodSomewhere)
There's also [CallerFilePath] which tells you the path of the original code file.
Use the StackFrame.GetFileLineNumber method, for example:
private static void ReportError(string message)
{
StackFrame callStack = new StackFrame(1, true);
MessageBox.Show("Error: " + message + ", File: " + callStack.GetFileName()
+ ", Line: " + callStack.GetFileLineNumber());
}
See Scott Hanselman's Blog entry for more information.
[Edit: Added the following]
For those using .Net 4.5 or later, consider the CallerFilePath, CallerMethodName and CallerLineNumber attributes in the System.Runtime.CompilerServices namespace. For example:
public void TraceMessage(string message,
[CallerMemberName] string callingMethod = "",
[CallerFilePath] string callingFilePath = "",
[CallerLineNumber] int callingFileLineNumber = 0)
{
// Write out message
}
The arguments must be string for CallerMemberName and CallerFilePath and an int for CallerLineNumber and must have a default value. Specifying these attributes on method parameters instructs the compiler to insert the appropriate value in the calling code at compile time, meaning it works through obfuscation. See Caller Information for more information.
I prefer one liners so:
int lineNumber = (new System.Diagnostics.StackFrame(0, true)).GetFileLineNumber();
In .NET 4.5 you can get the line number by creating the function:
static int LineNumber([System.Runtime.CompilerServices.CallerLineNumber] int lineNumber = 0)
{
return lineNumber;
}
Then each time you call LineNumber() you will have the current line. This has the advantage over any solution using the StackTrace that it should work in both debug and release.
So taking the original request of what is required, it would become:
MessageBox.Show("Error enter code here line number " + LineNumber());
This is building on the excellent answer by Marc Gravell.
For those who need a .NET 4.0+ method solution:
using System;
using System.IO;
using System.Diagnostics;
public static void Log(string message) {
StackFrame stackFrame = new System.Diagnostics.StackTrace(1).GetFrame(1);
string fileName = stackFrame.GetFileName();
string methodName = stackFrame.GetMethod().ToString();
int lineNumber = stackFrame.GetFileLineNumber();
Console.WriteLine("{0}({1}:{2})\n{3}", methodName, Path.GetFileName(fileName), lineNumber, message);
}
How to call:
void Test() {
Log("Look here!");
}
Output:
Void Test()(FILENAME.cs:104)
Look here!
Change the Console.WriteLine format how you like!
If its in a try catch block use this.
try
{
//Do something
}
catch (Exception ex)
{
System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace(ex, true);
Console.WriteLine("Line: " + trace.GetFrame(0).GetFileLineNumber());
}
You only asked about the line number and with nullable project type, you then need to use a something like this
internal class Utils
{
public static int Line([CallerLineNumber] int? lineNumber =null)=>lineNumber;
}
in your code, if you like to get a line number you then just call
var line=Utils.Line();
if you are logging and you would like to document the line number in say logging than call the method like this
public void MyMethod(int someValue)
{
switch(someValue)
{
case 1:
if(abc<xyz)
{
logger.LogInformation("case value {someValue} this line {line} was true", someValue ,Utils.Line()-2);
}
break;
case 2:
logger.LogInformation("case value {someValue} this {line} was executed",someValue,Utils.Line());
break;
caste 3:
logger.LogInformation("case value {someValue} this {line} was executed",someValue,Utils.Line());
break;
}
}
You can extend this pattern with any of the other [CallerXXX] methods and not use them where ever, not just in the method parameters.
in the Nuget Package Walter I use a super cool class named ExceptionObject
if you import the NuGet package you have some nice extension methods on the Exception class as well as access to a CallStack showing the call chain including method parameters and parameter values of all methods called.
It's like a stack of an exception only with values showing how you got where you got with what values.
public void MyMethod()
{
try
{
//get me all methods, signatures, parameters line numbers file names etc used as well as assembly info of all assemblies used for documentation of how the code got here
var stack= new CallStack();
foreach( var frame in StackedFrames)
{
logger.LogDebug(frame.ToString());
}
}
catch(SqlException e)
{
var ex = new ExceptionObject(e);
logger.LogException(e,"{this} exception due to {message} {server} {procedure} TSQL-line:{sqlline}\n{TSQL}"
,e.GetType().Name
,e.Message
,ex.SqlServer
,ex.SqlProcedureName
,ex.SqlLineNumber
,ex.Tsql
,ex.CallStack);
}
catch(Exception e)
{
var ex = new ExceptionObject(e);
logger.LogException(e,"{this} exception due to {message} signature: signature}\nCallStack:", e.GetType().Name,e.Message,ex.Signature,ex.CallStack);
}
}

Categories