Asked  7 Months ago    Answers:  5   Viewed   55 times

The goal is to unserialize a PHP serialized string and get sutable object in C#

Is there any way to make this possible in C#(.Net)?

To be more specific: We need to make an application which comunicates (Via HTTP) to specific website which returns the needed information. Fortunately/unfortunately we dont have permission to website so the data (array mostly) that is returned from website is PHP serialized.

 Answers

48

Found solution: Sharp Serialization Library

Wednesday, March 31, 2021
 
CMOS
answered 7 Months ago
70

Use .unserializeSession() instead of .unserialize().

Saturday, May 29, 2021
 
van_folmert
answered 5 Months ago
68

If you serialized an instance of List< MyClass > from your version 1.0.0.0 assembly, the SerializationBinder.BindToType function will be asked to provide this type:

System.Collections.Generic.List`1[[MyAssembly.MyClass, MyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=12345678901234567890]]

In order to remap the List< MyClass > type to your version 2.0.0.0 assembly, you need to change the type name to this:

System.Collections.Generic.List`1[[MyAssembly.MyClass, MyAssembly]]

The main point to note, is that the assembly name is not fully qualified. If you try to fully qualify the assembly name with a 2.0.0.0 version number, it will not work.

Friday, July 30, 2021
 
christina
answered 3 Months ago
53

It could look like this:

#include <iostream>
#include <sstream>
using namespace std;

int main()
{
    istringstream is("1n2n3n4nn5n");
    string s;
    while (getline(is, s))
    {
        if (s.empty())
        {
            cout << "Empty line." << endl;
        }
        else
        {
            istringstream tmp(s);
            int n;
            tmp >> n;
            cout << n << ' ';
        }
    }
    cout << "Done." << endl;
    return 0;
}

output:

1 2 3 4 Empty line.
5 Done.

Hope this helps.

Monday, August 9, 2021
 
neon29
answered 3 Months ago
99

You could hook the AppDomain.AssemblyResolve event to load the assemblies as they are needed. the event is raised each time that the runtime needs an assembly that it cannot resolve. It gives you one last chance to provide the assembly before the "Unable to find assembly" exception is thrown. Examples are on the page that I linked.

Monday, August 30, 2021
 
Andrei Urse
answered 2 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :