.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
MarieAdela
Imran Ghani
Post New Web Links

XMLSerializer Problem on typcasting a deserialized object

Posted By:      Posted Date: October 13, 2010    Points: 0   Category :.NET Framework
 

Hi,

I have little understanding problem with XMLSerialiyer.

It seams to be the way, that a serialized object can not be deserialized again if serialization and deserialization are called fromassemblies which are identical, but physically located on different paths. The following code shows the deserialization:

using (FileStream fs = new FileStream(settingsPath, FileMode.Open))
{
    XmlSerializer serializer = new XmlSerializer(typeof(MySettings));
    object o = serializer.Deserialize(fs);
    instance = o as MySettings;
}

The strange part is, that the object o shows all the properties of the MySettings class (in the debugger), but when I try to assign "o as MySettings" to instance instance stays null . So actually the deserialization seems to work, but the typcasting not.

Every thing works fine as long as it is the same application that created the xml file deserializes it. But in my case, where I wrote a test, using the same assemblys (partially loaded at runtime) then the application later on will show the described faulty behaviour.

What could be the cause to my problem?

Regards
Rainer

 




View Complete Post


More Related Resource Links

XMLSerializer Problem on typcasting a deserialized object

  

Hi,

I have little understanding problem with XMLSerialiyer.

It seams to be the way, that a serialized object can not be deserialized again if serialization and deserialization are called fromassemblies which are identical, but physically located on different paths. The following code shows the deserialization:

using (FileStream fs = new FileStream(settingsPath, FileMode.Open))
{
    XmlSerializer serializer = new XmlSerializer(typeof(MySettings));
    object o = serializer.Deserialize(fs);
    instance = o as MySettings;
}

The strange part is, that the object o shows all the properties of the MySettings class (in the debugger), but when I try to assign "o as MySettings" to instance instance stays null . So actually the deserialization seems to work, but the typcasting not.

Every thing works fine as long as it is the same application that created the xml file deserializes it. But in my case, where I wrote a test, using the same assemblys (partially loaded at runtime) then the application later on will show the described faulty behaviour.

What could be the cause to my problem?

Regards
Rainer

 


passing object values from server to client problem

  

I get a message that x_login is not declared.  I added Dim login as String = "123", but that didn't help.  What's the problem?

code behind....

Dim Login = "123"
x_login.Value = loginID


asp....

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<body>
   
<form id="simForm" runat="server" method='post' action='https://test.authorize.net/gateway/transact.dll'>
        <input id="HiddenValue" type="hidden" value="Initial Value" runat="server" />
        <input type='hidden' runat="server" name='x_login' id='x_login' />
        <input type='submit' runat="server" id='buttonLabel' />
 </form>

</body>
</html>


 


Problem passing custom object returned by the same webservice among two separate projects

  
I am running into casting issue with this scenario: 1. I made a custom object lets call it EmployeeObject.  2. The Employee object is wrapped in the EmployeeWebservice.  3. I have a client application project lets call it EmployeeClientApplication and a class library called DoSomeWorkClassLibrary.  Both EmployeeClientApplication and DoSomeWorkClassLibrary reference the EmployeeWebService and need to be able to pass the EmployeeObject back and forth.  4. The EmployeeClientApplication also references the DoSomeWorkClassLibrary. 5. The employeeObject in the EmployeeClientApplication becomes EmployeeClientApplication.EmployeeWebService.EmployeeObject. 6. The employeeObject in the DoSomeWorkClassLibrary becomes DoSomeWorkClassLibrary.EmployeeWebService.EmployeeObject. 7. The DoSomeWorkClassLibrary has a method called DoSomeWork that takes an EmployeeObject. When I try to pass employeeObject from EmployeeClientApplication to DoSomeWorkClassLibrary by doing something like this: DoSomeWorkClassLibrary.DoSomeWork(EmployeeClientApplication.EmployeeWebService.EmployeeObject), I am getting Unable to convert EmployeeClientApplication.EmployeeWebService.EmployeeObject to DoSomeWorkClassLibrary.EmployeeWebService.EmployeeObject.  I have searched high and low to fix this issue, I have tried changing the namespace of the reference.cs file of the webservice in

