← Back to team overview

nunit-core team mailing list archive

[Bug 558522] [NEW] Static std::string in C++/C# Mixed Project

 

Public bug reported:

I encountered a couple strange errors when running unit tests in a C# project that references a C++/CLI project when using static std::strings. I don't know if it is related to NUnit, TestDriven.Net, or .Net itself, but it only happens when running a unit test; I cannot reproduce the problem in a C# console application or C# Windows application. 
 
I have attached a rar archive of a Solution that demonstrates the problem.
 
The TestWeirdError project is a console application and has no problems.
If I comment out line 15 of CppClassForWeirdError.h ("static std::string s ...") or change the string to not be static, then the NUnitTestForWeirdError project works fine, too.
Otherwise, the NUnitTestForWeirdError project generates the following output:
 
 
In Release Mode:
 
TestCase 'NUnitTestForWeirdError.Class1.Test'
failed: System.AccessViolationException : Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
 f:\dd\vctools\crt_bld\self_x86\crt\src\msilexit.cpp(349,0): at _atexit_helper(IntPtr func, UInt32* __pexit_list_size, (fnptr)** __ponexitend, (fnptr)** __ponexitbegin)
 f:\dd\vctools\crt_bld\self_x86\crt\src\msilexit.cpp(520,0): at _atexit_m(IntPtr func)
 c:\users\administrator\documents\visual studio 2005\projects\testweirderror\cppclassforweirderror\cppclassforweirderror.h(15,0): at CppClassForWeirdError.CppClassForWeirdError..ctor()
 C:\Users\Administrator\Documents\Visual Studio 2005\Projects\TestWeirdError\NUnitTestForWeirdError\Class1.cs(14,0): at NUnitTestForWeirdError.Class1.Test()

 
In Debug Mode:
 
---- DEBUG ASSERTION FAILED ----
---- Assert Short Message ----
This function must be called in the default domain
---- Assert Long Message ----

    at <Module>._atexit_m(IntPtr func)  f:\dd\vctools\crt_bld\self_x86\crt\src\msilexit.cpp(517)
    at CppClassForWeirdError..ctor()  c:\users\administrator\documents\visual studio 2005\projects\testweirderror\cppclassforweirderror\cppclassforweirderror.h(15)
    at Class1.Test()  C:\Users\Administrator\Documents\Visual Studio 2005\Projects\TestWeirdError\NUnitTestForWeirdError\Class1.cs(14)
    at RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)  
    at RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)  
    at RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)  
    at RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)  
    at Reflect.InvokeMethod(MethodInfo method, Object fixture, Object[] args)  
    at TestMethod.RunTestMethod(TestCaseResult testResult)  
    at TestMethod.doTestCase(TestCaseResult testResult)  
    at TestMethod.doRun(TestCaseResult testResult)  
    at TestMethod.Run(TestCaseResult testResult)  
    at NUnitTestMethod.Run(TestCaseResult testResult)  
    at TestCase.Run(EventListener listener)  
    at TestCase.Run(EventListener listener, ITestFilter filter)  
    at TestSuite.RunAllTests(TestSuiteResult suiteResult, EventListener listener, ITestFilter filter)  
    at TestSuite.Run(EventListener listener, ITestFilter filter)  
    at TestFixture.Run(EventListener listener, ITestFilter filter)  
    at TestSuite.RunAllTests(TestSuiteResult suiteResult, EventListener listener, ITestFilter filter)  
    at TestSuite.Run(EventListener listener, ITestFilter filter)  
    at TestSuite.RunAllTests(TestSuiteResult suiteResult, EventListener listener, ITestFilter filter)  
    at TestSuite.Run(EventListener listener, ITestFilter filter)  
    at NUnitTestRunner.run(ITestListener testListener, Assembly assembly, ITestFilter filter)  
    at NUnitTestRunner.runMethod(ITestListener testListener, Assembly assembly, MethodInfo method)  
    at NUnitTestRunner.RunMember(ITestListener testListener, Assembly assembly, MemberInfo member)  
    at AdaptorTestRunner.Run(ITestListener testListener, ITraceListener traceListener, String assemblyPath, String testPath)  
    at Runner.Run()  
    at ThreadHelper.ThreadStart_Context(Object state)  
    at ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)  
    at ThreadHelper.ThreadStart()  
TestCase 'NUnitTestForWeirdError.Class1.Test'
failed: System.AccessViolationException : Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
 f:\dd\vctools\crt_bld\self_x86\crt\src\msilexit.cpp(349,0): at _atexit_helper(IntPtr func, UInt32* __pexit_list_size, (fnptr)** __ponexitend, (fnptr)** __ponexitbegin)
 f:\dd\vctools\crt_bld\self_x86\crt\src\msilexit.cpp(520,0): at _atexit_m(IntPtr func)
 c:\users\administrator\documents\visual studio 2005\projects\testweirderror\cppclassforweirderror\cppclassforweirderror.h(15,0): at CppClassForWeirdError.CppClassForWeirdError..ctor()
 C:\Users\Administrator\Documents\Visual Studio 2005\Projects\TestWeirdError\NUnitTestForWeirdError\Class1.cs(14,0): at NUnitTestForWeirdError.Class1.Test()

** Affects: nunitv2
     Importance: Undecided
         Status: New

