none
Runtime error when using .NET 2.0 DLL in a .NET 4.0 application RRS feed

  • Question

  • When I set the target framwork to 3.5 and have referenced 2 dlls based on .NET 2.0.50727, the application runs.

    But when I set the target framwork to 4.0 and try to run this application without any changes, I get the error:

    "A first chance exception of type 'System.Windows.Markup.XamlParseException' occurred in PresentationFramework.dll

    Additional information: Could not load file or assembly 'Microsoft.Windows.Design, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. Das System kann die angegebene Datei nicht finden."

    On my PC are all frameworks with all SPx installed. In app.config I added

    startup useLegacyV2RuntimeActivationPolicy="true"

    but it did't help. Isn't it possible, to reference a 2.0 dll in a WPF .NET 4.0 application?

    • Moved by Aspen VJ Wednesday, March 16, 2011 9:39 AM (From:Visual C# General)
    Tuesday, March 15, 2011 7:54 AM

Answers

  • Hi Diana,

     

    Welcome to the MSDN forum!

     

    This is because your original project targets .Net Framework 3.5 and the DLL targets .NET Framework 2.0.

    Both .NET Framework 3.5 and V2.0 loads CLR 2.0 so that your original application can run well.

    But .NET Framework 4.0 is different from version before. It loads CLR 4.0 which is not the same as the DLL. So exception occurred in the dll.

     

    The way to resolve the problem lists as below:

    1.       Rebuild the DLL to targets .NET Framework 4.0. But you need to make sure that the classes and methods in the DLL can support V4.0.

    2.       Fortunately, .NET Framework 4.0 supports to Load several versions of CLR in one process. You can forces to load CLR 2.0 when you using the DLL via CLR’s Hosting API: Creating a host application for the .NET Common Language Runtime.

    I hope this can help you resolve your problem.


    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, March 23, 2011 2:01 AM
    Wednesday, March 16, 2011 9:50 AM

All replies

  • Hi Diana,

    What is the 2.0 dll you are trying to use?

    When you switch your application to .net 4, any reference to any FCL library needs to point to version 4.

    In your case you need to change the reference to PresentationFramework.dll to version 4.


    Arturo
    Wednesday, March 16, 2011 6:30 AM
  • Hi Diana,

    Base on your description, I think your problem is related to CLR(Common Language Runtime). So I will move this thread to "CLR" forum. Thank you for understanding.


    Vin Jin [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.

    Wednesday, March 16, 2011 9:38 AM
  • Hi Diana,

     

    Welcome to the MSDN forum!

     

    This is because your original project targets .Net Framework 3.5 and the DLL targets .NET Framework 2.0.

    Both .NET Framework 3.5 and V2.0 loads CLR 2.0 so that your original application can run well.

    But .NET Framework 4.0 is different from version before. It loads CLR 4.0 which is not the same as the DLL. So exception occurred in the dll.

     

    The way to resolve the problem lists as below:

    1.       Rebuild the DLL to targets .NET Framework 4.0. But you need to make sure that the classes and methods in the DLL can support V4.0.

    2.       Fortunately, .NET Framework 4.0 supports to Load several versions of CLR in one process. You can forces to load CLR 2.0 when you using the DLL via CLR’s Hosting API: Creating a host application for the .NET Common Language Runtime.

    I hope this can help you resolve your problem.


    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, March 23, 2011 2:01 AM
    Wednesday, March 16, 2011 9:50 AM
  • Many thanks for the answers. I got from the vendor of this dll a version, which was built with .NET 4.0 and this worked then.
    Wednesday, March 23, 2011 2:07 PM