Skip to content

SystemSerializer update for BaseObjectStorageHelper #3702

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
6 commits merged into from
Jan 28, 2021

Conversation

michael-hawker
Copy link
Member

@michael-hawker michael-hawker commented Jan 28, 2021

Fixes #3692

This introduces a new light-weight serializer which we can use within the toolkit for the SystemInformation class still. And then developers with more complex type needs can specify their own serializer for the BaseObjectStorageHelper classes. See the related issue for more details.

Follow-on to #3637 and #3414

PR Type

What kind of change does this PR introduce?

  • Feature
  • Refactoring (no functional changes, no api changes)

What is the current behavior?

Using DataContractJsonSerializer, though we had used Newtonsoft.Json in 6.1.

What is the new behavior?

Use new SystemSerializer which passes values to/from the Windows ApplicationDataContainer APIs directly. Updates our internal usages of this to the new system. Requires developer using the BaseObjectStorageHelper to provide a serializer implementation.

This of course does provide a 'default'/system information within the toolkit now compared to our original thought of providing none at all before the SystemInformation problem was identified.

PR Checklist

Please check if your PR fulfills the following requirements:

  • Tested code with current supported SDKs
  • Pull Request has been submitted to the documentation repository instructions. Link:
  • Sample in sample app has been added / updated (for bug fixes / features)
  • New major technical changes in the toolkit have or will be added to the Wiki e.g. build changes, source generators, testing infrastructure, sample creation changes, etc...
  • Tests for the changes have been added (for bug fixes / features) (if applicable)
  • Header has been added to all new source files (run build/UpdateHeaders.bat)
  • Contains NO breaking changes

Other information

I tested copying the system.dat file from the Settings folder of our 6.1 sample app to the development version with the changes, no issues with SystemInformation reading the old data.

Updated/added unit tests to test the old json layer vs. reading from the new SystemSerializer as well as just testing a new System.Text.Json complex scenario. Added tests for exceptions.

TODO:

Rosuavio and others added 3 commits January 26, 2021 16:53
…mInformation

Tested copying data from 6.1 Sample App and was able to read/resume file writes with this new serializer.
TODO: Update tests.
@michael-hawker michael-hawker added this to the 7.0 milestone Jan 28, 2021
@ghost ghost added the in progress 🚧 label Jan 28, 2021
@ghost
Copy link

ghost commented Jan 28, 2021

Thanks michael-hawker for opening a Pull Request! The reviewers will test the PR and highlight if there is any conflict or changes required. If the PR is approved we will proceed to merge the pull request 🙌

@ghost ghost requested review from azchohfi, Kyaa-dost and Rosuavio January 28, 2021 01:09
@michael-hawker
Copy link
Member Author

Hmm, the UITests failed... I'll try a full build locally to check.

@michael-hawker
Copy link
Member Author

Just built locally fine:

image

@azchohfi I think I've noticed this a couple of times where the UI Tests just fail still in the CI... anything we can do to figure out what might have caused it?

@azchohfi
Copy link
Contributor

azchohfi commented Jan 28, 2021

This is the test that failed:
Failed Test_StorageHelper_DateTestFailure [15 ms]

Data of this type is not supported.

Error trying to serialize the value to be written to the application data store
  Stack Trace:
     at System.Runtime.InteropServices.WindowsRuntime.IMapSharedReferenceTypesStubClass.Insert[TKey, TValue](IDictionary`2, TKey, TValue) + 0xb4
   at System.Runtime.InteropServices.WindowsRuntime.IMapSharedReferenceTypesRCWAdapter.Indexer_Set[TKey, TValue](IDictionary`2, TKey, TValue) + 0x24
   at Windows.Storage.ApplicationDataCompositeValue.global::System.Collections.Generic.IDictionary<System.String,System.Object>.set_Item(String, Object) + 0x14
   at Microsoft.Toolkit.Uwp.Helpers.BaseObjectStorageHelper.Save[T](String, T) + 0x69
   at UnitTests.Helpers.Test_StorageHelper.Test_StorageHelper_DateTestFailure() + 0x2a
   at _$ILCT$.$ILT$ReflectionDynamicInvoke$.InvokeRetV(Object, IntPtr, InvokeUtils.ArgSetupState&, Boolean) + 0x2f
   at System.InvokeUtils.CalliIntrinsics.Call(IntPtr, Object, IntPtr, InvokeUtils.ArgSetupState&, Boolean) + 0x2c
   at System.InvokeUtils.CallDynamicInvokeMethod(Object, IntPtr, Object, IntPtr, IntPtr, Object, Object[], BinderBundle, Boolean, Boolean, Boolean) + 0x119

@michael-hawker
Copy link
Member Author

@azchohfi this test is passing locally it's supposed to throw an exception:

image

It just looks like it's throwing a slightly different exception in the CI? (System.Exception vs. System.ArgumentException)

I tried updating to use the more general [ExpectedException(typeof(Exception))] instead, but then get the opposite:

Message: 
    Test method threw exception System.ArgumentException, but exception System.Exception was expected. Exception message: System.ArgumentException: The parameter is incorrect.
    
    Error trying to write application data container value
  Stack Trace: 
    IMap`2.Insert(K key, V value)
    MapToDictionaryAdapter.Insert[K,V](IMap`2 _this, K key, V value)
    MapToDictionaryAdapter.Indexer_Set[K,V](K key, V value)
    BaseObjectStorageHelper.Save[T](String key, T value) line 126
    Test_StorageHelper.Test_StorageHelper_DateTestFailure()

…OS? code paths throwing different Exception Types...
@michael-hawker michael-hawker marked this pull request as ready for review January 28, 2021 19:36
@ghost
Copy link

ghost commented Jan 28, 2021

Hello @michael-hawker!

Because this pull request has the auto merge :zap: label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@ghost ghost merged commit 025a0ae into CommunityToolkit:master Jan 28, 2021
@michael-hawker michael-hawker mentioned this pull request Jan 28, 2021
8 tasks
Copy link
Contributor

@Rosuavio Rosuavio left a comment

Choose a reason for hiding this comment

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

We forgot a small thing.

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Investigate Basic Serializer for BaseObjectStorageHelper
4 participants