Search code examples
c#c++c++-cli.net-8.0dottrace

dotTrace fails while activating cpp/cli type from c# app


dotTrace 2024.2.6 is failing on an enterprise application my company works on. It fails while activating cpp type. I created minimal example with similar structure. It fails if I leave ATL part in, if not dotTrace runs fine. I believe in the enterprise application the problem is not only with ATL. And it all worked fine until we have switched from net48 to net8.0.

  • Program.csproj
    Program.cs

    using System.Reflection;
    var legacyDeploymentServerHostInstance = Assembly.LoadFrom("CppCli.dll").GetType("CppCli.CppCliType");
    var baseType = Activator.CreateInstance(legacyDeploymentServerHostInstance!) as Library.CppCli.BaseType;
    Console.WriteLine("Success");
    
  • Library.CppCli.csproj
    BaseType.cs

    namespace Library.CppCli {
        public interface BaseType : IDisposable {
        }
    }
    
  • CppCli.vcxproj
    CppCliType.h

    namespace CppCli
    {
        public ref class CppCliType : public Library::CppCli::BaseType
        {
        public:
             CppCliType();
             ~CppCliType();
        };
    }
    

    CppCliType.cpp

    #include "CppCliType.h"
    #include <atlstr.h>
    #include <iostream>
    
    namespace CppCli
    {
        CppCliType::CppCliType()
        {
            CString aCString = CString(_T("A string"));
            std::cout << (LPCTSTR)aCString;
        }
    
        CppCliType::~CppCliType()
        {
            System::Text::Json::JsonSerializer::Serialize(this);
        }
    }
    

The error I observe is

Fatal error. Internal CLR error. (0x80131506)
at System.StubHelpers.StubHelpers.ProfilerBeginTransitionCallback(IntPtr, IntPtr, System.Object)
at .ATL.CSimpleStringT<wchar_t,0>.{ctor}(ATL.CSimpleStringT<wchar_t,0>, ATL.IAtlStringMgr)
at .ATL.CStringT<wchar_t,ATL::StrTraitATL<wchar_t,ATL::ChTraitsCRT<wchar_t> > >.{ctor}(ATL.CStringT<wchar_t,ATL::StrTraitATL<wchar_t,ATL::ChTraitsCRT<wchar_t> > >, Char)
at CppCli.CppCliType..ctor()
at System.RuntimeType+ActivatorCache.CallConstructor(System.Object)
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean, Boolean)
at System.Activator.CreateInstance(System.Type, Boolean, Boolean)
at System.Activator.CreateInstance(System.Type, Boolean)
at System.Activator.CreateInstance(System.Type)
at Program.$(System.String[])

EDIT: I've noticed the same behavior with ANTS Performance Profiler.


Solution

  • I've asked on dotTrace forum here. Got an answer that this is a known issue and I need to track this ticket.