Serialize DataTable using protobuf-net-data gives Method Not Found error - protocol-buffers

I have been using the protobuf-net-data library (Richard Dingwall and Arjen Post) to serialize datatable. This was working fine and I was busy with something else. Recently I got back to this project, but I am getting error:
Method not found: 'Void ProtoBuf.ProtoWriter..ctor(System.IO.Stream, ProtoBuf.Meta.TypeModel, ProtoBuf.SerializationContext)'.
I took the source code and compiled as a separate library and tried to debug. Getting same error. In the DataSerializerEngine class, trying to enter the Writer.Serialize gives error.
public void Serialize(Stream stream, IDataReader reader, ProtoDataWriterOptions options)
{
if (stream == null)
{
throw new ArgumentNullException("stream");
}
if (reader == null)
{
throw new ArgumentNullException("reader");
}
Writer.Serialize(stream, reader, options);
}
I tried using older version of protobuf-net (2.3.2), but same issue. Not sure why I am getting this error. Much appreciate any help.
Latest update - After Marc's comments below: the latest version of protobuf-net-data was still using the ctor. I changed from using new to Create. With that, I am able to serialize. I took the protobuf-net-data src code and am making changes locally.
Now I am getting problem in DeSerialize (below 3065 was length of byte string sent after serialization of data table):
Sub-message not read entirely; expected -3, was 3065
at ProtoBuf.ProtoReader.State.ThrowProtoException(String message) in /_/src/protobuf-net.Core/ProtoReader.State.ReadMethods.cs:line 764
at ProtoBuf.ProtoReader.State.EndSubItem(SubItemToken token) in /_/src/protobuf-net.Core/ProtoReader.State.ReadMethods.cs:line 514
at ProtoBuf.ProtoReader.EndSubItem(SubItemToken token, ProtoReader reader) in /_/src/protobuf-net.Core/ProtoReader.cs:line 288
at ProtoBuf.Data.Internal.ProtoReaderContext.EndSubItem()
When I tried to use latest version of protobuf-net, the Create is deprecated as Marc mentioned. Some methods take writer as a parameter, so I am not sure how to change the code using State APIs.
regards

Related

Why do I get error when trying to add file attachments?

I am trying to use the method addFileAttachmentAsync() in office.js library.
This is the signature of the method I am using:
item.addFileAttachmentAsync(uploadLink, fileJson.name, { asyncContext: null }, function (asyncResult) { });
uploadLink is a string and here is an example of a file I'm trying to upload: https://xdr.purequad.com:6443/files/1b783908-a259-4839-93e2-18fe3248b943_moto.pdf.xdr
The file above is about ~3MB, but when I use a file under 1MB everything works perfectly.
Afterwards it throws this Exception :
Line: 9
Error: Unable to get property 'isInstanceOfType' of undefined or null reference
Also I have to mention this behavior happens only in IE11, while Google Chrome does not throw any exception at all and still does not work.
EDIT: The function was being interrupted before it ended properly! Check my comment.
I have solved the issue myself. When using addFileAttachmentAsync() because it's an async call one should never interrupt the task-pane with Office.context.ui.closeContainer() which was my case. Otherwise it will generate unexpected behavior.

What's the correct syntax for calling query.getObjectwithId(<id>, error())?

Environment:
Parse SDK version 1.90
Swift 2.1
Scenario:
Attempting to catch a query throw of an bad-query exception. I got the query template but I don't know the 2nd (error) parameter format.
I can't figure out what the syntax for the error parameter should be:
I removed the 'if' per suggestion, but got another compiler error:
Remedy?
The syntax of the error parameter is correct. However objectWithId does not return an Optional so wrapping it in a if let is not necessary and will cause an error (the 2nd error in your case).
This compiles without errors:
do {
let object = try query.getObjectWithId("OBJECT_ID", error: ())
print(object)
} catch {
print(error)
}
Regarding the Editor placeholder in source file error: That's strange one. Did you copy that code somewhere and paste it into Xcode? Try re-writing the code by hand. I did not get that error and I'm sure that it is unrelated to the syntax of the error parameter.
Apparently I was using an older parse.com SDK (v1.8.2). So I've updated to v. 1.9.0.
I got assorted Swift 2.1 syntax errors after I updated the parse.com frameworks.
So the remedy is the revised APIs using the new Swift 2.1 error handling paradigm:
do {
let videoObject = try query.getObjectWithId("")
} catch {
print("")
}

