Retargetable=Yes

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want to know if I can use the Retargetable attribute for my own assemblies.
I want to be able to run my Compact Framework assemblies on the desktop, but
I need to make a different assembly for the desktop but with the same
contract. The new assembly will have a different public key. So, my idea is
to tag this assembly has Retargetable. I put the flags in the assembly :

([assembly: AssemblyFlags((int)(AssemblyNameFlags.PublicKey |
AssemblyNameFlags.Retargetable))]

I see in the IL that the assembly is retargetable.

But now when I run on the desktop, I receive a error that the assembly is
not valid.

In brief: How can I use the Retargetable flag for my own assemblies? And how
the CLR know which public key correspond to the other? I want to do the
exactly same thing the Compact Framework assemblies do with Retargetable.

Thanks in advance.
 
Sorry, I don't understand what you are trying to do.

Let's start with some facts:
1. CF assemblies are retargetable
2. Full Fx assemblies are not
3. You can run CF apps on the desktop (assuming you don't use
device-specific functionality)
4. You cannot run desktop apps on the device._
5. For more: http://www.danielmoth.com/Blog/2004/09/retargetable-256.html

If you want to share code in that manner just create Smart Device projects
and then run the outputs on the desktop.

Have you some reason for creating a non-CF project and trying to force that
to run on both platforms or is it something else that you are trying?

Cheers
Daniel
 
Thanks for the response. I have already read your blog on this before asking
this question (very interresting blog by the way :) I know the CF assemblies
can run on the desktop. Here is what I want to do:

I want to write a assembly for the full framework and another one for the
comapct framework, but keeping the same contract (functions, classes, etc.),
the same way the compact framework is in respect to full framework (less
functions, but the present one have the same signature, which cause the
retargetable to work).

The reason I want to do this is because one of my core assembly (name it
AccessDriver.dll) need to call ntive core.dll functions (to talk to a driver)
and on the desktop, it's not the same DLL (kernel32.dll). There are other
differences too (the equivalent driver on the desktop has not the exactly the
same interface). I know I can make contionnals statements in the code, but
this can rapidly become a little bit ugly, and difficult to debug). If I can
make a new AccessDriver.dll assembly with the same fonctionnalities but
making the code inside different to be able to run on desktop, the assemblies
that are using AccessDriver.dll will only have to bind to this new one when
run on full framework (exactly the same way the retargetable attribute make
CF assemblies bind to the full framework assemblies when run on desktop).

So, my question is: How do I make a retargetable assembly? What are the
steps I need to do to make it work? I found no documentation on this on the
web, so I don't even know if it's possible.

Hope my wuestion is more clear. Thanks again for your help.

Daniel Moth said:
Sorry, I don't understand what you are trying to do.

Let's start with some facts:
1. CF assemblies are retargetable
2. Full Fx assemblies are not
3. You can run CF apps on the desktop (assuming you don't use
device-specific functionality)
4. You cannot run desktop apps on the device._
5. For more: http://www.danielmoth.com/Blog/2004/09/retargetable-256.html

If you want to share code in that manner just create Smart Device projects
and then run the outputs on the desktop.

Have you some reason for creating a non-CF project and trying to force that
to run on both platforms or is it something else that you are trying?

Cheers
Daniel
--
http://www.danielmoth.com/Blog/


Nic said:
I want to know if I can use the Retargetable attribute for my own
assemblies.
I want to be able to run my Compact Framework assemblies on the desktop,
but
I need to make a different assembly for the desktop but with the same
contract. The new assembly will have a different public key. So, my idea
is
to tag this assembly has Retargetable. I put the flags in the assembly :

