1

I have a project where I reference a third party assembly.

That assembly has x86 and x64 versions. I can only reference one, since the third party system relies on a specific one to work. (Depending on wich machine the system is installed)


Until now, I could manage both versions in a single project using this answer. So, I set the configuration manager option to x86 or x64 and it knows wich version to reference.

Targeting both 32bit and 64bit with Visual Studio in same solution/project


But then I came with the following problem: Needed to use a method from that assembly having version specific parameter type.

The x64 version has an IdToObject(long ID) method that doesn't exist in the x86.

The x86 version has an IdToObject(int ID) method that doesn't exist in the x64.

The ID is provided by another assembly of the same third party (that is not version specific). The ObjectID class gives me the ToInt32() and the ToInt64() methods.


If I try the IdToObject(ID.ToInt32()) in a x64 version, I get an overflow at runtime.

If I try the IdToObject(ID.ToInt64()) in a x86 version, doesn't compile (trying to pass long as int).

I've tried this, runs fine for the x64 version, but doesn't compile for the x86.

if (System.Reflection.Assembly.GetExecutingAssembly().GetName().ProcessorArchitecture == System.Reflection.ProcessorArchitecture.X86)
    return Document.IdToObject(ObjectID.ToInt32()); //returns an object
else
    return Document.IdToObject(ObjectID.ToInt64()); //returns an object

So, all I need is to avoid compiling a single line when project is set to x86, and another if project is set to x64. What can I do?

Community
  • 1
  • 1
Daniel Möller
  • 84,878
  • 18
  • 192
  • 214
  • Sounds like you might have to resort to using preprocessor directives? There may be another way but I don't know what it would be. http://msdn.microsoft.com/en-us/library/ed8yd1ha(v=vs.100).aspx – Tim B Jun 11 '13 at 19:36

1 Answers1

1

Looks like you will need to use a preprocessor directive. In your project properties for your 64-bit build configuration, add WIN64 under Build, Conditional compilation symbols. Then change your code to this:

#if WIN64
        return Document.IdToObject(ObjectID.ToInt64()); //returns an object
#else
        return Document.IdToObject(ObjectID.ToInt32()); //returns an object
#endif
Tim B
  • 2,340
  • 15
  • 21
  • The symbol can be anything you want. Feel free to reverse it, if you would prefer to add the symbol to your 32-bit build configuration. – Tim B Jun 11 '13 at 19:54