-- 
Static std::string in C++/C# Mixed Project
https://bugs.launchpad.net/bugs/558522
You received this bug notification because you are a member of NUnit
Developers, which is subscribed to NUnit V2.

Status in NUnit V2 Test Framework: New

Bug description:
I encountered a couple strange errors when running unit tests in a C# project that references a C++/CLI project when using static std::strings. I don't know if it is related to NUnit, TestDriven.Net, or .Net itself, but it only happens when running a unit test; I cannot reproduce the problem in a C# console application or C# Windows application. 
 
I have attached a rar archive of a Solution that demonstrates the problem.
 
The TestWeirdError project is a console application and has no problems.
If I comment out line 15 of CppClassForWeirdError.h ("static std::string s ...") or change the string to not be static, then the NUnitTestForWeirdError project works fine, too.
Otherwise, the NUnitTestForWeirdError project generates the following output:
 
 
In Release Mode:
 
TestCase 'NUnitTestForWeirdError.Class1.Test'
failed: System.AccessViolationException : Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
 f:\dd\vctools\crt_bld\self_x86\crt\src\msilexit.cpp(349,0): at _atexit_helper(IntPtr func, UInt32* __pexit_list_size, (fnptr)** __ponexitend, (fnptr)** __ponexitbegin)
 f:\dd\vctools\crt_bld\self_x86\crt\src\msilexit.cpp(520,0): at _atexit_m(IntPtr func)
 c:\users\administrator\documents\visual studio 2005\projects\testweirderror\cppclassforweirderror\cppclassforweirderror.h(15,0): at CppClassForWeirdError.CppClassForWeirdError..ctor()
 C:\Users\Administrator\Documents\Visual Studio 2005\Projects\TestWeirdError\NUnitTestForWeirdError\Class1.cs(14,0): at NUnitTestForWeirdError.Class1.Test()

 
In Debug Mode:
 
---- DEBUG ASSERTION FAILED ----
---- Assert Short Message ----
This function must be called in the default domain
---- Assert Long Message ----

    at <Module>._atexit_m(IntPtr func)  f:\dd\vctools\crt_bld\self_x86\crt\src\msilexit.cpp(517)
    at CppClassForWeirdError..ctor()  c:\users\administrator\documents\visual studio 2005\projects\testweirderror\cppclassforweirderror\cppclassforweirderror.h(15)
    at Class1.Test()  C:\Users\Administrator\Documents\Visual Studio 2005\Projects\TestWeirdError\NUnitTestForWeirdError\Class1.cs(14)
    at RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)  
    at RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)  
    at RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)  
    at RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)  
    at Reflect.InvokeMethod(MethodInfo method, Object fixture, Object[] args)  
    at TestMethod.RunTestMethod(TestCaseResult testResult)  
    at TestMethod.doTestCase(TestCaseResult testResult)  
    at TestMethod.doRun(TestCaseResult testResult)  
    at TestMethod.Run(TestCaseResult testResult)  
    at NUnitTestMethod.Run(TestCaseResult testResult)  
    at TestCase.Run(EventListener listener)  
    at TestCase.Run(EventListener listener, ITestFilter filter)  
    at TestSuite.RunAllTests(TestSuiteResult suiteResult, EventListener listener, ITestFilter filter)  
    at TestSuite.Run(EventListener listener, ITestFilter filter)  
    at TestFixture.Run(EventListener listener, ITestFilter filter)  
    at TestSuite.RunAllTests(TestSuiteResult suiteResult, EventListener listener, ITestFilter filter)  
    at TestSuite.Run(EventListener listener, ITestFilter filter)  
    at TestSuite.RunAllTests(TestSuiteResult suiteResult, EventListener listener, ITestFilter filter)  
    at TestSuite.Run(EventListener listener, ITestFilter filter)  
    at NUnitTestRunner.run(ITestListener testListener, Assembly assembly, ITestFilter filter)  
    at NUnitTestRunner.runMethod(ITestListener testListener, Assembly assembly, MethodInfo method)  
    at NUnitTestRunner.RunMember(ITestListener testListener, Assembly assembly, MemberInfo member)  
    at AdaptorTestRunner.Run(ITestListener testListener, ITraceListener traceListener, String assemblyPath, String testPath)  
    at Runner.Run()  
    at ThreadHelper.ThreadStart_Context(Object state)  
    at ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)  
    at ThreadHelper.ThreadStart()  
TestCase 'NUnitTestForWeirdError.Class1.Test'
failed: System.AccessViolationException : Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
 f:\dd\vctools\crt_bld\self_x86\crt\src\msilexit.cpp(349,0): at _atexit_helper(IntPtr func, UInt32* __pexit_list_size, (fnptr)** __ponexitend, (fnptr)** __ponexitbegin)
 f:\dd\vctools\crt_bld\self_x86\crt\src\msilexit.cpp(520,0): at _atexit_m(IntPtr func)
 c:\users\administrator\documents\visual studio 2005\projects\testweirderror\cppclassforweirderror\cppclassforweirderror.h(15,0): at CppClassForWeirdError.CppClassForWeirdError..ctor()
 C:\Users\Administrator\Documents\Visual Studio 2005\Projects\TestWeirdError\NUnitTestForWeirdError\Class1.cs(14,0): at NUnitTestForWeirdError.Class1.Test()





Follow ups

References