([assembly: AssemblyFlags((int)(AssemblyNameFlags.PublicKey |
AssemblyNameFlags.Retargetable))]

I see in the IL that the assembly is retargetable.

But now when I run on the desktop, I receive a error that the assembly is
not valid.

In brief: How can I use the Retargetable flag for my own assemblies? And
how
the CLR know which public key correspond to the other? I want to do the
exactly same thing the Compact Framework assemblies do with Retargetable.

Thanks in advance.
 
The best solution in your case is to use different projects for each
AccessDriver version - AccessDriverCF and another AccessDriverFull. This
two projects include the same files but with one different; the
AccessDriverCF will define CF macros. It gives you opportunity to share
the same code between 2 projects and modify it based on platform - here
is a small example:

#if CF
[DllImport("coredll.dll")]
#else
[DllImport("user32.dll")]
#endif
public static IntPtr GetCapture();


Best regards,
Sergey Bogdanov
 
OK the word "contract" threw me, it is best to say "expose the same
interface" or something like that... Also your explicit use of Retargetable
was confusing, you do not have to do that; CF assemblies are, Full Fx
aren't, that's it (without explicit use of any attributes).

So you basically want to have a dll behave differently on the desktop than
what on the CF. You have two options:
1. Decide at compile time what code runs on each platform
2. Decide at runtime

Option 1 is my preferred way of doing it, and although you found my blog
maybe you haven't read the entry which covers the topic of the compile time
technique:
http://www.danielmoth.com/Blog/2004/09/share-code-if-fullframe_17.html
A quick example:
#if FULL_FRAME
const string NariveDll = "kernel32.dll";
#else
const string NariveDll = "coredll.dll";
#endif
[DllImport (NariveDll)]
private static extern int GetTickCount();


Option 2 requires that you detect at runtime what platform you are on and
run the appropriate code. E.g:
if (System.Environment.OSVersion.Platform == PlatformID.WinCE){
' do CF stuff
}else{
' do Full fx stuff
}

Cheers
Daniel
--
http://www.danielmoth.com/Blog/


Nic said:
Thanks for the response. I have already read your blog on this before
asking
this question (very interresting blog by the way :) I know the CF
assemblies
can run on the desktop. Here is what I want to do:

I want to write a assembly for the full framework and another one for the
comapct framework, but keeping the same contract (functions, classes,
etc.),
the same way the compact framework is in respect to full framework (less
functions, but the present one have the same signature, which cause the
retargetable to work).

The reason I want to do this is because one of my core assembly (name it
AccessDriver.dll) need to call ntive core.dll functions (to talk to a
driver)
and on the desktop, it's not the same DLL (kernel32.dll). There are other
differences too (the equivalent driver on the desktop has not the exactly
the
same interface). I know I can make contionnals statements in the code, but
this can rapidly become a little bit ugly, and difficult to debug). If I
can
make a new AccessDriver.dll assembly with the same fonctionnalities but
making the code inside different to be able to run on desktop, the
assemblies
that are using AccessDriver.dll will only have to bind to this new one
when
run on full framework (exactly the same way the retargetable attribute
make
CF assemblies bind to the full framework assemblies when run on desktop).

So, my question is: How do I make a retargetable assembly? What are the
steps I need to do to make it work? I found no documentation on this on
the
web, so I don't even know if it's possible.

Hope my wuestion is more clear. Thanks again for your help.

Daniel Moth said:
Sorry, I don't understand what you are trying to do.

Let's start with some facts:
1. CF assemblies are retargetable
2. Full Fx assemblies are not
3. You can run CF apps on the desktop (assuming you don't use
device-specific functionality)
4. You cannot run desktop apps on the device._
5. For more: http://www.danielmoth.com/Blog/2004/09/retargetable-256.html

If you want to share code in that manner just create Smart Device
projects
and then run the outputs on the desktop.

Have you some reason for creating a non-CF project and trying to force
that
to run on both platforms or is it something else that you are trying?

Cheers
Daniel
--
http://www.danielmoth.com/Blog/


Nic said:
I want to know if I can use the Retargetable attribute for my own
assemblies.
I want to be able to run my Compact Framework assemblies on the
desktop,
but
I need to make a different assembly for the desktop but with the same
contract. The new assembly will have a different public key. So, my
idea
is
to tag this assembly has Retargetable. I put the flags in the assembly
:

([assembly: AssemblyFlags((int)(AssemblyNameFlags.PublicKey |
AssemblyNameFlags.Retargetable))]

I see in the IL that the assembly is retargetable.

But now when I run on the desktop, I receive a error that the assembly
is
not valid.

In brief: How can I use the Retargetable flag for my own assemblies?
And
how
the CLR know which public key correspond to the other? I want to do the
exactly same thing the Compact Framework assemblies do with
Retargetable.

Thanks in advance.
 
Ok, so if I understand you well, it's impossible to me to use this attribute:
[assembly: AssemblyFlags((int)AssemblyNameFlags.Retargetable))]

in my own assemblies? This attribute can only be used by Microsoft?

This question comes to me because in the MSDN documentation of this
attribute, it's possible to "retarget" assemblies to a different publisher
(another public key). So, I thinked it was possbile to to the same thing then
Microsoft and retarget my own CF assemblies to prevent me from having to deal
with "old C" #define statements in my code. I come from the COM world and
fall in love with interfaces based coding, which hide specific implementation
to the user by giving the same interface. I only wanted to find the
equivalent in .NET. Another solution to me is to declare a abstract class and
make two implementations, one for the desktop, and one for the compact
framework, and use some kind of late binding creation of the correct assembly
depending on the platform type.

Thanks again for your help. If you have another suggestions, please let me
know in this topic.