Symbol.Keyboard.KeyPad() object creation problem

  
on windows mobile 6.5 application running on Windows mobile 6 professional VGA emulator. I am trying to work on keyboard functionality like function key press events. I have coded the below line.   Symbol.Keyboard.KeyPad keypad = new Symbol.Keyboard.KeyPad();   keypad.KeyStateNotify +=new Symbol.Keyboard.KeyPad.KeyboardEventHandler(keypad_KeyStateNotify); keypad.AlphaNotify +=new Symbol.Keyboard.KeyPad.KeyboardEventHandler(keypad_AlphaNotify);   Its build successfully but raising exception at runtime. please help me out to run this code on emulator. because i don't have device.

Problem with listing records from table (object not found)

  
Hi everyone, I'm creating a website based on ASP.NET MVC 2 and SQL Server 2008 R2 Express for the database. After creating the table in database, I want to list all records in that table. For that, I use "scaffold'ing in ASP.NET to automatically generate the view file. But I encountered an error when loading that page. The error message was: [CODE] Server Error in '/' Application. Invalid object name 'dbo.Accommodations'. 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.Data.SqlClient.SqlException: Invalid object name 'dbo.Accommodations'. Source Error: Line 41:         </tr> Line 42: Line 43:     <% foreach (var item in Model) { %> Line 44: Line 45:         <tr> Source File: d:\MyProject\Views\Accommodation\Index.aspx    Line: 43 Stack Trace: [SqlException (0x80131904): Invalid object name 'dbo.Accommodations'.]    System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +2030802    System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +5009584 &n

Solution Deployment Problem (Administrative Framework Object Dependencies)

  
I'm having a problem with the deployment of a SharePoint workflow solution - hopefully someone can help me out.Here is the sequence of STSADM commands and their output from the console:C:\Workflows>stsadm -o deactivatefeature -name IL.SharePoint.Workflows -url http://localhost/ -forceOperation completed successfully.C:\Workflows>stsadm -o uninstallfeature -name IL.SharePoint.Workflows -forceOperation completed successfully.C:\Workflows>stsadm -o retractsolution -name IL.SharePoint.Workflows.wsp -localDeploymentSucceeded : server : The solution was successfully deployed.il.sharepoint.workflows.wsp: Operation completed with errors.C:\Workflows>stsadm -o deletesolution -name IL.SharePoint.Workflows.wspOperation completed successfully.C:\Workflows>stsadm -o addsolution -filename IL.SharePoint.Workflows.wspAn object in the SharePoint administrative framework, "SPSolutionLanguagePack Name=0 Parent=SPSolution Name=il.sharepoint.workflows.wsp", depends on other objects which do not exist.  Ensure that all of the objects dependencies are created and retry this operation.IL.SharePoint.Workflows.wsp: The Solution installation failed.Here is the related log info from the SharePoint logs:error-redacted.txtAs far as I can see, SP is attempting to insert a "SPSolutionLanguagePack" object into the configuration database, with an invalid foreign key reference

.NET Remoting Problem with Sponsor Renewal on CAO (Client Activated Object) Architecture

  
I have figured out a strange behaviour when using Client Activated Sponsorship and hope to get a hint from somebody who already got in touch with similar problems. The case is as follows: An Application is used by a server and a client. Both use (or try to use) the same objects after a user login. A lease of a session object on the server (serverSession) is initialised correctly with all of its regular remoting values in the lease for InitialLeaseTime (10) SponsorshipTimeout (5) RenewOnCallTime (10) In order to test the behaviour the values are set to seconds. It is easier to check the log every few seconds, than to wait some minutes until the Sponsorship Renewal call. If a client performs a login, the lease is according to its logged in state renewed each 10 seconds (or whatever the value is set to). So no problem so far. The lease will be alive as long as the client performs a logout, by the way it is used on a local network. Just compare the log (the renewal is firing every 10 seconds as expected): 2010-02-17 10:29:40.4338 Info Log5 SponsorObject:Renewal() 2010-02-17 10:29:50.4308 Info Log5 SponsorObject:Renewal() 2010-02-17 10:30:00.4328 Info Log5 SponsorObject:Renewal() 2010-02-17 10:30:10.4298 Info Log5 SponsorObject:Renewal() 2010-02-17 10:30:20.4318 Info Log5 SponsorObject:Renewal() 2010-02-17 10:30:30.4288 Info Log5 SponsorObject:Renewal() As soon as

Unable to cast object of type problem

  
hi I'm having a problem in this code: Public Function GetChannelList() As List(Of channel) Implements IChannelService.GetChannelList         Dim db As ChannelDataContext = New ChannelDataContext         Dim channelMatch = From channelRow In db.channels _                           Join parentChild In db.ChannelParentChildListings _                           On channelRow.channel_id Equals parentChild.parent_id _                           Order By channelRow.title Ascending _                           Select channelRow.channel_id, channelRow.title, parentChild.child,   parentChild.child_id           Return channelMatch    <-------- Error throw Unable to cast object of type 'System.Data.Linq.DataQuery`1[VB$AnonymousType_1`4[S

ListBox object Binding Problem...?

  

hii guy's

i created a ListBox and i added Engine Class object into it...so i wana display Engine Class property "Name" into ListBox..so plz tell me how can i add property name of "Name" to ListBox of Class "Engine"

Thanks,

@nagaraju

 

 


Problem with xmlns when I convert object to XML and XML to object back

  

Hi, I am facing a strange problem.

I have a class object which I am accessing through webservice call.

Now actually that class has a property with type of Array inside that class and that array is the array of same class object. Means in reality, I have detailed tree structure as per how data gets fill up in that class object.

This is how my XML is and my actual code.

string xml_For_Obj = "";

                xml_For_Obj = "<xml version=\"1.0\" encoding=\"utf-16\">  ";
                xml_For_Obj += "    <ComponentObject xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">";
                xml_For_Obj += "        <BundledComponents xmlns=\"http://MySite.com/ISI/OtherWebService/Components\">";
                xml_For_Obj += "            <ComponentObject>";
                xml_For_Obj += "                <SKU>Test Sku Name</SKU> ";
                xml_For_Obj += "                <SubGroup>Test SubGroup</SubGroup> ";
                xml_For_Obj += "                <Quantity>70</Quantity> ";
                xml_For_Obj += "                    <BundledComponents >";
  

ListBox Object Binding Problem..??

  

hii guy's here i'm having small problem on Object DataBinding using ListBox.. i've a WCF class like..


[System.Runtime.Serialization.DataContract]    
	public class EngineInstanceStatus 
	{
             public string Name
		{
			get
			{
				return m_name;
			}
		}
       }

so i wana add dis class object to my ListBox.. den it'll display its property name "Name" in ListBox whenever i added this class object ot ListBox..


so plz tell me with sample how can i do this one..


Thanks,

@nagaraju


Problem in binding List<> object to Gridview

  

Dears,

We I bind a list<> object to a gridview it calls an error like this:

Error: DataBinding: 'Default2+JobsList' does not contain a property with the name 'JobId'

Hear is my markup Codes:

<asp:GridView ID="GridView1" runat="server" DataKeyNames="JobId" AutoGenerateColumns="False"
                            OnRowCommand="GridView1_RowCommand">
                            <Columns>
                                <asp:BoundField DataField="JobName" .../>
                                <asp:BoundField DataField="JobExplain" .../>
                                <asp:ButtonField CommandName="DeleteJob" .../>
                            </Columns>
</asp:GridView>


and Code behind:

public struct JobsList
    {
        public int JobId;
        public string JobName, JobExplain;
        public JobsList(int id, string name, string explain)
        {
            JobId = id;
            JobName = name;
            JobExplain = explain;
        }
    }

List<JobsList> list = new List<JobsList>();

....

list.Add(new JobsList(Approperiate Attributes..));
GridView1.DataSource = list;
GridView1.Data

WPF problem binding to an object

  

Hi: I'm having a problem binding to an object I create. I'm a newbie to WPF.  Here's my Visual Basic code, followed by my XAML.  The code runs with no errors, but nothing appears in the Label1, when I expected to see the FirstName "Shirley".  What am I doing wrong?  Thanks,  Al

Imports System.Windows

Class MainWindow
  Public Class Person
    Public FirstName As String

    Public Sub New(ByVal fName As String)
      FirstName = fName
    End Sub
  End Class

  Private Sub Window_Loaded(ByVal sender As System.Object, ByVal e As Syste

Problem in passing Json collection object from View to Action

  

Hi,

I am trying to send json data from view to controller action.  But the issue is the data is not populating in the action parameter List<Score>.

View Model:
public class Score
{
   public int QuestionId { get; set; }
   public int PrevAnswerId { get; set; }
   public int CurrAnswerId { get; set; }
   public string CurrAnswerName { get; set; }
}


Json Data look like:
[
{QuestionId:1, PrevAnswerId:3,  CurrAnswerId:3,  CurrAnswerName:'Known to Broker'},
{QuestionId:2, PrevAnswerId:7,  CurrAnswerId:7,  CurrAnswerName:'Completed'},
{QuestionId:3, PrevAnswerId:10, CurrAnswerId:10, CurrAnswerName:'Report'}
]

On window load,  I will construct the Json object using "eval()" function and do some operation in the data before its save.

On Save Click, I will call the action through the ajax call.
$.ajax({
        url: url,
        type: "GET",
        dataType: 'json',
        data: {score: ScoreJson},
     &nb

COM Object problem with .NET 4?

  

Hi,

I have a 32BIT COM object DLL from a vendor.

I have created a .NET 4 application using VS.NET 2010 set to work on x86 only and I have added a reference to the COM Object.
Problem is that on run time I am getting the error "Invalid Pointer" and in other situations I am getting the error "The Parameter is Incorrect".

When setting the project to work with .NET 3.5 than every thing is working without any problems.

How can I make the COM DLL to work on .NET 4 please?

Thanks,
Asaf

 


Threading problem with object context

  

Hello,

Let me try to explain the problem that i am working on.

I have a object where i need to update some values. The calculation of this values are causing some server load.

Thats why i do not refresh those values with each request. After refreshing the values they are valid for a certain time.

But if the values are needed to be refreshed (if they are "out of date") and there are more then one requests before the calculation is done

each thread (each request) is detecting that the values are "out of date" and each request is calculating the values again which is really killing the system :-)

To solve the problem i tried to set a property on the object, where i mark that the values are being calculated.

But if receive to many requests it still happens that the values are calculated twice. Which also creates useless system load.

So even before i set this property (and i do that before the calculation starts) an other thread already got to the same point and is also calculating the values.


Can anyone provide me some links or infos that i can learn how to manage this kind of problems?

Thanks


Cannot insert duplicate key row in object 'Table' with unique index 'Column_Id' Problem

  

All, We have a User where there is an Access Application installed. Every Day he enters some Account Numbers in it. This Access application is hooked to SQL Server 2008 which updates a table in SQL Server. Now last 2 weeks user had some Connection Issues so he did not enter any Account Numbers in the Access application instead he just noted them on a Excel sheet.

Now I did not want him to insert manually, so I took that Excel sheet, loaded account numbers in a Temp table and tried to insert all the Missing Account Numbers in the Main table. But it failed with the following error: Note: Account_No has a Unique Non Clustered Index on it and it is not a Primary key also. How can I insert them? (There are no duplicate account numbers as well that I am trying to insert its all Unique Accout Numbers)

Msg 2601, Level 14, State 1, Line 1
Cannot insert duplicate key row in object 'dbo.Table_Name' with unique index 'Accoutn_No'.
The statement has been terminated.

 


Categories: 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend