It was a misfortune - I need to write an application on UWP. Of course, I design everything according to the MVC model. It is much more convenient for me to test and develop models in a console application, and it so often happens that those classes that worked perfectly for the console app do not find the definition of classes in the UWP application and vice versa. So how to write as cross-platform as possible?

I understand, for example, the class for working with the camera may not work in the console application, but in order that the encryption or serialization classes do not work ... then I ask you to forgive me - to hell the developers of all this!

I have a library, but when I connect it, I get an error:

one

If I create a portable library and specify the target UWP platform, then it does not know about the existence of such classes as: BinaryFormatter, Aes, AesCryptoServiceProvider, CryptoStream, Serializable. This is, in principle, logical, because they did not bother to add them to the UWP! Besides how to write your own implementation algorithms, can you somehow transfer these classes? Is there at least some kind of cross-platform ???

    1 answer 1

    Binary serialization is significantly dependent on reflection and dynamic code generation, so it, unfortunately, is not available in limited subsets of .NET (UWP / Silverlight / .NET Core). Perhaps it makes sense to switch to XML serialization or DataContractSerializer .

    And cryptography is not so bad! She just “moved” to another namespace . You need to use SymmetricKeyAlgorithmProvider.OpenAlgorithm with one of the AES parameters, the full list is here .


    Perhaps this part of the code will not be easily portable to the desktop. For this, according to the idea in the Universal App, you can select common and platform-specific parts.

    • I need to perform an object to byte [] operation and vice versa. With cryptography, not everything is so bad ... everything is terrible! What for? Why this move? And why is there no support for the old version (I just don’t know how to say it differently)? - Sanych Goilo
    • @SanychGoilo: object to byte[] - this is serialization. And you, in theory, should not care which one. - VladD
    • @SanychGoilo: Why the cryptography has moved, I personally do not know. Maybe because the system implementation is used, and not dragging your bike. In any case, look at the problem not emotionally, but pragmatically: you have cryptography on the platform, so there is no disaster. And the fact that there is another namespace and a slightly different syntax - well, so you are a programmer, you can handle it. - VladD
    • It is important for me to get byte Time is wasted, that's all the emotions. Until recently, I do not believe that this can not be somehow solved. - Sanych Goilo
    • @SanychGoilo: Well, why didn't XML serialization please you? Or DataContractSerializer ? They will also give you an array of bytes at the output. - VladD