NewtonSoft JSON.NEt 7.0.1 - serialization

Previously I have been serializing DataTables with simply JsonConvert.Serialize(oMyTable), in version 6.0.8 which works just fine, I updated today to 7.0.1 and if I run my webservice method via invoke on the web site, the return values are just as before. However, if I call the exact same instance of the webservice from an application, it isn't invoking the DataTableConverter and I get the serialized result containing all the properties of a DataTable object. It seems to not run the DataTableConverter, anyone else having a similar problem? Yes, the DataTable has rows and it also has a name. I noticed some changes to the DataTableConverter mentioned in the 7.0.1 release, did something change that would cause the converter not to be invoked as it was previously?
Thanks
Alan
Code that previously worked (and still does using 6.0.8):
public string GetZoneConfiguration(int iZoneId)
{
string sOutput = string.Empty;
if (string.IsNullOrEmpty(this.RFIDConnection))
{
oLog.Error("{0}, no RFIDConnection value.", System.Reflection.MethodBase.GetCurrentMethod().Name);
return sOutput;
}
DBUtility oDatabase = new DBUtility(this.RFIDConnection);
string sSQL = "select zone_id, zone_org, zone_name, zone_type, read_time, read_cycles, sensor_bounce_time, sensor_method, filter, reader_id, reader_name, reader_tcp_address from vw_rfid_zone_readers";
sSQL += " where zone_id = " + iZoneId.ToString() + " and reader_active = 1";
DataTable oTable = new DataTable("ZoneConfiguration");
if (!oDatabase.ReadData(sSQL, ref oTable))
{
oLog.Error("{0}, ReadData returned {1}.", System.Reflection.MethodBase.GetCurrentMethod().Name, oDatabase.SQLError);
}
sOutput = JsonConvert.SerializeObject(oTable);
return sOutput;
}

I too have had problems with code that worked in an old version but doesn't in the latest version. I just rolled back, on Nuget you can still install the older versions which is nice!

Related

Error trying to run ASE sql (sybase) on .net core web api "A request to send or receive data was disallowed ..."

When I run this SQL, I get this error
This is the second SQL I run, but I tried running the 1st SQL that works twice and a row and it worked fine, so maybe not a open connection issue?
A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using a send to call) no address was supplied.
last time I got that error, in very similar code, it was because I left the "#" off the variable name in the args section.
So I strongly suspect this is the bad generic error for "Your SQL calling code is messed up somehow" or "that returned 0 rows"(man, I hope its not the latter)
public List<EnrTypeSepInfoCV> GetEnrTypeSepInfo(long enrId)
{
var aseSqlConnectionString = configuration.GetConnectionString("SybaseDBDapper");
string sql = "";
sql += "select et.enrtype_id, ";
sql += " et.active as stud_status, ";
sql += " s.sep_dt ";
sql += "from enrollment_type et,separation s ";
sql += "where et.enrtype_id *= s.enrtype_id ";
sql += "and et.enr_id = #al_enr_id ";
dapperTools.DapperCustomMapping<EnrTypeSepInfoCV>();
try
{
using (IDbConnection db = new AseConnection(aseSqlConnectionString))
{
var arguments = new
{
#al_enr_id = enrId
};
List<EnrTypeSepInfoCV> ll = new List<EnrTypeSepInfoCV>();
ll = db.Query<EnrTypeSepInfoCV>(sql, arguments).ToList();
return ll;
}
}
catch (Exception ex)
{
Trace.WriteLine(ex.ToString());
return null;
}
}
If I pull the SQL out, replace the variable with the passed in value everything works.
I looked line by line comparing this to a working SQL call method and I can't see any differences.
Anyone know what I did wrong?
Is there a way to get more informative errors in situations like this?
If it matters, I'm writing a .Net Core web API Service to be consumed by a Vue app running against a Sybase DB v12.*.
I have other API methods working correctly, that call the DB the same way.
Here is my data object
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace SpProofOfConceptAPI.Dto
{
public class EnrTypeSepInfoCV
{
[Dapper.Column("enrtype_id")]
public Int64 EnrTypeId { get; set; }
[Dapper.Column("stud_status")]
public string StudStatus { get; set; }
[Dapper.Column("sep_dt")]
public DateTime? SepDt { get; set; }
}
}
Okay,
So this message appears to be a generic "something went wrong connecting" message.
In my case, it was the connection timeout expiring. the Default is 15s, I changed it to 600s, and it's working fine. (We have some long running reports that can take a long time)
Since it's on ASE, I just added 'Connection Timeout = 600;'.

LINQPad "The name SubmitChanges does not exist"

Working with LINQPad 5 on virtual machine win 10. Select queries work, now I try to use update query and it gives me an error about SubmitChanges() method.
CS0103 The name 'SubmitChanges' does not exist in the current context.
Basically all answers that I found are like this: write SubmitChanges() or SaveChanges() if you are using EF. Also I tried to change from C# Statements to C# Program.
How to submit changes in LinqPad
In one answer user might not add a connection, which I did. (screen 1)
LINQpad: Global function SubmitChanges not found
Then I tried to pass a "this" to a method, and in my case "this" is an UserQuery, not a DataContext. (screen 2) Which is wierd.
linqpad - SubmitChanges Extension
void Main()
{
var ret =from t in Tbblankimages where t.Comment == "1234" select t;
var im = ret.First();
MemoryStream ms = new MemoryStream();
using (FileStream file = new FileStream("E:\\saved.jpg",FileMode.Open,System.IO.FileAccess.Read))
{
file.CopyTo(ms);
}
byte[] imageData= ms.ToArray();
im.Image = imageData;
Test(this);
}
static void Test(System.Data.Linq.DataContext c)
{
c.SubmitChanges();
}
Screenshots with error messages:
https://imgur.com/a/18a7lSo (screen 1)
https://imgur.com/a/Nipp7t5 (screen 2)
Also I should add that the database is PostgreSQL and I use custom driver to it from here:
https://github.com/fknx/linqpad-postgresql-driver
Version of Postgresql is 11.3-4-windows-x64
With postgresql driver it works differently:
https://github.com/fknx/linqpad-postgresql-driver
var user = Users.Single(u => u.Id == 42);
user.Emailaddress = "john.doe#abc.com";
this.Update(user);
Sometimes Linqpad disconnects and causes this problem.
I click on the top left Refresh button to solve this problem.

The type initializer for 'MimeKit.ParserOptions' threw an exception

I am testing using an existing System.Net.Mail.MailMessage with MimeKit's support for direct casting to a MimeMessage in addition to using MimeKit's DkimSigner and MailKit's Smtp client.
I am getting "The type initializer for 'MimeKit.ParserOptions' threw an exception." With a stack trace mentioning 'at MimeKit.MimeMessage.CreateFromMailMessage(MailMessage message)'
There is also an Inner Excpetion: "The type initializer for 'MimeKit.Utils.CharsetUtils' threw an exception." Stacktrace: 'at MimeKit.ParserOptions..ctor() at MimeKit.ParserOptions..cctor()
I am not getting any exception on my development box but that only executes up to the conversion and signing not the actual smtp sending.
Dim netMail As New System.Net.Mail.MailMessage
netMail.From = New System.Net.Mail.MailAddress("no_reply#lionandlambchurch.com")
netMail.To.Add(txtTo.Text)
netMail.Subject = txtSubject.Text
netMail.Body = txtContent.Text
Dim mimeMail As MimeMessage = CType(netMail, MimeMessage)
Dim headersToSign = New List(Of HeaderId)
headersToSign.Add(HeaderId.From)
headersToSign.Add(HeaderId.To)
headersToSign.Add(HeaderId.Subject)
headersToSign.Add(HeaderId.Date)
Dim privateKeyPath = AppDomain.CurrentDomain.BaseDirectory + "\App_Data\rsa.private"
Dim signer = New Cryptography.DkimSigner(privateKeyPath, "lionandlambchurch.com", "key1")
Dim loggerPath = AppDomain.CurrentDomain.BaseDirectory + "\logs\smtp-mailkit.log"
mimeMail.Sign(signer, headersToSign, Cryptography.DkimCanonicalizationAlgorithm.Relaxed, Cryptography.DkimCanonicalizationAlgorithm.Simple)
' Don't attempt sending locally
If Request.Url.Host.ToLower().Contains("localhost") Then Return
Using client As New MailKit.Net.Smtp.SmtpClient(New ProtocolLogger(loggerPath))
client.Connect("relay-hosting.secureserver.net", 25, False)
If chkAuthenticate.Checked Then
client.Authenticate("no_reply#lionandlambchurch.com", "****")
End If
client.Send(mimeMail)
client.Disconnect(True)
End Using
Had same problem and I solved it by opening the NuGet console in Visual Studio and installing the newest System.Text.Encoding.CodePages package:
install-Package System.Text.Encoding.CodePages
Based on the exception, the error is occurring during the conversion, not sending.
For some reason, the static constructor for MimeKit.ParserOptions is failing because the static constructor for MimeKit.Utils.CharsetUtils is failing.
Looking at MimeKit's code, all I can think of is that your server doesn't have UTF-8 or Latin1 support.
e.g. System.Text.Encoding.GetEncoding (65001, new EncoderExceptionFallback (), new DecoderExceptionFallback ()); or Encoding.GetEncoding (28591, new EncoderExceptionFallback (), new DecoderExceptionFallback ()); is throwing an exception.
Honestly, I don't know how that could even happen.
What .NET are you using on your server?

