Skip to content
This repository was archived by the owner on Jan 24, 2021. It is now read-only.

Removed binaryformatter replaced with json serializer #2264

Merged
merged 1 commit into from
Feb 18, 2016

Conversation

jchannon
Copy link
Member

@jchannon jchannon commented Feb 9, 2016

address #2220

@jchannon jchannon added this to the coreclr milestone Feb 9, 2016
@jchannon jchannon force-pushed the binaryformatterremoval branch from f40a54c to 4a37969 Compare February 9, 2016 15:55
{
formatter.Serialize(outputStream, sourceObject);
var jsonSerializer = new JsonSerializer(new JavaScriptSerializer());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we really new this up every time?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, why haven't we #ifdef'ed this to use BinaryFormatter where available?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because JS will work for both I guess

@@ -1531,6 +1537,9 @@
<Link>Diagnostics\Views\login.sshtml</Link>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't see this anywhere?

IDictionary<string, object> expando = new ExpandoObject();

foreach (PropertyDescriptor property in TypeDescriptor.GetProperties(value.GetType()))
expando.Add(property.Name, property.GetValue(value));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing { }

@thecodejunkie
Copy link
Member

So the one thing here is that this does not seem to handle object graphs. The ObjectExtensions.ToDynamic does not seem to handle if there are complex types on one of the properties? With the BinaryFormatter is not a problem, but here we only seem to handle 1-level of properties and they have to be primitive types

@@ -34,8 +35,10 @@ public CsrfFixture()
this.pipelines = new MockPipelines();

this.cryptographyConfiguration = CryptographyConfiguration.Default;

this.objectSerializer = new DefaultObjectSerializer();
var fakeAssCatalog = A.Fake<IAssemblyCatalog>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

People might get offended by the word 'Ass'

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😄 This is the same as the adq variable, why shorten it? fakeAssemblyCatalog is waaaaay more descriptive. 👍 for changing this, even if it's not for the same reason @phillip-haydon pointed out ;)

@jchannon jchannon force-pushed the binaryformatterremoval branch from 19afc01 to bf5bba8 Compare February 16, 2016 11:21
@jchannon
Copy link
Member Author

@thecodejunkie seems to be ok or are you thinking more complex https://dotnetfiddle.net/0RDcN1

@jchannon jchannon force-pushed the binaryformatterremoval branch from bf5bba8 to 2592da4 Compare February 16, 2016 11:33
@jchannon jchannon force-pushed the binaryformatterremoval branch 2 times, most recently from ff26612 to 68216cc Compare February 16, 2016 12:08
@jchannon jchannon force-pushed the binaryformatterremoval branch 3 times, most recently from d158036 to 55391d6 Compare February 17, 2016 17:06
@thecodejunkie
Copy link
Member

I stand corrected :D

@thecodejunkie
Copy link
Member

Looking at AppVeyor, we should get #2274 in first and then rebase this?

@@ -66,7 +66,7 @@ protected override void ApplicationStartup(TinyIoCContainer container, IPipeline

this.Conventions.StaticContentsConventions.Add(StaticContentConventionBuilder.AddDirectory("moo", "Content"));

CookieBasedSessions.Enable(pipelines);
CookieBasedSessions.Enable(pipelines, container.Resolve<IAssemblyCatalog>());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.AssemblyCatalog should be all that is needed here, no?

@jchannon jchannon force-pushed the binaryformatterremoval branch 2 times, most recently from fef04ee to 98ff683 Compare February 18, 2016 11:00
@jchannon jchannon force-pushed the binaryformatterremoval branch from 98ff683 to 14ac689 Compare February 18, 2016 11:02
thecodejunkie added a commit that referenced this pull request Feb 18, 2016
Removed binaryformatter replaced with json serializer
@thecodejunkie thecodejunkie merged commit a8616d8 into NancyFx:coreclr Feb 18, 2016
using (var outputStream = new MemoryStream())
private dynamic AddTypeInformation(object sourceObject)
{
var sourceType = this.assemblyCatalog.GetAssemblies().Select(assembly => assembly.GetType(sourceObject.GetType().FullName)).FirstOrDefault(type => type != null);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jchannon this can be replaced by sourceObject.GetType().AssemblyQualifiedName can't it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we already do that a few lines below, this is finding the type in the list of assemblies to get the assembly qualified name as the object being serialized might be in a project just with pocos for example

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is finding the type in the list of assemblies to get the assembly qualified name

But why do you need to find it in a list of assemblies when you got the type right there? It's even used to get the FullName of the type...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think maybe AssemblyQualifiedName is empty if its a class in a separate poco lib or something.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You think? 😝

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think thats some sarcasm I'm not getting 😄 We need to find the type in the assemblies to get the AQN

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't think, you need to know.

The only way AssemblyQualifiedName returns null is if it's a generic type parameter. From MSDN:

The assembly-qualified name of the Type, which includes the name of the assembly from which the Type was loaded, or null if the current instance represents a generic type parameter.

image

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well if you hadn't insisted on one commit message per PR then I might have
something that jogs my memory why I added it.

Remove it, run the tests and if all is ok then consider me told

On Tuesday, 23 February 2016, Kristian Hellang [email protected]
wrote:

In src/Nancy/DefaultObjectSerializer.cs
#2264 (comment):

  •        using (var outputStream = new MemoryStream())
    
  •    private dynamic AddTypeInformation(object sourceObject)
    
  •    {
    
  •        var sourceType = this.assemblyCatalog.GetAssemblies().Select(assembly => assembly.GetType(sourceObject.GetType().FullName)).FirstOrDefault(type => type != null);
    

You can't think, you need to know.

The only way AssemblyQualifiedName returns null is if it's a generic type
parameter. From MSDN:

The assembly-qualified name of the Type, which includes the name of the
assembly from which the Type was loaded, or null if the current instance
represents a generic type parameter.

[image: image]
https://cloud.githubusercontent.com/assets/582487/13261618/49c94f20-da61-11e5-8eb1-937c659111c6.png


Reply to this email directly or view it on GitHub
https://github.com/NancyFx/Nancy/pull/2264/files#r53822433.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants