Alexa Skill request deserialization fails - json to SkillRequest object C# - c#

I would like to get some help here, I am using Alexa.NET nuget package to develop a custom alexa skill using c#, I get the following error.
My Request to the Function(AWS Lambda):
{
"version": "1.0",
"session": {
"new": true,
"sessionId": "amzn1.echo-api.session.[unique-value-here]",
"application": {
"applicationId": "amzn1.ask.skill.[unique-value-here]"
},
"user": {
"userId": "amzn1.ask.account.[unique-value-here]"
},
"attributes": {}
},
"context": {
"AudioPlayer": {
"playerActivity": "IDLE"
},
"System": {
"application": {
"applicationId": "amzn1.ask.skill.[unique-value-here]"
},
"user": {
"userId": "amzn1.ask.account.[unique-value-here]"
},
"device": {
"supportedInterfaces": {
"AudioPlayer": {}
}
}
}
},
"request": {
"type": "LaunchRequest",
"requestId": "amzn1.echo-api.request.[unique-value-here]",
"timestamp": "2016-10-27T18:21:44Z",
"locale": "en-US"
}
}
The Deserialization Error:
System.Exception: Error deserializing the input JSON to type SkillRequest
at Amazon.Lambda.TestTool.Runtime.LambdaExecutor.BuildParameters(ExecutionRequest request, ILambdaContext context) in C:\codebuild\tmp\output\src142363207\src\Tools\LambdaTestTool\src\Amazon.Lambda.TestTool\Runtime\LambdaExecutor.cs:line 214
at Amazon.Lambda.TestTool.Runtime.LambdaExecutor.ExecuteAsync(ExecutionRequest request) in C:\codebuild\tmp\output\src142363207\src\Tools\LambdaTestTool\src\Amazon.Lambda.TestTool\Runtime\LambdaExecutor.cs:line 52
---------------- Inner 1 Exception ------------
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Amazon.Lambda.TestTool.Runtime.LambdaExecutor.BuildParameters(ExecutionRequest request, ILambdaContext context) in C:\codebuild\tmp\output\src142363207\src\Tools\LambdaTestTool\src\Amazon.Lambda.TestTool\Runtime\LambdaExecutor.cs:line 202
---------------- Inner 2 Exception ------------
Amazon.Lambda.Serialization.SystemTextJson.JsonSerializerException: Error converting the Lambda event JSON payload to type Alexa.NET.Request.SkillRequest: Deserialization of reference types without parameterless constructor is not supported. Type 'Alexa.NET.Request.Type.Request'
at Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer.Deserialize[T](Stream requestStream)
---------------- Inner 3 Exception ------------
System.NotSupportedException: Deserialization of reference types without parameterless constructor is not supported. Type 'Alexa.NET.Request.Type.Request'
at System.Text.Json.ThrowHelper.ThrowNotSupportedException_DeserializeCreateObjectDelegateIsNull(Type invalidType)
at System.Text.Json.JsonSerializer.HandleStartObject(JsonSerializerOptions options, ReadStack& state)
at System.Text.Json.JsonSerializer.ReadCore(JsonSerializerOptions options, Utf8JsonReader& reader, ReadStack& readStack)
at System.Text.Json.JsonSerializer.ReadCore(Type returnType, JsonSerializerOptions options, Utf8JsonReader& reader)
at System.Text.Json.JsonSerializer.ParseCore(ReadOnlySpan`1 utf8Json, Type returnType, JsonSerializerOptions options)
at System.Text.Json.JsonSerializer.Deserialize[TValue](ReadOnlySpan`1 utf8Json, JsonSerializerOptions options)
at Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer.Deserialize[T](Stream requestStream)
SkillRequest.cs(From Alexa.NET nuget package):
public class SkillRequest
{
public SkillRequest();
[JsonProperty("version")]
public string Version { get; set; }
[JsonProperty("session")]
public Session Session { get; set; }
[JsonProperty("context")]
public Context Context { get; set; }
[JsonProperty("request")]
public Type.Request Request { get; set; } //This is throwing the deserialization error
//See below for properties within this.
public System.Type GetRequestType();
}
Request property type in SkillRequest above(this is where the problem is I think):
[JsonConverter(typeof(RequestConverter))]
public abstract class Request
{
protected Request();
[JsonProperty("type", Required = Required.Always)]
public string Type { get; set; }
[JsonProperty("requestId")]
public string RequestId { get; set; }
[JsonProperty("locale")]
public string Locale { get; set; }
[JsonConverter(typeof(MixedDateTimeConverter))]
[JsonProperty("timestamp")]
public DateTime Timestamp { get; set; } // This might be the problem?
}
I tried different DateTime formats, I played around by removing properties, to see if it goes past the deserialization error, nothing seems to be working. Can someone help?

I had this same issue, serializing JSON as per an Alexa tutorial I was following. This post helped me to resolve it, however, I was not comfortable with the idea of rewriting the Alexa.net class locally, as it was used this way in working tutorials I was following.
According to: Amazon From .net core 3 there is a new JSON serializer used in the templates. It provides a performance benefit, but also seems to introduce this error with Alexa.Net.
[assembly: LambdaSerializerAttribute(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))]
was replaced by
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))]
The new serializer was throwing the 'parameterless constructor' error. After installing the Amazon.Lambda.Serialization.Json package via Nuget, and referencing the previous version of the serializer referenced in the tutorials I was following, all worked perfectly.

Just wanted to chime in with what worked for me.
I have a ASP.NET Core 3.1 Web API service I'm hitting from Alexa and was getting this same error. I added a reference to NuGet package Microsoft.AspNetCore.Mvc.NewtonsoftJson and then popped this into my Startup.cs file: services.AddControllers().AddNewtonsoftJson(); in the ConfigureServices() function.
Source: https://dotnetcoretutorials.com/2019/12/19/using-newtonsoft-json-in-net-core-3-projects/
Also looks like this was sort of reported as an issue
https://github.com/timheuer/alexa-skills-dotnet/issues/193

Related

How to ignore ActionParameters in the Audit Trail data

I have implemented Audit Trail in asp.net core 3.1 application using great library which has a very good documentation also : https://github.com/thepirat000/Audit.NET/blob/master/src/Audit.WebApi/README.md
I have implemented it in a asp.net core 3.1 web api project with the recommended approach : Middleware + Action Filters (Asp.Net Core): Adding the Audit Middleware together with the Global Action Filter (or Local Action Filters).
I have the following sample output:
{
"EventType":"POST Values/Post",
"Environment":{
"UserName":"Federico",
"MachineName":"HP",
"DomainName":"HP",
"CallingMethodName":"WebApiTest.Controllers.ValuesController.Post()",
"AssemblyName":"WebApiTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null",
"Culture":"en-US"
},
"StartDate":"2017-03-09T18:03:05.5287603-06:00",
"EndDate":"2017-03-09T18:03:05.5307604-06:00",
"Duration":2,
"Action":{
"TraceId": "0HLFLQP4HGFAF_00000001",
"HttpMethod":"POST",
"ControllerName":"Values",
"ActionName":"Post",
"ActionParameters":{
"value":{
"Id":100,
"Text":"Test"
}
},
"FormVariables":{
},
"RequestUrl":"http://localhost:65080/api/values",
"IpAddress":"127.0.0.1",
"ResponseStatus":"OK",
"ResponseStatusCode":200,
"RequestBody":{
"Type":"application/json",
"Length":27,
"Value":"{ Id: 100, Text: \"Test\" }"
},
"ResponseBody":{
"Type":"SomeObject",
"Value":{
"Id":1795824380,
"Text":"Test"
}
},
"Headers": {
"Connection": "Keep-Alive",
"Accept": "text/html, application/xhtml+xml, image/jxr, */*",
"Accept-Encoding": "gzip, deflate",
"Accept-Language": "en-GB",
"Host": "localhost:37341",
"User-Agent": "Mozilla/5.0, (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0), like, Gecko"
}
}
}
From the above output I want ActionParameters not to be captured as part of the Audit trail data. I have gone through the documentation but did not see any out of the box solution for it.
Can anyone help me here with some code sample which will serve as a reference for my implementation
There are at least three ways to accomplish this.
You can avoid the parameters being captured in the event object by marking those with [AuditIgnore] Attribute in the action method.
[HttpPost]
public IEnumerable<string> PostAccount(string user, [AuditIgnore]string password)
{
// password argument will not be audited
}
Or you can remove the action parameters from the event object before saving the scope, by using a custom action:
// On your start-up code
using Audit.WebApi;
Audit.Core.Configuration.AddCustomAction(ActionType.OnEventSaving, scope =>
{
scope.GetWebApiAuditAction().ActionParameters = null;
});
Or, as ChatGPT suggested, you could implement your own AuditDataProvider, inheriting from the Data Provider you currently use, and removing the Action Parameters before calling the real provider's InsertEvent/ReplaceEvent methods. But this complicates things unnecessarily.
public class CustomAuditDataProvider : Audit.Core.Providers.FileDataProvider
{
public override object InsertEvent(AuditEvent auditEvent)
{
RemoveActionParams(auditEvent);
return base.InsertEvent(auditEvent);
}
public override Task<object> InsertEventAsync(AuditEvent auditEvent)
{
RemoveActionParams(auditEvent);
return base.InsertEventAsync(auditEvent);
}
public override void ReplaceEvent(object path, AuditEvent auditEvent)
{
RemoveActionParams(auditEvent);
base.ReplaceEvent(path, auditEvent);
}
public override Task ReplaceEventAsync(object path, AuditEvent auditEvent)
{
RemoveActionParams(auditEvent);
return base.ReplaceEventAsync(path, auditEvent);
}
private void RemoveActionParams(AuditEvent auditEvent)
{
auditEvent.GetWebApiAuditAction().ActionParameters = null;
}
}
// In your start-up code:
Audit.Core.Configuration.Setup().UseCustomProvider(new CustomAuditDataProvider());

