I am currently using NServiceBus6. I am successfully submitting a message from my web api to endpoint which is windows service hosted. Everything works fine in my development environment on my local machine. I am using "NewtonsoftSerializer" in all my endpoint configurations. I have now deployed my solution to a server. My services are now hosted as Window Services as opposed to a console app. Service Insight is now reporting an NServiceBusDeserialization Exception:
An error occurred while attempting to extract logical messages from transport message 8221d498-81ca-406e-8ab6-a77701065f1f ---> System.Xml.XmlException: Data at the root level is invalid. Line 1, position 1.
A couple items stick out. A. I am not using XmlSerialization. B. I have no serialization issues in development environment. I would appreciate any help provided thank you.
Message Class:
public class CreateSearchRequest : ICommand
{
public SearchRequest Request { get; set; }
}
SearchRequest:
public class SearchRequest : Resource
{
public string User { get; set; }
public string SearchName { get; set; }
public SearchCriteriaSimple Criteria { get; set; }
public string Status { get; set; }
public DateTime RequestBegin { get; set; }
public DateTime RequestEnd { get; set; }
public int Records { get; set; }
public string OutputFileName { get; set; }
public string FtpLocation { get; set; }
public DateTime CreateDate { get; set; }
}
SearchRequestSimple:
public class SearchCriteriaSimple
{
public string Name { get; set; }
public List<Dictionary<string, string>> Criteria { get; set; }
}
Resource: Azure DocumentDbResource class
I am embarrassed to say. But I have figured out the issue. During development in Visual studio I configured the endpoint in the Task AsyncOnStart() method of ProgramService.cs. It seems once I install the NServiceBus host I must also provide configuration via Endpoint Config. Once I matched serialization there the issues went away.
Related
I just upgraded my .net 4.8 MVC web app to .net6.
I used Sessions to store objects.
for example the User class:
public class User
{
[Key]
public string UserID { get; set; }
public string TenantId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string MobilePhone { get; set; }
public bool IsEnabled { get; set; }
public virtual ICollection<Department> Departments { get; set; }
}
This is how I set the session:
Session[Consts.CURRENTUSER] = userFromDb;
This is how I use it:
User _currentUser = Session[Consts.CURRENTUSER] as User;
Now, after the upgrade it does not compile. I get the following error:
Error CS0103 The name 'Session' does not exist in the current context
If i use the following HttpContext.Session[Consts.CURRENTUSER] as User it still does not allow the the above use.
Will appreciate an example on how I will be able to use the above scenario in .net core.
after reading Microsoft docs, I followed this guide from step 4 to allow the usage of Sessions.
Then, in order to use complex objects in .net core I followed this link which provided an extension method that implementing the use of complex objects in sessions.
I'm developing a web api with .NET Core
I use Swagger for API documentation
For an endpoint i have a return object like this
public class TaxonomyNode
{
public int Id { get; set; }
public string Key { get; set; }
public string Title { get; set; }
public string ParentKey { get; set; }
public bool HasAssociations { get; set; }
public int Level { get; set; }
public IEnumerable<TaxonomyNode> Children { get; set; }
}
When i launch my web application on swagger page and expland my API endpoint swagger give me this error
Resolver error at paths./api/Taxonomies/{idTaxonomyItemDbMaster}/GetNodes.get.responses.200.content.application/json.schema.properties.children.items.$ref
Could not resolve reference:
Resolver error at paths./api/Taxonomies/{idTaxonomyItemDbMaster}/GetNodes.get.responses.200.content.text/json.schema.properties.children.items.$ref
Could not resolve reference:
Resolver error at paths./api/Taxonomies/{idTaxonomyItemDbMaster}/GetNodes.get.responses.200.content.text/plain.schema.properties.children.items.$ref
Could not resolve reference:
the problem is
public IEnumerable Children { get; set; }
i think that swagger go into an overflow when generating documentation for response
How can i prevent this?
thanks
Your model of type TaxonomyNode is refering to the type TaxonomyNode as a property.
Therefore it will cause a infinite loop if you wish to serialize this type.
It is the cause of the error you are getting
Could someone explain why this is happening, I have a C# backend that I'm connecting to via WCF. In the back end, i have two classes in the same namespace that have two properties that have the same name. These classes are used in a separate object. The types of the properties are different, one is a string and one is an object but there seems to be some sort of collision when deserializing the object?
It's returning this random error when I call to return the object.
This could be due to the service endpoint binding not using the HTTP
protocol. This could also be due to an HTTP request context being aborted by
the server (possibly due to the service shutting down). See server logs for
more details.
Here are the classes, the property causing the problem is BCIssued
public class Activities
{
public string ApplicationReceived { get; set; }
public string PIMGranted { get; set; }
public Bcgranted[] BCGranted { get; set; }
public object CCCGranted { get; set; }
// public object BCIssued { get; set; }
public object CCCIssued { get; set; }
}
public class CCC
{
public string BCIssued { get; set; }
public string FinalIns { get; set; }
public string LapsedMonths { get; set; }
public object WorkStarted { get; set; }
public object Notified { get; set; }
public object Lapsed { get; set; }
public object Extension { get; set; }
}
Thanks to Rene's post about WCF logging, i was able to turn on logging and found the error on the server side
Type 'Newtonsoft.Json.Linq.JToken' is a recursive collection data contract
which is not supported. Consider modifying the definition of collection
'Newtonsoft.Json.Linq.JToken' to remove references to itself.
I have a stateless service that loads and returns an array of entity objects (POCO using EF). Lazy loading and proxy creation is disabled.
Everything is works just fine as long as I only return a single level graph:
var devices = context.Devices.Where(d => d.ParentHost_Id == hostId);
return Task.FromResult(devices.ToArray());
However, if I want to include another level, things go south in bad way:
var devices = context.Devices.Where(d => d.ParentHost_Id == hostId).Include(d => d.ConnectedDevices);
return Task.FromResult(devices.ToArray());
In this case, my code will load and return the requested objects without any trouble, but somewhere upstream in the call chain Service Fabric throws a COMException which it then handles by calling my service again. This results in a new COMExcetion, and it keeps doing this until I stop it.
{System.Runtime.InteropServices.COMException (0x80071C4C): Undantag från HRESULT: 0x80071C4C
vid Microsoft.ServiceFabric.Services.Communication.FabricTransport.Common.NativeServiceCommunication.IFabricServiceCommunicationClient.EndRequest(IFabricAsyncOperationContext context)
vid Microsoft.ServiceFabric.Services.Communication.FabricTransport.Client.NativeServiceCommunicationClient.EndRequest(IFabricAsyncOperationContext context)}
The Devices class is generated by EF and looks like this:
public partial class Devices
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public Devices()
{
this.LogValues = new HashSet<LogValues>();
}
public long Id { get; set; }
public int DeviceId { get; set; }
public int Type { get; set; }
public string Property { get; set; }
public string Name { get; set; }
public Nullable<long> ParentHost_Id { get; set; }
public virtual Hosts Hosts { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<LogValues> LogValues { get; set; }
public virtual ConnectedDevices ConnectedDevices { get; set; }
}
Any ideas on why this happens would be appreciated!
Apparently, the problem was that my object graph contained a circular reference (the ConnectedDevice had a reference to Device). I removed it from the EF model and everything is now working as expected.
My project is web apllication on ASP.NET MVC 6
and basicaly I have a realy weird problem.
This is the code:
await Dashboards.UpdateReward(dashboard);
await Lessons.Update(lesson);
methods don't do anything specific but save modified states to database.
Here is what the problem is. When I start application normally and run through this part of the code it throws error:
Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.
But here is the tricky part when I debug it and go step by step it works just fine without any error.
You may want to take a look at this to find more information about your exception:
Validation failed for one or more entities. See 'EntityValidationErrors' property for more details
Thank you for your help. It would seem that the problem was in dashboard model. Lazzy loading didnt load my User property and since it is foreign key it can not be null value.
[Key, ForeignKey("User")]
public string UserId { get; set; }
//Gemification
public int Level { get; set; }
public int Experience { get; set; }
public int Yens { get; set; }
//Application
[Column(TypeName = "datetime2")]
public DateTime Created { get; set; }
[Column(TypeName = "datetime2")]
public DateTime Updated { get; set; }
public string CreatedBy { get; set; }
public string UpdatedBy { get; set; }
public virtual ICollection<Lesson> Lessons { get; set; }
public virtual ICollection<OwnedGroup> OwnedGroups { get; set; }
[Required]
public virtual ApplicationUser User { get; set; }
Any way thank you for your help.