我想在我的.NET库中创建单元测试,它托管Edge.js以进行node.js函数调用。
失败并出现System.AccessViolationException
错误,我继续尝试在单元测试中使用Edge来重现此问题。
我能做到这一点,还是我不理解目前的限制?
重现,一个简单的单元测试
using System.Threading.Tasks;
using EdgeJs;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace UnitTest {
[TestClass]
public class UnitTest1 {
[TestMethod]
public void TestMethod1() {
Start().Wait();
}
public static async Task<object> Start() {
var func = Edge.Func(@"
return function (data, cb) {
cb(null, 'Node.js ' + process.version + ' welcomes ' + data);
}
");
return await func("MSTEST");
}
}
}
并且MSTEST挂起并且报告的消息显示在输出中
System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at _atexit_helper(IntPtr func, UInt32* __pexit_list_size, (fnptr)** __ponexitend_e, (fnptr)** __ponexitbegin_e)
at _atexit_m(IntPtr func)
at ClrFunc.Initialize(Local<v8::Function>* , Func`2 func)
at ClrFunc.Initialize(FunctionCallbackInfo<v8::Value>* info)
at initializeClrFunc(FunctionCallbackInfo<v8::Value>* info)
at Nan.imp.?A0x8dda69af.FunctionCallbackWrapper(FunctionCallbackInfo<v8::Value>* info)
at EdgeJs.Edge.NodeStartx86(Int32 argc, String[] argv)
at EdgeJs.Edge.<>c__DisplayClass11_0.<Func>b__0()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
at _atexit_helper(IntPtr func, UInt32* __pexit_list_size, (fnptr)** __ponexitend_e, (fnptr)** __ponexitbegin_e)
at _atexit_m(IntPtr func)
at ClrFunc.Initialize(Local<v8::Function>* , Func`2 func)
at ClrFunc.Initialize(FunctionCallbackInfo<v8::Value>* info)
at initializeClrFunc(FunctionCallbackInfo<v8::Value>* info)
at Nan.imp.?A0x8dda69af.FunctionCallbackWrapper(FunctionCallbackInfo<v8::Value>* info)
at EdgeJs.Edge.NodeStartx86(Int32 argc, String[] argv)
at EdgeJs.Edge.<>c__DisplayClass11_0.<Func>b__0()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()