Skip to content
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

NATIVE_WRITE_FAILED Error on Windows 10 #73

Open
davidofwatkins opened this issue Mar 24, 2017 · 4 comments
Open

NATIVE_WRITE_FAILED Error on Windows 10 #73

davidofwatkins opened this issue Mar 24, 2017 · 4 comments

Comments

@davidofwatkins
Copy link

On Windows 10 (Surface Pro), I'm getting a NATIVE_WRITE_FAILED error from the following code:

NativeStorage.setItem('foo', 'bar', function() {
    console.log('success');
},
function(err) {
    console.log('error', err); // err = { code: 1, exception: null, source: "Native" }
});

In the "Output" tab of Visual Studio, I see the following when I run this:

The maximum number of credentials that may be stored has been exceeded
WinRT information: The maximum number of credentials that may be stored has been exceeded

I don't have much experience developing for Windows, but I see that NativeStorage is saving to Windows.Security.Credentials.PasswordVault() on Windows (see #38), which seems too limited to me. Is this expected? Perhaps the plugin should use something like Windows.Storage.ApplicationData?

Does anyone have any further ideas how to fix this? (cc @3h3c)

@alokrajiv
Copy link
Collaborator

@davidofwatkins Thank you very much for bringing this into notice.

I am going to re-write the windows implementation usingWindows.Storage.ApplicationData.current.localSettings.

@julesongithub
Copy link

@alokrajiv I don't know how to use github but I've got the code to replace the Windows.Security.Credentials.PasswordVault functionality with Windows.Storage.ApplicationData.current.localSettings:

var NativeStorageProxy = {
    getItem: function (win, fail, args) {
        try {
            var key = args[0];
            var value = Windows.Storage.ApplicationData.current.localSettings.values[key];
            // A value of undefined will throw a JSON error during the win() callback
            if (value === undefined) {
                fail(2);
            }
            else {
                win(value);
            }
        } catch (e) {
            fail(2);
        }
    },
    setItem: function (win, fail, args) {
        try {
            var key = args[0],
                value = args[1];
            // A value of undefined will throw a JSON error during the win() callback
            if (value === undefined) {
                fail(3);
            }
            else {
                Windows.Storage.ApplicationData.current.localSettings.values[key] = value;
                win(value);
            }
        } catch (e) {
            fail(1);
        }
    },
    remove: function (win, fail, args) {
        try {
            var values = Windows.Storage.ApplicationData.current.localSettings.values,
                key = args[0];
            if (values.hasKey(key)) {
                values.remove(key);
                win(key);
            }
            else {
                fail(2);
            }
        } catch (e) {
            fail(1);
        }
    },
    clear: function (win, fail, args) {
        try {
            Windows.Storage.ApplicationData.current.localSettings.values.clear();
            win();
        } catch (e) {
            fail(1);
        }
    },
    keys: function (win, fail) {
        try {
            var values = Windows.Storage.ApplicationData.current.localSettings.values,
                keys = [];
            for (var p in values) {
                if (values.hasOwnProperty(p)) {
                    keys.push(p);
                }
            }
            win(keys);
        } catch (e) {
            fail(2);
        }
    },
    putString: function (win, fail, args) {
        this.setItem(win, fail, args);
    },
    getString: function (win, fail, args) {
        this.getItem(win, fail, args);
    },
    putBoolean: function (win, fail, args) {
        this.setItem(win, fail, args);
    },
    getBoolean: function (win, fail, args) {
        this.getItem(win, fail, args);
    },
    putInt: function (win, fail, args) {
        this.setItem(win, fail, args);
    },
    getInt: function (win, fail, args) {
        this.getItem(win, fail, args);
    },
    putDouble: function (win, fail, args) {
        this.setItem(win, fail, args);
    },
    getDouble: function (win, fail, args) {
        this.getItem(win, fail, args);
    }
};

require("cordova/exec/proxy").add("NativeStorage", NativeStorageProxy);

@JeffBerman
Copy link

Has this been looked into at all, or has @julesongithub's code been reviewed? We just got bit by the same NATIVE_WRITE_FAILED error on a Windows 10 Surface Pro.

@alokrajiv alokrajiv removed their assignment Sep 29, 2018
@alokrajiv
Copy link
Collaborator

Unfortunately, something I missed along the way. Maybe someone can contribute here?

fresh2-wfan pushed a commit to fresh2-wfan/cordova-plugin-nativestorage that referenced this issue Oct 10, 2018
Use ApplicationData Storage instead of PasswordVault on Windows. Based on TheCocoaProject#73 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants