🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: microsoft.public.dotnet.framework.interop
Article #8

C# XslCompiledTransform crash when called from VCL C++

#8
From: Jeroen ter Hofstede
Date: Thu, 16 Mar 2006 15:09
73 lines
3297 bytes
Environment:
- .Net Framework v2.0.50727
- Borland C++ Builder 5

We are extending our C++ application with functionality in a C# dll.
The C++ app creates an object from the (registered) dll and calls a
method in it. This method creates and uses an XslCompiledTransform
object. Unfortunately, when calling Load() on this object, the
application crashes with an access violation in the .Net runtime. This
problem does not occur when we call the same method from a VB
application, nor does it occur when performing the same steps from
within a (C++ Builder) console application. Until now, we've only
managed to reproduce the problem from within a windowed (VCL)
application.

Does someone have any clue about what might cause this problem, and
moreover, what can be done about it?
TIA,
Jeroen


The smallest example that exhibits the problem contains:

* The C# file issue.cs (compile with csc /target:library issue.cs, and
then register it with regasm /codebase issue.dll)
---
using System.Runtime.InteropServices;
using System.Xml.Xsl;

[Guid("694C1820-04B6-4988-928F-FD858B95C880")]
public interface IIssue
{
  void issue ();
}

[Guid("9E5E5FB2-219D-4ee7-AB27-E4DBED8E123E"),
 ClassInterface(ClassInterfaceType.None)]
public class Issue : IIssue
{
  public void issue ()
  {
    XslCompiledTransform transformer = new XslCompiledTransform ();
    transformer.Load (@"c:\transform.xsl");
  }
}
---

* The xsl file c:\transform.xsl:
---
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
</xsl:template>
</xsl:stylesheet>
---

and
* The C++ Builder program (project2.cpp in project2)
---
# include <olectnrs.hpp>
USERES("Project2.res");

WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
  OleInitialize (0);
  Variant obj = CreateOleObject ("Issue");
  obj.OleFunction ("issue");
  return 0;
  // Cut away the from creation and message
  //loop - not needed for example
}
---
Technical Details
Message-ID: <1142521767.541238.214090@z34g2000cwc.googlegroups.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!postnews.google.com!z34g2000cwc.googlegroups.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 10fc48,f764f9342057d78f,start
X-Google-Thread: fde74,f764f9342057d78f,start
X-Google-Attributes: gid10fc48,gidfde74,public
X-Google-Language: ENGLISH,ASCII-7-bit
Path: arc1-ca.pugleaf.net!g2news1.google.com!postnews.google.com!z34g2000cwc.googlegroups.com!not-for-mail
From: "Jeroen ter Hofstede" <jeroen.ter.hofstede@wanadoo.nl>
Newsgroups: microsoft.public.dotnet.framework.interop,borland.public.cppbuilder.language.cpp
Subject: C# XslCompiledTransform crash when called from VCL C++
Date: 16 Mar 2006 07:09:27 -0800
Organization: http://groups.google.com
Lines: 74
Message-ID: <1142521767.541238.214090@z34g2000cwc.googlegroups.com>
NNTP-Posting-Host: 62.177.224.213
Mime-Version: 1.0
Content-Type: text/plain; charset="iso-8859-1"
X-Trace: posting.google.com 1142521774 17626 127.0.0.1 (16 Mar 2006 15:09:34 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Thu, 16 Mar 2006 15:09:34 +0000 (UTC)
User-Agent: G2/0.2
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1,gzip(gfe),gzip(gfe)
Complaints-To: groups-abuse@google.com
Injection-Info: z34g2000cwc.googlegroups.com; posting-host=62.177.224.213;
   posting-account=GtcNIQ0AAAB-HytxjLrEI1snnk-XzQGu