Orleans 7.0 Serializer not working with POCOs originating from Nuget package

I have a Orleans 7.0 project with and I'm having an issue with the new default serializer.
The old serializer in Orleans 3.6.5 worked fine and it was serializing all the models and Dtos in the several internal Nuget packages.
Now in Orleans 7.0 the project does not recognize the models in the Nuget packages and I get this error:
Orleans.Serialization.CodecNotFoundException: Could not find a copier for type InternalProject.Model.
   at Orleans.Serialization.Serializers.CodecProvider.ThrowCopierNotFound(Type type) in /_/src/Orleans.Serialization/Serializers/CodecProvider.cs:line 666
   at Orleans.Serialization.Serializers.CodecProvider.GetDeepCopier[T]() in /_/src/Orleans.Serialization/Serializers/CodecProvider.cs:line 300
   at Orleans.Serialization.ServiceCollectionExtensions.CopierHolder`1.get_Value() in /_/src/Orleans.Serialization/Hosting/ServiceCollectionExtensions.cs:line 203
   at Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService[TService](Object caller, ICodecProvider codecProvider) in /_/src/Orleans.Serialization/GeneratedCodeHelpers/OrleansGeneratedCodeHelper.cs:lin
e 75
   at OrleansCodeGen.InternalProject.Model.Copier_SpecificModel..ctor(ICodecProvider codecProvider) in C:\Projects\InternalProject.Model\Orleans.CodeGenerator\Orleans.CodeGenerator.Orle
ansSerializationSourceGenerator\InternalProject.Model.orleans.g.cs:line 20736
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.ConstructorInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)
   at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.ConstructorMatcher.CreateInstance(IServiceProvider provider)
   at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.CreateInstance(IServiceProvider provider, Type instanceType, Object[] parameters)
   at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.GetServiceOrCreateInstance[T](IServiceProvider provider)
   at Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService[TService](Object caller, ICodecProvider codecProvider) in /_/src/Orleans.Serialization/GeneratedCodeHelpers/OrleansGeneratedCodeHelper.cs:lin
e 72
Now for the interesting part: when I copy paste the exact same class in my main project I no longer get this error, and the class serializes perfectly fine.
I tried referencing the Nuget project directly in the main project(ProjectReference), the result is the same.
I only get rid of errors in two scenarios:
when I use the Json Serializer with IgnoreCycles (undesirable in my scenario, doesn't get rid of the underlying problem)
siloBuilder.Services.AddSerializer(sb =>
{
sb.AddJsonSerializer(
isSupported: type => type.Namespace.StartsWith("Nuget.Namespace"),
new JsonSerializerOptions()
{
ReferenceHandler = ReferenceHandler.IgnoreCycles
}
);
});
when I add the classes directly in the main project. Example class from the error:
[GenerateSerializer]
public sealed class Class1: Class1Base
{
public Class1()
{
}
public Class1(IRequest request, bool boolean, InternalClass internalClass)
: base(request, boolean)
{
InternalClass = internalClass;
}
[Id(0)]
public InternalClass InternalClass{ get; set; }
}
[GenerateSerializer]
public class Class1Base
{
public Class1Base()
{
}
public Class1Base(IRequest request, bool boolean)
{
Request = request;
Boolean= boolean;
}
[Id(0)]
public IRequest Request { get; set; }
[Id(1)]
public bool Boolean{ get; set; }
}

Send byte array to server

I have an image object that I need to save on the server. I convert it into an array of bytes, and then serialize it into JSON with my optional data. But the server can not successfully convert it and it returns an error message to me:
{
"Message": "Cannot convert object of type 'System.String' to type 'System.Byte[]'",
"StackTrace": " at System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeInternal(Object o, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object& convertedObject) at System.Web.Script.Serialization.ObjectConverter.AssignToPropertyOrField(Object propertyValue, Object o, String memberName, JavaScriptSerializer serializer, Boolean throwOnError) at System.Web.Script.Serialization.ObjectConverter.ConvertDictionaryToObject(IDictionary`2 dictionary, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object& convertedObject) at System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeInternal(Object o, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object& convertedObject) at System.Web.Script.Services.WebServiceMethodData.StrongTypeParameters(IDictionary`2 rawParams) at System.Web.Script.Services.RestHandler.InvokeMethod(HttpContext context, WebServiceMethodData methodData, IDictionary`2 rawParams) at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)",
"ExceptionType": "System.InvalidOperationException"
}
My Json Data which i send:
{
"articleData": {
"ArticleNumber": "002",
"ArticlePhoto": "/9j/4QBwRXhpZgAATU0AKgAAAAgABIdpAAQAAAABAAAAPgESAAQAAAABAAAAAAEAAAQAAAABAAAC0AEBAAQAAAABAAAFAAAAAAAAA6ACAAMAAAABAWgAAKADAAMAAAABAoAAAJIIAAQAAAABAAAAAAAAAAD/4AAQSkZJRgABAQAAAQABAAD/2wBDABQODxIPDRQSEBIXFRQYHjIhHhwcHj0sLiQySUBMS0dARkVQWnNiUFVtVkVGZIhlbXd7gYKBTmCNl4x9lnN+gXz/2wBDARUXFx4aHjshITt8U0ZTfHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHz/wAARCAKAAWgDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwDjKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAoqWigCKipaKAIqKlooAioqWigCKipaKAIqKlooAioqWigCKipaKAIqKlooAioqWigCKipaKAIqKlooAioqWigCKipaKAIqKlooAioqWigCKipaKAIqKlooAioqWigCKipaKAIqKlooAioqWigCKipaKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKAND7HF/tfnS/Yov9r86npcVndjIBZQ/wC1+dKLGI/3vzqcVIBxRdgVfsEOP4vzo+wQ/wC1+dWiOKXFF2BT+wQ/7X50v2CH/a/OrYFLii7AqjToD/e/OnjTbfH8X51YWnr0ouwKy6Xbnrv/AO+q6KDwjpkkCORNllBPz/8A1qyVrs7T/jzi/wBwfyqkxGKvg/SyOk//AH3/APWpf+EO0v0n/wC/n/1q3V+7S5piMH/hDtL9J/8Av5/9amnwfpYHSfr/AM9P/rV0Hamsfl/EUAYQ8H6Wc/6/r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KKUCkApRQAtOFIAacBSGApw600Cnge9ADlpw60iilI4zQAtLQKAKAFooApcUAQlj5mKsIelV3xuzUsZ6VDGi0nSs+4/4/Y/8Aeq+n3az7j/j8T60LcaLlNpufc0cVZAtFBUGimBz+/wBqN/tTKKsQ/f7Ub/amUUAP3+1G/wBqZRQA/f7Ub/amUUAP3+1G/wBqZRQA/wAz2o8z2plFAD9/tR5h9KZRQA/zPajzPamUUAP3+1Hme1MooAk8z2FHm+1R0UWAlE5HYU77Sf7o/OoKKVgJvPJOdopRckfwioKKLAWPtR/uj86PtR/uj86r0UWAs/az/dH50C8YfwD86rUUWQFr7af7g/Ol+2t/cH51UoosgLYvm/uD86UX7D/lmPzqnRRZDuy8NRYf8sx+dL/aTYx5Y/OqFFFkFy9/aTf88x+dKNTb/nmPzqhRRZCND+1G/wCeS/nR/aj/APPMfnWfRRZAXTqDE/6sfnSrqTL/AMsx+dUaKOVDuaS6w6jHlL+dQyX7SSh9gBHvVOilyoLsvDUn/uD86P7Tf/nmPzqjRTshF8ao4/5Zj86KoUUWQBRRRTAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKAP//Z"
},
"sessionId": "d98b2c41-373a-40af-ac3b-874198e22a08"
}
My Request provider:
public class JsonProvider : IJsonProvider
{
private const string JsonContentType = "application/json";
public async Task<TResult> MakeApiCall<TResult,TData>(string url, HttpMethod method, TData data)
where TResult : class
{
using (var httpClient = new HttpClient())
{
using (var request = new HttpRequestMessage(method, url))
{
if (method != HttpMethod.Get)
{
var json = await Task.Run(() => JsonConvert.SerializeObject(data))
.ConfigureAwait(false);
request.Content = new StringContent(json, Encoding.UTF8, JsonContentType);
}
HttpResponseMessage response = await httpClient.SendAsync(request)
.ConfigureAwait(false);
var stringSerialized = await response.Content.ReadAsStringAsync()
.ConfigureAwait(false);
return await Task.Run(() => JsonConvert.DeserializeObject<TResult>(serialize))
.ConfigureAwait(false);
}
}
}
}
Request Objects:
public class SessionRequest
{
[JsonProperty("sessionId")] public string SessionId { get; set; }
}
public class UploadArticlePhotoRequest : SessionRequest
{
[JsonProperty("articleData")] public PhotoRequest ArticleData { get; set; }
}
public class PhotoRequest
{
[JsonProperty("ArticleNumber")] public string ArticleNumber { get; set; }
[JsonProperty("ArticlePhoto")] public byte[] ArticlePhoto { get; set; }
}
Can the problem in the format of conversion or encoding? Is it a client application or server problem?
Can the problem in the format of conversion or encoding? Is
Read the error message. It is clear. "Cannot convert object of type 'System.String' to type 'System.Byte[]'".
Is it a client application or server problem?
Well, obviously - gibven it is a .NET level error - the error happens on the server. Now, this may be bad data sent, but generally that would be seen as a server level error.
You basically made up a TData and it is not compatible with the data sent.
Happens - lack of reading details. That ALSO leads to horrific code like this:
return await Task.Run(() => JsonConvert.DeserializeObject(serialize))
.ConfigureAwait(false);
Just skip the Task.run and deserialize sync. See, there is no async method for that - with good reason - and you do not gain aynthign with Task.RUn, all you do is make sure 2 threads wait, not one. Antipattern from a lack of reading details and thinking things through. There is no way JsonConvert should be async to start (it is CPU bound, not IO bound) and you force the use of a separate task for it, while the original one waits.