Breezejs How to debug cause of TypeError in query response

I'm attempting to use Breeze to query a ASP.Net Web API endpoint and the query fails - with the data object containing:
internalError: TypeError
arguments: Array[2]
0: "createCtor"
1: null
length: 2
__proto__: Array[0]
get message: function () { [native code] }
get stack: function () { [native code] }
set message: function () { [native code] }
set stack: function () { [native code] }
type: "non_object_property_load"
The data object has a message (and responsetext) property which contains the full json response from the query which looks ok and the metadata thats been generated matches the response - it also records status 200 for the response
So I'm guessing there is some kind of issue mapping the response to an object on the client side?
I'm using the NuGet package for Breeze version 0.85.2
I can get the sample ToDo project to run fine on the same environment
My project does use domain objects, contexts etc all from different assemblies and namespaces but I understood thats supported in this version?
Also that one of the properties is an enum - in the metadata this is defined as {\"name\":\"State\",\"type\":\"Edm.Self.State\",\"nullable\":\"false\"}] but in the response is comes through as an integer
Looking for tips on how to debug this further on the client side
Update
comparing the working sample with my code, the error looks to be coming from this function:
/**
Returns the constructor for this EntityType.
#method getEntityCtor
#return {Function} The constructor for this EntityType.
**/
ctor.prototype.getEntityCtor = function () {
if (this._ctor) return this._ctor;
var typeRegistry = this.metadataStore._typeRegistry;
var aCtor = typeRegistry[this.name] || typeRegistry[this.shortName];
if (!aCtor) {
var createCtor = v_modelLibraryDef.defaultInstance.createCtor;
if (createCtor) {
aCtor = createCtor(this);
} else {
aCtor = function() {
};
}
}
this._setCtor(aCtor);
return aCtor;
};
The defaultInstance property on v_modelLibraryDef is undefined in my running code - what am I missing on the configuration of breeze for that to happen?
Update 2 - Resolved but why
Ok so I got this working - I was missing a reference to knockout (which I was planning to use but hadn't got that far) - I was a little bit misled by the breeze prerequisites which don't mention knockout so if anyone can explain how I could have got this working without knockout and if its a bug then the points are yours
Got same error, and referencing knockout.js helped(I'm using angularjs for my app)
manager.executeQuery(query).then(function(data) {
console.log(data);
});
But.
It seems, that data-mapper works with knockout by default, so we have XHR results as K.O. model with observables.
so I added breeze.config.initializeAdapterInstance("modelLibrary", "backingStore", true);
and now I don't receive data.results as observable collection.
Hope my answer will help.
Sorry you struggled Richard. We'll try to learn from it and spare the next person the pain you endured.
FWIW, we do not say that Knockout is a prerequisite ... because KO is not a prerequisite. You can use Angular or Backbone instead and we anticipate other alternatives in future.
We don't want to drown you in configuration options when you're just learning Breeze. So we picked KO as the default model library (just as jQuery is the default AJAX provider and Web API is the default "dataservice" technology). We say so in numerous places; prerequisites looks like another good place to mention it.
As it happens, you intended to go with KO anyway so no configuration would have been necessary. Most folks start with something like the MVC template which includes KO and loads it for you in the Index.cshtml.
Apparently you started from a clean slate ("ASP Empty Web Application" perhaps?). The Breeze Web API NuGet package strives to be spare and therefore does not include KO. We figured (incorrectly) that you would add it yourself ... in the right script order ... if you wanted to use KO. Clearly we could do a better job of documenting this particular development path ... especially as we like it so much ourselves. Thanks for pointing it out.
The other problem is that the exception was not helpful. You can see from other attempts to answer your question that even folks with Breeze experience couldn't recognize what was wrong. We'll look to see if we can detect the missing script a little earlier and throw an exception with a better message.
This error looks like it has to do with one of your Entity type constructors. I'm guessing that you are calling the 'registerEntityTypeCtor' method somewhere in your code. If so, then I would put a breakpoint in the constructor that you are registering there.
Per your other comment, .NET enums are supposed to get converted into integers on the breeze client. This is the only 'primitive' datatype that could support them. They will get converted back to enums on the server when you call 'EntityManager.saveChanges'
Breeze does not require 'knockout', you can use either 'angularjs' or 'backbone' as well. We simply default the breeze client to knockout if you do not specify another library. See the 'breeze.config.initializeAdapterInstance' topic here. We do need to a better job of documenting this.
Every time I get an error at which the Message property of the response is the data in json format means I have a bug in the function that runs after getting the data.
Example:
dataservice.getPalanca(routeData.PalancaID)
.then(function (data) {
self.palanca(data.results[0]);
})
.fail(function (error) {
console.log(error); /*if I get here and error.Message == correct json almost always means error in .then function*/
toastr.error("Ha ocurrido un error al obtener los datos");
});
I hope I help you.

StackID Api issue

I downloaded the StackID api from the following link http://code.google.com/p/stackid/source/checkout
I followed the instructions in the readme file but am still encountering an exception.
The site crashes on this line in the Current.cs file
private static string SiteWideSalt { get { return KeyStore.GetKey(KeyStore.LatestKeyVersion).Salt; } }
The error I'm receiving is:
The type initializer for 'OpenIdProvider.Helpers.KeyStore' threw an exception.
{"Error converting value 1 to type 'OpenIdProvider.Helpers.KeyStore+Key'."} <--this is what's in the inner exception, which to me doesn't make sense since the property for value is byte and last I checked this should work with the number 1.
Any help would be appreciated, thanks!
I also had some issues there.
After putting the content of the key-gen file in square brackets "[]" to make it a JSON array I had to restart IIS and it works fine now.

MiniProfiler NullReferenceException in SqlServerStorage.LoadInBatch() function due to client timings

I'm getting the following exception when I click on the share link for an individual profile. I'm using the latest version from NuGet, 2.0.1.
The Exception:
System.NullReferenceException: Object reference not set to an instance of an object.
at StackExchange.Profiling.Storage.SqlServerStorage.LoadInBatch(DbConnection conn, Object idParameter) in C:\Users\sam\Desktop\MiniProfiler\StackExchange.Profiling\Storage\SqlServerStorage.cs:line 348
at StackExchange.Profiling.Storage.SqlServerStorage.Load(Guid id) in C:\Users\sam\Desktop\MiniProfiler\StackExchange.Profiling\Storage\SqlServerStorage.cs:line 297
at StackExchange.Profiling.UI.MiniProfilerHandler.Results(HttpContext context) in C:\Users\sam\Desktop\MiniProfiler\StackExchange.Profiling\UI\MiniProfilerHandler.cs:line 314
at StackExchange.Profiling.UI.MiniProfilerHandler.ProcessRequest(HttpContext context) in C:\Users\sam\Desktop\MiniProfiler\StackExchange.Profiling\UI\MiniProfilerHandler.cs:line 188
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
The code:
I found what I think is the source of the null reference in the code here:
ClientTimings clientTimings = null;
if (clientTimingList.Count > 0)
{
clientTimings.Timings = clientTimingList;
}
Am I missing something, or is that always going to throw an exception when there are entries in the clientTimingList?
Workarounds:
I thought maybe if I disabled batching, I wouldn't run the LoadInBatch function, but LoadIndividually has the same issue.
I looked for a way to disable client timings, but couldn't find a setting for it.
Maybe I could set a trigger in the database to delete the rows, but that seems a little extreme.
If I get the time, I'll get the code and submit a pull request. I wanted to make sure I wasn't missing anything obvious first.
Looks like it was a bug. I've added a ticket on github and a pull request to fix it: https://github.com/SamSaffron/MiniProfiler/pull/40
The new code looks like this:
if (clientTimingList.Count > 0)
{
clientTimings = new ClientTimings();
clientTimings.Timings = clientTimingList;
}

Resources