If I can invoke the api Car Availability with a locationDescription.name that have more than three letters the api send me the following errors:
"18|Presentation|Serializing/Deserializing error: [type = DataElement]
[name = name] [Error = Invalid length for data element]."
Could you help, please?
Thanks
Seems like your class does not have public default constructor.
Refer : https://support.microsoft.com/en-in/help/330592/error-message-when-you-serialize-a-class-by-using-the-xmlserializer-cl
When you try to use the XmlSerializer class to serialize a class that
does not have a public default constructor, you may receive the
following System.InvalidOperationException exception error message: An
unhandled exception of type 'System.InvalidOperationException'
occurred in system.xml.dll Additional information: There was an error
reflecting 'class'. where class indicates the class that the
XmlSerializer class tried to serialize.
Related
Working on a semester-long project from a code-based that was inherited from last semester's students. Trying to add a simple method that updates a boolean field isPaid on an application class. When I call context.SaveChanges() I get the error:
SqlException: Conversion failed when converting the nvarchar value '2ab5dcc9-f6f8-464c-aa35-1832d6ed8018' to data type int.
In the code below I am passing in the ApplicationId updating the IsPaid variable. However, I'm receiving an error on the StudentId. The context.SaveChanges() method is called in other parts of the program with no such error. Could not be more confused any help would be much appreciated
Here is a picture of the debug window https://ibb.co/6WZGmMX
public void Paid(int id)
{
Application app = DbContext.Application.FirstOrDefault(a => a.ApplicationId == id);
app.IsPaid = true;
DbContext.Application.Update(app);
DbContext.SaveChanges();
}
Error message I am receiving:
An unhandled exception occurred while processing the request.
SqlException: Conversion failed when converting the nvarchar value '2ab5dcc9-f6f8-464c-aa35-1832d6ed8018' to data type int.
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, bool breakConnection, Action<Action> wrapCloseInAction)
DbUpdateException: An error occurred while updating the entries. See the inner exception for details.
Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.Execute(IRelationalConnection connection)
Could you try changing your Paid method parameter to a GUID instead of integer ID?
public void Paid(Guid id)
Based on your error message, the method is passing in a Guid as an int, so that's why the error is being thrown.
If this does not work, try checking the contents of app.Id to see what that value is.
The issue is not with context.SaveChanges() itself, it is an issue with the specific data being saved in this particular method.
The project is a copy of Unity doc but it raise an error that I cant underestand
The error is:
Unhandled Exception:
Unity.Exceptions.ResolutionFailedException: Resolution of the
dependency failed, type = 'System.Object', name = 'MainPage'.
Exception occurred while: Calling constructor
SecondPrims.Views.MainPage(). Exception is: ResolutionFailedException
- Resolution of the dependency failed, type = 'SecondPrims.ViewModels.MainPageViewModel', name = '(none)'. Exception
occurred while: while resolving. Exception is:
InvalidOperationException - The current type, ITextToSpeech, is an
interface and cannot be constructed. Are you missing a type mapping?
----------------------------------------------- At the time of the exception, the container was: Resolving
SecondPrims.ViewModels.MainPageViewModel,(none) Resolving parameter
'textToSpeech' of constructor
SecondPrims.ViewModels.MainPageViewModel(ITextToSpeech textToSpeech)
Resolving ITextToSpeech,(none)
----------------------------------------------- At the time of the exception, the container was: Resolving
SecondPrims.Views.MainPage,MainPage (mapped from System.Object,
MainPage)
Resolving SecondPrims.Views.MainPage,MainPage
Calling constructor SecondPrims.Views.MainPage() occurred
Project file:
http://www.mediafire.com/file/fs656jowkiy2bd9/SecondPrims.zip
The answer is because of registering the ITextToSpeech Interface in each platform.
https://stackoverflow.com/a/50493741/478162
Prism 7 changed this behavior as it is actually an anti-pattern to
rely on a secondary container. You simply need to register your
TextToSpeech service in the IPlatformInitializer like:
public class iOSInitializer : IPlatformInitializer
{
public void RegisterTypes(IContainerRegistry containerRegistry)
{
containerRegistry.Register<ITextToSpeech, TextToSpeech_iOS>();
}
}
Are you adding your dependencies correctly ?
containerRegistry.RegisterForNavigation<MainPage>();
containerRegistry.Register<ITextToSpeech, TextToSpeech>();
I have an asp.net WebAPI app. I'm returning files to the client in the Request.CreateResponse(,) second parameter as type Dictionary<string, List<System.Net.Http.StreamContent>>, where List<System.Net.Http.StreamContent>> contains all the files.
I'm deserializing the files at the client using the following:
var someContent = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, List<System.Net.Http.StreamContent>>>(result.Content.ReadAsStringAsync().Result);
This code throws the exception:
An unhandled exception of type
'Newtonsoft.Json.JsonSerializationException' occurred in
Newstonsoft.Json.dll.
Additional information: Unable to find a construction to use for type
System.Net.Http.StreamContent. A class should either have default
constructor, one constructor with arguments or a constructor marked
with the JsonConstructor attribute. Path 'myFiles[0].Headers'
Is there a different way to return actual files?
I'm building an asp.Net MVC application with Code First EntityFramework. I'm using Dependency Injection with Unity Container.
I have a context class like this
public partial class MyContext : DbContext
{
public MyContext()
: base("name=MyConnString")
{
Database.SetInitializer<MyContext>(null);
}
}
A Repository class like this:
public class Repository
{
public Repository(DbContext dataContext)
{
}
}
In Bootstrapper class I have this:
container.RegisterType<DbContext, MyContext>("DbContext",new HierarchicalLifetimeManager());
When I run the application, it throw this Exception:
The current type, System.Data.Common.DbConnection, is an abstract class > and cannot be constructed. Are you missing a type mapping?
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: The current type, System.Data.Common.DbConnection, is an abstract class and cannot be constructed. Are you missing a type mapping?
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
The current type, System.Data.Common.DbConnection, is an abstract class and cannot be constructed. Are you missing a type mapping?
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: The current type, System.Data.Common.DbConnection, is an abstract class and cannot be constructed. Are you missing a type mapping?
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
After research I found that this error is because Unity uses the most verbose constructor by default.
I need use the second constructor, but I don't know how configure Unity
Have you any idea?
You're looking for InjectionConstructor:
public partial class MyContext : DbContext
{
[InjectionConstructor]
public MyContext()
: base("name=MyConnString")
{
Database.SetInitializer<MyContext>(null);
}
}
You may also find this useful reading: https://msdn.microsoft.com/en-us/library/ff650802.aspx
I have run into a bit of a problem, well not sure if it is a problem, but would like some advice.
I have developed a c# webservice in vs2010 and when I debug the service i get this error in my browser
The XML element 'VoucherResponse' from namespace 'http://test.org/' references a method and a type. Change the method's message name using WebMethodAttribute or change the type's root element using the XmlRootAttribute.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: The XML element 'VoucherResponse' from namespace 'test.org' references a method and a type. Change the method's message name using WebMethodAttribute or change the type's root element using the XmlRootAttribute.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Now looking at my code in at the actual class "VoucherResponse" i have,
public class VoucherResponse : AResponse
{
public Voucher Voucher { get; set; }
}
And the Voucher object looks like this
public class Voucher
{
public string PIN { get; set; }
public string Serial { get; set; }
public string Batch { get; set; }
}
Now in one of my web methods I return the VoucherResponse and I am assuming that this error occurs when it is reflected through and checked.
Has anyone had a similar problem with this before, or can anyone give me some advice on this?
Thanks
I found another case that raises the error! Here's my code:
[WebMethod]
public CheckUpdateResponse CheckUpdate()
{
...
}
Ok, let me explain: CheckUpdateResponse is a structure I defined in my code, CheckUpdate() is a method. So, in the WSDL .NET add automatically a Response suffix to the method name CheckUpdate.
Et voilĂ : it finds a duplicate element and gives the error "Change the method's message name using WebMethodAttribute..."
Solution? I renamed the returned type from CheckUpdateResponse to CheckUpdateResult and now everything works fine!
I hope this will help someone! I lost a lot of time on this...
Apparently, SOAP cannot handle methods that have the same name as their return type.
You can fix it by reading the error, and acting accordingly:
public class VoucherResponse
{
[WebMethod(MessageName="TheVoucher")]
public Voucher Voucher{get; set;}
}
I had the same issue, but in my case; the application that I developed is web service client, so I don't have control on changing the WSDL\Schema.
The problem was that I had one web service with 17 operations, all of them are returning the same complex type, I got the mentioned error due to deserialization of the return type, because .Net is wrapping the return type for each output, and the serializer is throwing error:
The XML element 'XYZ' from namespace 'ABC' references a method and a type. Change the method's message name using WebMethodAttribute or change the type's root element using the XmlRootAttribute.
Solution:
I opened Reference.cs file, removed all wappered return type generated classes, and kept only one, then changed its class name to be generic, not related to the operation, it worked for me.