NServiceBus System.ArgumentNullException

I'm new to NServiceBus (and a green developer) and I'm getting destroyed by this exception (in the NSB console, before calling the handler):
2014-02-26 14:27:10,269 [8] ERROR NServiceBus.Unicast.Transport.TransportReceiver [(null)] <(null)> -
Failed to deserialize message with ID: b0e459fa-0ada-431c-bbee-a2de00ee2a29
System.Runtime.Serialization.SerializationException: An error occurred while attempting to extract logical messages
from transport message NServiceBus.TransportMessage ---> System.ArgumentNullException: Value cannot be null.
Parameter name: path
at System.IO.Path.CheckInvalidPathChars(String path, Boolean checkAdditional)
at System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionA
ccess access, AccessControlActions control, String[] pathListOrig, Boolean check
ForDuplicates, Boolean needFullPath, Boolean copyPathList)
at System.IO.FileSystemInfo.set_Attributes(FileAttributes value)
at SetIsReadOnly(Object , Object )
at NServiceBus.Serializers.XML.XmlMessageSerializer.GetObjectOfTypeFromNode(T
ype t, XmlNode node) in c:\BuildAgent\work\31f8c64a6e8a2d7c\src\NServiceBus.Core
\Serializers\XML\XmlMessageSerializer.cs:line 492
at NServiceBus.Serializers.XML.XmlMessageSerializer.GetPropertyValue(Type typ
e, XmlNode n) in c:\BuildAgent\work\31f8c64a6e8a2d7c\src\NServiceBus.Core\Serial
izers\XML\XmlMessageSerializer.cs:line 828
at NServiceBus.Serializers.XML.XmlMessageSerializer.GetObjectOfTypeFromNode(T
ype t, XmlNode node) in c:\BuildAgent\work\31f8c64a6e8a2d7c\src\NServiceBus.Core
\Serializers\XML\XmlMessageSerializer.cs:line 487
at NServiceBus.Serializers.XML.XmlMessageSerializer.Process(XmlNode node, Obj
ect parent, Type nodeType) in c:\BuildAgent\work\31f8c64a6e8a2d7c\src\NServiceBu
s.Core\Serializers\XML\XmlMessageSerializer.cs:line 379
at NServiceBus.Serializers.XML.XmlMessageSerializer.Deserialize(Stream stream
, IList`1 messageTypesToDeserialize) in c:\BuildAgent\work\31f8c64a6e8a2d7c\src\
NServiceBus.Core\Serializers\XML\XmlMessageSerializer.cs:line 359
at NServiceBus.Unicast.Messages.ExtractLogicalMessagesBehavior.Extract(Transp
ortMessage physicalMessage) in c:\BuildAgent\work\31f8c64a6e8a2d7c\src\NServiceB
us.Core\Unicast\Messages\ExtractLogicalMessagesBehavior.cs:line 74
at NServiceBus.Unicast.Messages.ExtractLogicalMessagesBehavior.Invoke(Receive
PhysicalMessageContext context, Action next) in c:\BuildAgent\work\31f8c64a6e8a2
d7c\src\NServiceBus.Core\Unicast\Messages\ExtractLogicalMessagesBehavior.cs:line
52
--- End of inner exception stack trace ---
I got the MVC Example project working from the free chapters, but I couldn't get the pubsub example to work because 'Host doesn't support hosting of multiple endpoints.'
I'm working in 3 projects in my broken solution, just trying to get a simple 1-node pub and 1-node sub going:
Core (NServiceBus.Interfaces 4.4.1 from NuGet, contains Events folder with IFileUploadedEvent.cs)
FileWatcherService (NServiceBus.Host 4.4.1 from NuGet)
FileMoverService (NServiceBus.Host 4.4.1 from NuGet)
Core\Events\IFileUploadedEvent.cs:
using NServiceBus;
using ...
namespace Core.Events
{ public interface IFileUploadedEvent : IEvent
{ Guid EventId { get; set; }
string Client { get; set; }
FileInfo FileName { get; set; }
}
}
FileWatcherService has default app.config, no mappings.
FileWatcherService.EndpointConfig.cs:
namespace FileWatcherService
{ using NServiceBus;
public class EndpointConfig : IConfigureThisEndpoint, AsA_Publisher {}
}
FileWatcherService.FileWatcher.cs:
using NServiceBus;
using Core.Events;
using ...
namespace FileWatcherService
{ public class FileWatcher : IWantToRunWhenBusStartsAndStops
{ public IBus Bus { get; set; }
public void Activate()
{ ... }
...Stalker, calls PublishFileUploaded
public void PublishFileUploaded(FileInfo fileName, string clientName)
{ Bus.Publish<IFileUploadedEvent>(evt =>
{ evt.EventId = Guid.NewGuid();
evt.Client = clientName;
evt.FileName = fileName;
});
} } }
the FileMoverService.App.config contains:
<UnicastBusConfig>
<MessageEndpointMappings>
<add Messages="Core" Endpoint="FileWatcherService" />
</MessageEndpointMappings>
</UnicastBusConfig>
In the NSB windows, I see
FileMover: Subscribing to Core.Events.IFileUploadedEvent
FileWatcher: Subscribing FileMoverService#ccc to message type Core.Events.IFileUploadedEvent
The FileMover class implements IHandleMessages, but the code never reaches that because NServiceBus throws the first error.
I tried running Init() in the EndpointConfig, but I still get the same error.
Help me Please! What am I doing wrong?
If you want to move files or other blobs using NServiceBus, look at using our "data bus" capabilities described here:
http://docs.particular.net/NServiceBus/attachments-databus-sample
Turns out you can't Deserialize a FileInfo object. So I'll have to approach the problem completely differently.

MVC4 and ServiceStack session in Redis

I have a brand new MVC4 project on which I have installed the ServiceStack MVC starter pack (version 4.0.12 from MyGET) to bootstrap the usage of the service stack sessions.
In my AppHost my custom session is configured as:
Plugins.Add(new AuthFeature(() => new CustomUserSession(),
new IAuthProvider[] {
new CredentialsAuthProvider(config)
}));
The custom session looks like this for testing purposes:
public class CustomUserSession : AuthUserSession
{
public string Hello { get; set; }
}
And the ICacheClient is registered as a redis client:
// register the message queue stuff
var redisClients = config.Get("redis-servers", "redis.local:6379").Split(',');
var redisFactory = new PooledRedisClientManager(redisClients);
var mqHost = new RedisMqServer(redisFactory, retryCount: 2);
container.Register<IRedisClientsManager>(redisFactory); // req. to l
container.Register<IMessageFactory>(mqHost.MessageFactory);
container.Register<ICacheClient>(c =>
(ICacheClient)c.Resolve<IRedisClientsManager>()
.GetCacheClient())
.ReusedWithin(Funq.ReuseScope.None);
I have then created a ControllerBase which for simplicity loads and saves the custom session for each request:
public abstract class ControllerBase : ServiceStackController<CustomUserSession>
{
protected override IAsyncResult BeginExecute (System.Web.Routing.RequestContext requestContext, AsyncCallback callback, object state)
{
ViewBag.Session = this.UserSession;
return base.BeginExecute (requestContext, callback, state);
}
protected override void EndExecute(IAsyncResult asyncResult)
{
SaveSession(null);
base.EndExecute(asyncResult);
}
public void SaveSession(TimeSpan? expiresIn = null)
{
Cache.CacheSet(SessionFeature.GetSessionId(), UserSession, expiresIn ?? new TimeSpan(0, 30, 0));
}
}
I then modify the Hello property to read "World" in one of my actions, and I can clearly see with a breakpoint on the SaveSession method that the value has been properly. However, upon loading the page again and inspecting the loaded session, there's nothing set. Also, looking in the Redis database, the following blob is saved:
{
"createdAt": "/Date(-62135596800000-0000)/",
"lastModified": "/Date(-62135596800000-0000)/",
"providerOAuthAccess": [],
"isAuthenticated": true,
"tag": 0
}
It's not saving my custom property. Can anyone tell me what I'm doing wrong / missing?
=== UPDATE ===
If I change any of the properties from the base AuthUserSession the changes to those properties are persisted - so it would seem that SS somehow decides to disregard the properties from my concrete type.
Because AuthUserSession is a DataContract and attributes are now inherited in v4, you also need to mark each member with [DataMember], e.g:
public class CustomUserSession : AuthUserSession
{
[DataMember]
public string Hello { get; set; }
}

Categories