Results 1 to 13 of 13

Thread: x86 Application calling "AnyCPU" User Control

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2009
    Posts
    739

    x86 Application calling "AnyCPU" User Control

    I'm building a UserControl which will be used by other developers.

    If I build the UserControl for "AnyCPU" will there be any problems if another developer uses my UC in an application which he builds for x86.

    I mean if the complete application is running on a 32 bit machine then all should be OK but if the app is running on a 64bit machine then the x86 app will run on wow64 but where does my UC run ? In native 64bit or does it default to the same as the parent ?

    Or do I have to make x86 and x64 versions of my UC ?

    Or what ?

    Thanks
    Ian

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: x86 Application calling "AnyCPU" User Control

    What happened when you tried it for yourself?

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2009
    Posts
    739

    Re: x86 Application calling "AnyCPU" User Control

    Actually the UserControl is part of an application I'm working on. I'm developing the UC and the application in the same solution at the same time so don't have any cpu mismatch problems as yet. I'd like to build this for AnyCPU.

    But once this project is complete my next project will be to take the user control on its own and develop it further so that I, and colleagues, can use it in other projects.

    Hence my question - if I eventually build the UC for AnyCPU is that going to cause a problem if I later build a new x86 application that calls that UC.

    I'd have thought there'd be some well known rule about such things.

    Thank you - I really do appreciate it.
    Last edited by IanS; Nov 9th, 2010 at 05:13 AM.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: x86 Application calling "AnyCPU" User Control

    Quote Originally Posted by IanS View Post
    Actually the UserControl is part of an application I'm working on. I'm developing the UC and the application in the same solution at the same time so don't have any cpu mismatch problems as yet. I'd like to build this for AnyCPU.

    But once this project is complete my next project will be to take the user control on its own and develop it further so that I, and colleagues, can use it in other projects.
    None of that is relevant. Create a couple of new projects in the particular configuration you're interested in and run them. It will take you a couple of minutes.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2009
    Posts
    739

    Re: x86 Application calling "AnyCPU" User Control

    But I don't yet have a working UC that I can compile - I haven't got to that stage yet.

    I read very often on this forum that people have a working solution but then somebody else with more knowledge pops up saying that even though it works it isn't standard practice and they should do it a different way.

    I'm just curious about if there is any recommendation from MS - I mean even if I did the test and came back and said everything works you or somebody else might then come back and recommend something else.

    So, I'm not asking anyone to do the work for me - I'm just asking if there is a standard/recommended way to do it - If there's an MS document that I've missed then please just point me at it and I'll do the actual reading.

    Thanks
    Ian

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: x86 Application calling "AnyCPU" User Control

    You need to stop thinking about your current project. Your current project is COMPLETELY IRRELEVANT. All that matters is the principle. Create a new Windows Control Library project and compile it. Create a Windows Forms Application project. Add the UC from the library project to the form in the application project. That is ALL you have to do. You don't care AT ALL about functionality, so you don't have to add any. All you care about is whether a UC from a project targeting Any CPU can be used in a project targeting x86, so that's all you have test. This is VERY simple and you're trying to make it complicated. If you want to test a specific thing, isolate that specific thing and test it. Adding anything else just complicates things for no gain.

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2009
    Posts
    739

    Re: x86 Application calling "AnyCPU" User Control

    If you read my last post you'd realize I'm not talking about my current project. Ignore my current project.

    I understand that you want me to create a UC and an exe (various combinations x86, x64, anycpu etc) and test that to see what works - I understand that - I'm not that slow in the head.

    But just because the test shows that it works doesn't mean that it's the recommended solution.

    I'm not looking for a method that works - I'm asking that of the few methods/combination that work is there is a recommended method of doing something.
    Last edited by IanS; Nov 9th, 2010 at 03:05 PM.

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2009
    Posts
    739

    Re: x86 Application calling "AnyCPU" User Control

    Let me ask a completely different question.

    I'm a complete beginner and I'm thinking of making a UserControl that might be used by me and other people later in other projects. Should I target my UserControl for x86, x64 or AnyCPU ?

    More than one of those might well work - but which is recommended ?

  9. #9
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: x86 Application calling "AnyCPU" User Control

    An 32-bit assembly can only be referenced by other 32-bit assemblies and a 64-bit assembly can only be referenced by other 64-bit assemblies. It's that simple.

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2009
    Posts
    739

    Re: x86 Application calling "AnyCPU" User Control

    After all that then what you're saying is that I probably have to build two (three) UserControls. One for x86 and one for x64 and (and one for AnyCPU?) so that the person building his EXE can bundle the correct UserControl with his deployment.

    Or would it be better if I'd make the UserControl source file available and then the developer would be able to add that right into his own solution before he builds and then he can build any way he wants.

    You see where I'm coming from? I'm sure there are more than one way to do something but there's also the 'recommended' way to do something.

    If you were making a UC that would be used by other developers how would 'you' deploy it to those developers?

  11. #11
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: x86 Application calling "AnyCPU" User Control

    You should create whatever you think is needed. If you think all three would be needed then create all three.

  12. #12
    Hyperactive Member imadthemad's Avatar
    Join Date
    May 2005
    Posts
    344

    Re: x86 Application calling "AnyCPU" User Control

    personally i default everything to x86
    not just for debugging purposes, but also because for some reason if you build AnyCPU app and reference something 32bit, then if you run the app on a 64bit windows, you will get an error because the program will try to run as 64bit and like jmcilhiney said, 64bit can only reference 64bit, and if you have referenced only 32bit then there's your error...
    i've downloaded programs built in .net that have this issue and i've had to use the corflags.exe to switch the AnyCPU to 32bit.

    in your case however since the app is in 32bit and you are referencing something compiled as anycpu, then it will run on both 32bit and 64bit processors as 32bit, and will reference in both cases 32bit (not 64)

    in other words, even if your reference is anycpu, that just means any program can reference it. If a 32bit program references it, the reference acts as if x86, EVEN ON 64bit pc (because the program referencing it is 32bit)
    Basketball-NBA Dream status - quit
    Programming-Next Bill Gates Dream status - quit
    Becoming a doctor dream - LIVING IT: Med 2\4

  13. #13

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2009
    Posts
    739

    Re: x86 Application calling "AnyCPU" User Control

    Quote Originally Posted by imadthemad View Post
    in other words, even if your reference is anycpu, that just means any program can reference it. If a 32bit program references it, the reference acts as if x86, EVEN ON 64bit pc (because the program referencing it is 32bit)
    Thank you - that's what I've been trying t get at.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width