Daniel Moth said:
OK the word "contract" threw me, it is best to say "expose the same
interface" or something like that... Also your explicit use of Retargetable
was confusing, you do not have to do that; CF assemblies are, Full Fx
aren't, that's it (without explicit use of any attributes).

So you basically want to have a dll behave differently on the desktop than
what on the CF. You have two options:
1. Decide at compile time what code runs on each platform
2. Decide at runtime

Option 1 is my preferred way of doing it, and although you found my blog
maybe you haven't read the entry which covers the topic of the compile time
technique:
http://www.danielmoth.com/Blog/2004/09/share-code-if-fullframe_17.html
A quick example:
#if FULL_FRAME
const string NariveDll = "kernel32.dll";
#else
const string NariveDll = "coredll.dll";
#endif
[DllImport (NariveDll)]
private static extern int GetTickCount();


Option 2 requires that you detect at runtime what platform you are on and
run the appropriate code. E.g:
if (System.Environment.OSVersion.Platform == PlatformID.WinCE){
' do CF stuff
}else{
' do Full fx stuff
}

Cheers
Daniel
--
http://www.danielmoth.com/Blog/


Nic said:
Thanks for the response. I have already read your blog on this before
asking
this question (very interresting blog by the way :) I know the CF
assemblies
can run on the desktop. Here is what I want to do:

I want to write a assembly for the full framework and another one for the
comapct framework, but keeping the same contract (functions, classes,
etc.),
the same way the compact framework is in respect to full framework (less
functions, but the present one have the same signature, which cause the
retargetable to work).

The reason I want to do this is because one of my core assembly (name it
AccessDriver.dll) need to call ntive core.dll functions (to talk to a
driver)
and on the desktop, it's not the same DLL (kernel32.dll). There are other
differences too (the equivalent driver on the desktop has not the exactly
the
same interface). I know I can make contionnals statements in the code, but
this can rapidly become a little bit ugly, and difficult to debug). If I
can
make a new AccessDriver.dll assembly with the same fonctionnalities but
making the code inside different to be able to run on desktop, the
assemblies
that are using AccessDriver.dll will only have to bind to this new one
when
run on full framework (exactly the same way the retargetable attribute
make
CF assemblies bind to the full framework assemblies when run on desktop).

So, my question is: How do I make a retargetable assembly? What are the
steps I need to do to make it work? I found no documentation on this on
the
web, so I don't even know if it's possible.

Hope my wuestion is more clear. Thanks again for your help.

Daniel Moth said:
Sorry, I don't understand what you are trying to do.

Let's start with some facts:
1. CF assemblies are retargetable
2. Full Fx assemblies are not
3. You can run CF apps on the desktop (assuming you don't use
device-specific functionality)
4. You cannot run desktop apps on the device._
5. For more: http://www.danielmoth.com/Blog/2004/09/retargetable-256.html

If you want to share code in that manner just create Smart Device
projects
and then run the outputs on the desktop.

Have you some reason for creating a non-CF project and trying to force
that
to run on both platforms or is it something else that you are trying?

Cheers
Daniel
--
http://www.danielmoth.com/Blog/


I want to know if I can use the Retargetable attribute for my own
assemblies.
I want to be able to run my Compact Framework assemblies on the
desktop,
but
I need to make a different assembly for the desktop but with the same
contract. The new assembly will have a different public key. So, my
idea
is
to tag this assembly has Retargetable. I put the flags in the assembly
:

([assembly: AssemblyFlags((int)(AssemblyNameFlags.PublicKey |
AssemblyNameFlags.Retargetable))]

I see in the IL that the assembly is retargetable.

But now when I run on the desktop, I receive a error that the assembly
is
not valid.

In brief: How can I use the Retargetable flag for my own assemblies?
And
how
the CLR know which public key correspond to the other? I want to do the
exactly same thing the Compact Framework assemblies do with
Retargetable.

Thanks in advance.
 
Nic, your CF assembly can already run on both platforms; what is the point
of applying the attribute?

The "old style" compile time constants are not old style at all e.g. look at
DEBUG and TRACE constants that all managed projects have.

I also come from a COM background and too love interfaces. That is
orthogonal to what we are discussing here.

Your client code will indeed program against an interface; the compilation
constant is used in the server-side code so you are not losing anything
apart from having to distribute different assemblies for the two platforms.

If you *really* want to use the same binary, I have described the
alternative approach of checking at runtime which platform you are on;
again, that is in the provider code, the calling code is oblivious to the
fact.

Cheers
Daniel
--
http://www.danielmoth.com/Blog/


Nic said:
Ok, so if I understand you well, it's impossible to me to use this
attribute:
[assembly: AssemblyFlags((int)AssemblyNameFlags.Retargetable))]