Unable to query a different workspace

I was trying to follow this post to query a testcase in a workspace("/workspace/6749437088") that is not the default workspace but the query is not returning that testcase and in fact, not returning anything. Below is the code I am using. If I do a query with 'not equal' the test cases, I notice that it is returning test cases in the user's default workspace. I am using C# and using Rally Rest API Runtime v4.0.30319 and ver 1.0.15.0. Any suggestions? Thanks.
Inserting test case result using Java Rally Rest API failing when workspace is different from default set on account
private string GetRallyObj_Ref(string ObjFormttedId)
{
string tcref = string.Empty;
try
{
string reqType = _Helper.GetRallyRequestType(ObjFormttedId.Substring(0, 2).ToLower());
Request request = new Request(reqType);
request.Workspace = "/workspace/6749437088";
request.Fetch = new List<string>()
{
//Here other fields can be retrieved
"Workspace",
"Name",
"FormattedID",
"ObjectID"
};
//request.Project = null;
string test = request.Workspace;
request.Query = new Query("FormattedID", Query.Operator.Equals, ObjFormttedId);
QueryResult qr = _RallyApi.Query(request);
string objectid= string.Empty;
foreach (var rslt in qr.Results)
{
objectid = rslt.ObjectID.ToString();
break;
}
tcref = "/"+reqType+"/" + objectid;
}
catch (Exception ex)
{
throw ex;
}
return tcref;
Sorry, I found out the issue. I was feeding the code a project ref#, not a workspace ref #. I found out the correct workspace by using pieces of the code in the answer part of this post: Failed when query users in workspace via Rally Rest .net api by querying the workspace refs of the username I am using and there I found out the correct workspace ref. Thanks, Kyle anyway.
The code above seems like it should work. This may be a defect- I'll look into that. In the meantime if you are just trying to read a specific object from Rally by Object ID you should be able to do so like this:
restApi.GetByReference('/testcase/12345',
'Results, 'Verdict', 'Duration' //fetch fields);

Testing Void in Visual Studio 2010

I have single project(c#) and have the following codes.
Everything is working fine. But I just want to know
how to test it and view the result in Visual Studio 2010.
I am classic asp developer and always use Response.end() to get result. but no idea how to do it in c# project. Thanks.
public static string ApplicationLocationList()
{
GetApplicationLocationListTableAdapter getApplicationLocationListTableAdapter = new GetApplicationLocationListTableAdapter();
DataTable dtgetApplicationLocationListTableAdapter.GetApplicationLocationListData(Library.MovieClass.saveApplicationID);
if (dt.Rows.Count > 0)
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < dt.Rows.Count; i++)
{
string cityList = dt.Rows[i]["City"].ToString();
string stateList = dt.Rows[i]["State"].ToString();
sb.Append(cityList + "," + stateList + System.Environment.NewLine);
}
return sb.ToString();
}
else
{
return string.Empty;
}
}
Judging by your reference to the Response object, I'm guessing this is an ASP.NET project. If you want to see the contents of sb on the page, you could try the following:
Response.Write(sb.ToString());
Response.Flush();
That should write the contents of the StringBuilder to the Response buffer & the Flush() method should send it down to the client page.
If you want to see only the empty string returned, you could just omit the Write() method & just Flush() the response, which should show you only a blank page after the postback.
I'm assuming that this is an ASP.NET application, in which case you want to use System.Web.HttpApplication.CompleteRequest as an equivalent to Response.End, and Response.Write(sb.ToString()); before the return sb.ToString();.
If it's a console application, then use System.Diagnostics.Debug.WriteLine(sb.ToString()); in the same place.