none
Full framework binaries on compact framework RRS feed

  • Question

  •  

    Hi All,

    I developed a dynamic linking library (dll) on .NET full framework.  This dll does not includes any platform invoke calls. And all the functions used by this dll supports .NET compact framework as well. My main concern is to use this same dll in .NET compact framework.

    So I am thinking of just using the same dll without recompiling on .NET compact framework.  So what are the recommendations about this approach? Please let me know the difficulties and complexities that could occur in this mechanism.

    Thank you,

    Sira Buwa.

    Tuesday, June 3, 2008 8:50 AM

Answers

  • The .NET Framework has a concept called retargeting - basically what this means is that, any assembly compiled against the .NET Compact Framework, will automatically work if run the .NET Framework. However, the reverse is not true.

    For this to work, however, you need to make sure that you only take dependancies on assemblies that either ship in the Compact Framework, or are compiled against the Compact Framework.


    Managed Extensibility Framework Team | My Blog: http://davesbox.com
    Friday, June 6, 2008 4:07 AM
    Moderator
  • Strongs names of certain Compact Framework assemblies (such as System.dll, System.Xml, etc) contain a bit called Retargetable=Yes. When an assembly that is compiled against these references is loaded on the .NET Framework ('Desktop') CLR, the CLR redirects the Compact Framework references (which have a different strong name as they have a different public key) with this bit set to their equivalent on Desktop Framework.

    For example, let's say we have an assembly that is compiled against System.dll, System.Xml.dll and System.Data.SqlClient.dll from the Compact Framework.

    When this assembly is loaded on the Desktop Framework, the CLR sees the Compact Framework references, and instead of attempting to load them, it redirects them to the Desktop equivalent, for example,

    Compact                                           Desktop
    System.dll                                     -> System.dll
    System.Xml.dll                               -> System.Xml.dll
    System.Data.SqlClient.dll              -> System.Data.dll

    As you can see, not only does the CLR redirect assemblies to the same name but different public key, but also can redirect Compact Framework assemblies to a different name and different public key.

    Now take note that this doesn't happen to every Compact Framework assembly; some do not have an equivalent version on the Desktop or some do not have the same APIs or more (which is required for this to work). Also note that this is a hard-coded list of assemblies, so it can not be added to.

    This scenario enables a library writer to build a single library against the lowest common denominator, in this case, Compact Framework, while still allow those targeting the Desktop Framework to take a reference to it.

    Another thing to note is that this only works for Compact Framework -> Desktop Framework. The reverse will not work, nor will this work for any other Framework, such as Silverlight 2.0 and the Micro.


    Managed Extensibility Framework Team | My Blog: http://davesbox.com
    Sunday, June 8, 2008 1:22 AM
    Moderator

All replies

  • You should post this question to the Smart Devices forum, left behind on the old forums site.  As long as the compiled assembly contains nothing but pure IL, there shouldn't be any problem.  Not so sure about the assembly references, use ildasm.exe to verify them.
    Hans Passant.
    Tuesday, June 3, 2008 12:05 PM
    Moderator
  • Hi Hans,

    Thank you very much. I post the question to following forum.

    http://forums.microsoft.com/msdn/ShowPost.aspx?PostID=3440215&SiteID=1

    But most of the time I got negation. Con you comment on them..

    Thank you,
    Sira Buwa.
    Thursday, June 5, 2008 4:55 AM
  • The .NET Framework has a concept called retargeting - basically what this means is that, any assembly compiled against the .NET Compact Framework, will automatically work if run the .NET Framework. However, the reverse is not true.

    For this to work, however, you need to make sure that you only take dependancies on assemblies that either ship in the Compact Framework, or are compiled against the Compact Framework.


    Managed Extensibility Framework Team | My Blog: http://davesbox.com
    Friday, June 6, 2008 4:07 AM
    Moderator
  • Well, you've marked your own post as the answer, but, what exactly does it mean?  I'm curious from the point of view of this forum's topic, the CLR.  You make it sound like the assembly references are indeed the problem.  The "retargeting" bit isn't all that clear.  Interpreting: some "targets" can be translated, some can not?  Please enlighten us with an answer.
    Hans Passant.
    Saturday, June 7, 2008 11:09 PM
    Moderator
  • Strongs names of certain Compact Framework assemblies (such as System.dll, System.Xml, etc) contain a bit called Retargetable=Yes. When an assembly that is compiled against these references is loaded on the .NET Framework ('Desktop') CLR, the CLR redirects the Compact Framework references (which have a different strong name as they have a different public key) with this bit set to their equivalent on Desktop Framework.

    For example, let's say we have an assembly that is compiled against System.dll, System.Xml.dll and System.Data.SqlClient.dll from the Compact Framework.

    When this assembly is loaded on the Desktop Framework, the CLR sees the Compact Framework references, and instead of attempting to load them, it redirects them to the Desktop equivalent, for example,

    Compact                                           Desktop
    System.dll                                     -> System.dll
    System.Xml.dll                               -> System.Xml.dll
    System.Data.SqlClient.dll              -> System.Data.dll

    As you can see, not only does the CLR redirect assemblies to the same name but different public key, but also can redirect Compact Framework assemblies to a different name and different public key.

    Now take note that this doesn't happen to every Compact Framework assembly; some do not have an equivalent version on the Desktop or some do not have the same APIs or more (which is required for this to work). Also note that this is a hard-coded list of assemblies, so it can not be added to.

    This scenario enables a library writer to build a single library against the lowest common denominator, in this case, Compact Framework, while still allow those targeting the Desktop Framework to take a reference to it.

    Another thing to note is that this only works for Compact Framework -> Desktop Framework. The reverse will not work, nor will this work for any other Framework, such as Silverlight 2.0 and the Micro.


    Managed Extensibility Framework Team | My Blog: http://davesbox.com
    Sunday, June 8, 2008 1:22 AM
    Moderator