Share via


AnyCPU/Prefer 32-bit/Class Library

Question

Monday, June 17, 2013 11:12 AM

Hi,

I am a little confused:

Using AnyCPU as platform target, and having a executable project (ConsolApp, or WindowsApp) I can select/deselect "Prefere 32-bit" while in a Class Library this option is disabled for changes.

  • Why is that?
  • If I uncheck "Prefere 32-bit" do I then get a 64-bit process automatically ?
  • what happens to the "Class Libraries" in a solution, if the related executabel project is set one or the other way?

Also, in my case I need to make use of a 64-bit native C dll. I realized, that if I use "AnyCPU" and uncheck "Prefere 32-bit" I can make use of the 64-bit dll from within my "API Wrapper Class Library". Is this the right way to do it, or am I now just lucky that I can access the dll ?

Thanks for any clarification on this subject!

Regard
Rainer

All replies (8)

Monday, June 17, 2013 1:00 PM ✅Answered | 1 vote

Hello,

Here is a healthy discussion on AnyCPU

http://stackoverflow.com/questions/516730/what-does-the-visual-studio-any-cpu-target-mean

Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.


Tuesday, June 18, 2013 5:51 AM ✅Answered

Thanks for Kevininstructor’s help.

Hi Rainer,

In addition, I think you would get more useful information about the Prefer 32-bit and Any CPU from the following documents:

What is the purpose of the “Prefer 32-bit” setting in Visual Studio 2012 and how does it actually work?

What AnyCPU Really Means As Of .NET 4.5 and Visual Studio 11

Between “Any CPU 32-bit preferred” and “x86” is only this: a .NET application compiled to x86 will fail to run on an ARM Windows system, but an “Any CPU 32-bit preferred” application will run successfully.

Best Regards,

Jack Zhai [MSFT]
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.


Thursday, June 20, 2013 2:21 AM ✅Answered

Hi,

How am I supposed to treat class libraries then for different targets?

I think you could get more useful information from this thread:

http://social.msdn.microsoft.com/Forums/vstudio/en-US/260e27c0-f67c-4eb5-a69e-8e5999d2c4f6/using-32-or-64bit-dll-with-anycpu-dll

I discuss with the CLR expert, the result is that we have to use the same target. I mean that your app would load the same 32/64bit .dll files like the above link.

Best Regards,

Jack Zhai [MSFT]
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.


Thursday, June 20, 2013 7:11 AM ✅Answered

Hi Jack,

thank you very much for your help!

So I resume:

The most flexible way would be to set the target platform of a class library to "AnyCPU". This then means, that this assembly gets JITed to what ever the "using" Process is running as (64/32-Bit), right?

Please correct me if that is wrong. Otherwise I consider my Questions as answered and thank every body for his help.

Regards
Rainer


Tuesday, June 18, 2013 6:59 AM

Kevininstructor, Jack,

thank you both for your help and links!

I still need to do a little more reading, but the subject already starts to clear up ;-)

What I have (so far) not found a answer to is : Why is Prefere 32-bit disabled in class libraries?Will they automatically adapt? What if I have a Solution of Libraries only ?

Best Regards
Rainer


Wednesday, June 19, 2013 3:10 AM

Hi,

As my understanding, it just supports the executable project, so it's disabled for class libraries.

Reference:

http://stackoverflow.com/questions/16546886/why-the-checkbox-prefer-32-bit-is-disabled-in-visual-studio-2012

Best Regards,

Jack Zhai [MSFT]
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.


Wednesday, June 19, 2013 11:10 AM

Hello Jack,

I got that, but it does not answer my question "WHY" is it disabled for class libraries?
How am I supposed to treat class libraries then for different targets?

Regards
Rainer


Thursday, June 20, 2013 8:08 AM

You are correct :)

Have a nice day,

Jack Zhai [MSFT]
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.