none
Starting a .NET 2.0 Process From a .NET 4.0 Process RRS feed

  • Question

  • Hi,

    I have an application, lets called it 4.0App.exe.  This application is built against .NET Framework 4.0.  This app starts up a different application in a separate app domain, 2.0App.exe, which is built against .NET Framework 2.0.  My 2.0App runs ok but some of the pieces are having a few issues and it is because the core .NET system assemblies that are loaded are 4.0 instead of 2.0.  If I run the 2.0App by itself, the .NET 2.0 System assemblies are loaded and everything works great.  When my 4.0App starts my 2.0App (in a separate AppDomain), the 2.0App has issues and I can clearly see that the 4.0 System assemblies are loaded and not the 2.0 assemblies.

    I'm wondering if there is any way to force the 2.0 assemblies to load in this scenario.  I've been experimenting with all different kinds of combinations of the following settings in the two exe.config files but nothing seems to be working.  

    <startup useLegacyV2RuntimeActivationPolicy="true">

        <supportedRuntime version="v2.0.50727" />

        <supportedRuntime version="v4.0" />

      </startup>

    The 2.0App.exe.config file is assigned to the newly created AppDomain.  In that config file, even if I say the only supported runtime is 2.0, the 4.0 assemblies are still loaded.

    Any ideas on this issue?  I hope I have explained this good enough.

    Thanks,

    ~Corey

    Friday, June 3, 2011 5:29 PM

Answers

  •  

    Hi Corey,

     

    According to your description, you need to load two versions of CLR-CLR 4.0 and CLR 2.0, am I right? If yes, I think we need to host a different version of CLR.

     

    Fortunately, with .NET Framework 4.0, Microsoft now supports the ability to load v2.0 and v4.0 in a single Windows process, allowing components written for .NET Framework versions 2.0 and 4.0 to run side by side without experiencing any compatibility problems. This is a fantastic new feature, as it allows .NET Framework components to be used reliably in more scenarios than ever before.

     

    Detail information, please refer to:

    CLR Hosting APIs

    Creating a host application for the .NET Common Language Runtime

    Host CLR


    Paul Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Paul Zhou Wednesday, June 15, 2011 4:47 AM
    Wednesday, June 8, 2011 8:19 AM

All replies

  • You would need to start it as a separate process if you want to force .NET 2 to load.  Loading in a separate appdomain will still use the same core libraries (as they create the app domain).

     

    Calling Process.Start, however, will launch it using .NET 2.0.

     

    That being said, I'm curious - what issues are you receiving with this application when running under the .NET 4 CLR?  It's probably easier to correct those....


    Reed Copsey, Jr. - http://reedcopsey.com
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Friday, June 3, 2011 6:07 PM
    Moderator
  • Hi,

    Thanks for the quick response.  We seem to be having an issue loading any form that uses a System.Windows.Forms.RichTextBox.  Normally the app will just disappear and we don't get any exception or stack trace other than the common message "Your process has stopped working".  There are times when we get the following exception, but this just may be a bad effect, we aren't sure.

    Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

    Source : mscorlib

    System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

    at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)

    at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)

    at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection, Boolean suppressSecurityChecks)

    at System.Reflection.Assembly.Load(AssemblyName assemblyRef)

    at System.Xml.Serialization.TempAssembly.LoadGeneratedAssembly(Type type, String defaultNamespace, XmlSerializerImplementation& contract)

    at System.Xml.Serialization.XmlSerializer.FromMappings(XmlMapping[] mappings, Type type)

    at System.Web.Services.Protocols.SoapClientType..ctor(Type type)

    at System.Web.Services.Protocols.SoapHttpClientProtocol..ctor()

    at SixDisciplines.Win.UI.WebServices.WebProxyBase..ctor()

    at SixDisciplines.Win.UI.Data.PerformanceReview..ctor()

    at SixDisciplines.Win.UI.DataAccess.PerformanceReview..ctor()

    at SixDisciplines.Win.UI.Screens._700_503_002_00..ctor()

     

    We know this is due to using the RichTextBox because if we remove this control from our form, everything works fine.  Note that this is a wrapped Windows RichTextBox so it is possible that we are doing something that causes this problem, but I'm not sure.

     

    Thanks,

    ~Corey

    Friday, June 3, 2011 6:44 PM
  • Does your ~main~ program (the .NET 4 one) have <startup useLegacyV2RuntimeActivationPolicy="true"> in it's app.config?

     

    The problem is likely due to the COM interop with RichTextBox (internally)...


    Reed Copsey, Jr. - http://reedcopsey.com
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Friday, June 3, 2011 7:13 PM
    Moderator
  • Yes, I have this in my main 4.0's app.exe.config file.

    <startup useLegacyV2RuntimeActivationPolicy="true">

        <supportedRuntime version="v4.0" />

    </startup>

    Friday, June 3, 2011 7:19 PM
  • Not sure why this is doing it- Is there a reason you can't launch the application with Process.Start instead of trying to load it in an app domain?

    That will work, provided the application runs standalone.


    Reed Copsey, Jr. - http://reedcopsey.com
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Friday, June 3, 2011 7:29 PM
    Moderator
  • Well, it's kind of hard for me to explain.  It's been built like this for a long time.  The main app is our sign on app, and it starts up the client application from that.  It uses an app domain because certain communication is needed back to the main app, we show certain progress information, and it limits the user to a single process.  I think it would be a large effort to redesign the way our sign on process works and we just don't have that kind of time at this point.
    Friday, June 3, 2011 7:40 PM
  •  

    Hi Corey,

     

    According to your description, you need to load two versions of CLR-CLR 4.0 and CLR 2.0, am I right? If yes, I think we need to host a different version of CLR.

     

    Fortunately, with .NET Framework 4.0, Microsoft now supports the ability to load v2.0 and v4.0 in a single Windows process, allowing components written for .NET Framework versions 2.0 and 4.0 to run side by side without experiencing any compatibility problems. This is a fantastic new feature, as it allows .NET Framework components to be used reliably in more scenarios than ever before.

     

    Detail information, please refer to:

    CLR Hosting APIs

    Creating a host application for the .NET Common Language Runtime

    Host CLR


    Paul Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Paul Zhou Wednesday, June 15, 2011 4:47 AM
    Wednesday, June 8, 2011 8:19 AM
  •  

    Hi,

     

    I am writing to check the status of the issue on your side. Would you mind letting us know the result of the suggestions?

     

    If you have got answers, please remember to mark answer and close this thread.

    If not, any more concerns, please feel free to let us know.


    Paul Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, June 13, 2011 6:06 AM