none
Passing a System.Array to a VB6 ActiveX EXE from C# RRS feed

  • Question

  • I have a C# app written in VS2005 using Net Framework 2.0. I call a function in a VB6 ActiveX EXE and pass a System.Array by ref. I recently upgraded the app to VS2010 but still using Net Framework 2.0. No problems. Then I decided to change the Target Platform to Net Framework 4.0 and now the call to that function generates an unhandled exception of type INVALID ARGUMENT. I tried Net Framework 3.5 and it works fine. Is this a known issue with Net Framework 4.0?

    The array I am passing is of a custom type defined in the VB6 ActiveX EXE named RDOPack. I define the array with 8 elements then run this code:

                Array RDOPackSA = Array.CreateInstance(typeof(RDOPack), 8);

                // then copy the data from the local data structure into the system array

                Array.Copy(RDOPack, RDOPackSA, 8);

                // then pass the ActiveX EXE the pointer to the System.Array which now contains

               //  the data from the local data structure array

                Object.ReadData(ref RDOPackSA);  // this line generates the exception

    This all works in Net Framework 2.0 and 3.5 but not in 4.0. I have not tried VS2012 or VS2013 yet but I think I may have to.

    One of my colleagues who is using my ActiveX EXE discovered this problem.

    Thanks in advance for any help.

    chiselca

    Thursday, July 24, 2014 8:57 PM

Answers

  • Hi Chiselca,

    .NET Framework 4 is a great version and improves many features. The Framework 4 is highly compatible with applications that are built with earlier .NET Framework versions. To run older applications with Framewrok 4, you should compile your app with the target .NET Framework version specified in the properties for your project, or you can specify the supported runtime with the supportedRuntime element in configuration file. See more information from the following links. http://msdn.microsoft.com/en-us/library/vstudio/ms171868(v=vs.100).aspx#application_compatibility_and_deployment.

    http://msdn.microsoft.com/en-us/library/vstudio/w4atty68(v=vs.100).aspx.

    If possible, you can also rewrite your project using Framework 4. If you have any question, you can reopen thread in this forum. It’s better if you post with some code sample. It will help us to reproduce your problem.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. <br/> Click <a href="http://support.microsoft.com/common/survey.aspx?showpage=1&scid=sw%3Ben%3B3559&theme=tech"> HERE</a> to participate the survey.

    • Marked as answer by chiselca Wednesday, July 30, 2014 5:03 PM
    Friday, July 25, 2014 1:56 AM
    Moderator

All replies

  • Hi Chiselca,

    .NET Framework 4 is a great version and improves many features. The Framework 4 is highly compatible with applications that are built with earlier .NET Framework versions. To run older applications with Framewrok 4, you should compile your app with the target .NET Framework version specified in the properties for your project, or you can specify the supported runtime with the supportedRuntime element in configuration file. See more information from the following links. http://msdn.microsoft.com/en-us/library/vstudio/ms171868(v=vs.100).aspx#application_compatibility_and_deployment.

    http://msdn.microsoft.com/en-us/library/vstudio/w4atty68(v=vs.100).aspx.

    If possible, you can also rewrite your project using Framework 4. If you have any question, you can reopen thread in this forum. It’s better if you post with some code sample. It will help us to reproduce your problem.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. <br/> Click <a href="http://support.microsoft.com/common/survey.aspx?showpage=1&scid=sw%3Ben%3B3559&theme=tech"> HERE</a> to participate the survey.

    • Marked as answer by chiselca Wednesday, July 30, 2014 5:03 PM
    Friday, July 25, 2014 1:56 AM
    Moderator
  • Herro,

    Thanks for your quick reply. The links you provided led me to articles that, once I digested them, made me think the issue might be the new Interop Reference property "Embed Interop Types" that is new for NET Framework 4.0. This property is set to True by default. I set it to False and this fixed the error I was getting.

    Thanks again,

    chiselca

    Wednesday, July 30, 2014 5:08 PM