in my own assemblies? This attribute can only be used by Microsoft?

This question comes to me because in the MSDN documentation of this
attribute, it's possible to "retarget" assemblies to a different publisher
(another public key). So, I thinked it was possbile to to the same thing
then
Microsoft and retarget my own CF assemblies to prevent me from having to
deal
with "old C" #define statements in my code. I come from the COM world and
fall in love with interfaces based coding, which hide specific
implementation
to the user by giving the same interface. I only wanted to find the
equivalent in .NET. Another solution to me is to declare a abstract class
and
make two implementations, one for the desktop, and one for the compact
framework, and use some kind of late binding creation of the correct
assembly
depending on the platform type.

Thanks again for your help. If you have another suggestions, please let me
know in this topic.

Daniel Moth said:
OK the word "contract" threw me, it is best to say "expose the same
interface" or something like that... Also your explicit use of
Retargetable
was confusing, you do not have to do that; CF assemblies are, Full Fx
aren't, that's it (without explicit use of any attributes).

So you basically want to have a dll behave differently on the desktop
than
what on the CF. You have two options:
1. Decide at compile time what code runs on each platform
2. Decide at runtime

Option 1 is my preferred way of doing it, and although you found my blog
maybe you haven't read the entry which covers the topic of the compile
time
technique:
http://www.danielmoth.com/Blog/2004/09/share-code-if-fullframe_17.html
A quick example:
#if FULL_FRAME
const string NariveDll = "kernel32.dll";
#else
const string NariveDll = "coredll.dll";
#endif
[DllImport (NariveDll)]
private static extern int GetTickCount();


Option 2 requires that you detect at runtime what platform you are on and
run the appropriate code. E.g:
if (System.Environment.OSVersion.Platform == PlatformID.WinCE){
' do CF stuff
}else{
' do Full fx stuff
}

Cheers
Daniel
--
http://www.danielmoth.com/Blog/


Nic said:
Thanks for the response. I have already read your blog on this before
asking
this question (very interresting blog by the way :) I know the CF
assemblies
can run on the desktop. Here is what I want to do:

I want to write a assembly for the full framework and another one for
the
comapct framework, but keeping the same contract (functions, classes,
etc.),
the same way the compact framework is in respect to full framework
(less
functions, but the present one have the same signature, which cause the
retargetable to work).

The reason I want to do this is because one of my core assembly (name
it
AccessDriver.dll) need to call ntive core.dll functions (to talk to a
driver)
and on the desktop, it's not the same DLL (kernel32.dll). There are
other
differences too (the equivalent driver on the desktop has not the
exactly
the
same interface). I know I can make contionnals statements in the code,
but
this can rapidly become a little bit ugly, and difficult to debug). If
I
can
make a new AccessDriver.dll assembly with the same fonctionnalities but
making the code inside different to be able to run on desktop, the
assemblies
that are using AccessDriver.dll will only have to bind to this new one
when
run on full framework (exactly the same way the retargetable attribute
make
CF assemblies bind to the full framework assemblies when run on
desktop).

So, my question is: How do I make a retargetable assembly? What are the
steps I need to do to make it work? I found no documentation on this on
the
web, so I don't even know if it's possible.

Hope my wuestion is more clear. Thanks again for your help.

:

Sorry, I don't understand what you are trying to do.

Let's start with some facts:
1. CF assemblies are retargetable
2. Full Fx assemblies are not
3. You can run CF apps on the desktop (assuming you don't use
device-specific functionality)
4. You cannot run desktop apps on the device._
5. For more:
http://www.danielmoth.com/Blog/2004/09/retargetable-256.html

If you want to share code in that manner just create Smart Device
projects
and then run the outputs on the desktop.

Have you some reason for creating a non-CF project and trying to force
that
to run on both platforms or is it something else that you are trying?

Cheers
Daniel
--
http://www.danielmoth.com/Blog/


I want to know if I can use the Retargetable attribute for my own
assemblies.
I want to be able to run my Compact Framework assemblies on the
desktop,
but
I need to make a different assembly for the desktop but with the
same
contract. The new assembly will have a different public key. So, my
idea
is
to tag this assembly has Retargetable. I put the flags in the
assembly
:

([assembly: AssemblyFlags((int)(AssemblyNameFlags.PublicKey |
AssemblyNameFlags.Retargetable))]

I see in the IL that the assembly is retargetable.

But now when I run on the desktop, I receive a error that the
assembly
is
not valid.

In brief: How can I use the Retargetable flag for my own assemblies?
And
how
the CLR know which public key correspond to the other? I want to do
the
exactly same thing the Compact Framework assemblies do with
Retargetable.

Thanks in advance.
 
Back
Top