Skip to content

Possible regression "weakly-referenced JS value" #331

Closed

Description

Hello,

Lately I have this strange error popping up from my NAOT library which is built using the latest version 0.7.30 of node-api-dotnet:

Error: The weakly-referenced JS value not available.
at Microsoft.JavaScript.NodeApi.JSReference.GetValue() + 0xe6
at Microsoft.JavaScript.NodeApi.Interop.JSRuntimeContext.GetOrCreateObjectWrapper[T](T, Func'1) + 0x6a
at Microsoft.JavaScript.NodeApi.Interop.JSRuntimeContext.GetOrCreateObjectWrapper[T](T) + 0x8d
at Microsoft.JavaScript.NodeApi.Generated.Module.get_MicrosoftNodeapiNested_Parent_Child(JSCallbackArgs __args) + 0x90
at MicrosoftNodeapiNested!+0x128c39
at Microsoft.JavaScript.NodeApi.JSValue.InvokeCallback[TDescriptor](JSRuntime.napi_env, JSRuntime.napi_callback_info, JSValueScopeType, Func`2) + 0x1bc

I have made a small app and library to replicate the bug as it happens in my original NAOT library:

[JSExport]
public static class Program
{
    public static Parent GetParentInstance() {
        return new Parent();
    }
}`
[JSExport]
public class Parent {
    public string ParentName { get; set; } = "not set";
    public Child Child { get; set; } = new Child();
}
[JSExport]
public class Child {
    public string ChildName { get; set; } = "not set";
    public ChildChild ChildChild { get; set; } = new ChildChild();
}
[JSExport]
public class ChildChild {
    public string ChildChildName { get; set; } = "not set";
}

Then I've ran dotnet publish (with aot and node module settings) and then npm pack ( type="module" in package.js) to obtain the local npm package and made this demo mjs app:

import {Program , Parent, Child, ChildChild} from "./node_modules/microsoftnodeapinested/MicrosoftNodeapiNested.mjs";
const p = Program.getParentInstance();
console.log("parent name:",p.parentName);
const ccname = p.child.childChild.childChildName;
console.log("immediate ccname:",ccname);
let iter = 0;
setInterval(() => {
    console.log("loop #",iter++, " ccname:",p.child.childChild.childChildName);
}, 3000);

After about 5 loops I get that error.

This could be similar to a previous resolved issue (#292 which I have opened a while ago) but no nullable properties are involved.
I am not sure since when this started happening but as far as I remember, version 0.7.0 - 0.7.1 did not had it, therefore this could be a regression bug (perhaps while tying to fix some other memory-leak related issues?)

Thanks in advance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions