2

I am trying to upgrade a project from VS2005. It is a VB.NET project B that depends on a C# project that references a C++ dll, A.dll. I am getting an error saying 'Unable to find assembly A_class, Version 2.0.0.0, Culture=neutral, PublicKeyToken=null'. The targeted platform of the C++ project is 4.0 and since that project depends on others, I can't downgrade it. But I did set the platform for the VB.NET project to 4.0. What else does the Version 2.0.0.0 refer to ? I have tried to create a brand-new project and added the vb forms into it after I have built it successfully. The C++ dll is in the output directory, if the VB project doesn't find it there, it doesn't get to this point. During build. I either get no error (but forms don't load) or I get 2 errors (one for each form):

error MSB3103: Invalid Resx file. Could not load file or assembly 'A-class, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format. Line 136, position 5.

Please help me, give me a suggestion, I don't know where to look. thank you very much.

Thalia
  • 13,637
  • 22
  • 96
  • 190

1 Answers1

4

"An attempt was made to load a program with an incorrect format"

99% of the time this means you are trying to load a 32-bit assembly using 64-bit tools, or vice versa. The version number in the error message just means the version number of the assembly that it's trying to load; it has nothing to do with .NET version being targeted. In this case it appears that the resource compiler is what has issues.

Try configuring your solution to explicitly build x86 instead of Any CPU and see if that resolves your problem.

Michael Edenfield
  • 28,070
  • 4
  • 86
  • 117
  • It builds in x86 - I need it to build in x64, and there doesn't seem to be anything in the code that requires x86. As for the dependencies, they build fine in x64 and I verified the dlls with Dependency Walker. – Thalia Mar 23 '12 at 21:45
  • Is this a project dependency or a file dependency? AFAIK you can't switch back and forth between architectures when you add a reference directly to a file, as opposed to via a project reference (the architecture is even embedded into the reference.) – Michael Edenfield Mar 29 '12 at 01:57
  • I don't understand the question - though I think if I did I would be very close to fixing this problem. The VB project has two forms built using a UserControl, and in the UserControl there is a reference to a namespace from a C# project that is a wrapper for a c++ dll. Also, both the UserControl and one of the forms use a namespace from another VB project - that builds perfectly, and whose controls show up in the Toolbox. The UserControl from the main project seems to build fine, but it only shows up in the Toolbox in x86 (not in x64). – Thalia Mar 29 '12 at 22:29
  • The two forms don't show in design mode (they give an error about not recognizing the object built using the control) - but I can build the project - most of the time. The error I get when I can't is on one of the forms: it hates the import from the project that manages to place controls in the toolbox (and is set as a reference of course). I cheated, removed the code from that form, erased the data content of the resource file, and placed back the content in the form - and now I can build. – Thalia Mar 29 '12 at 22:32
  • So unless I try to look at the forms, I am fine - but I am not sure how this project will behave as a reference for other projects - I am building it as a class - and if it will not break at a subsequent build. And... I have to be able to build for x64. – Thalia Mar 29 '12 at 22:34
  • I actually thought, after I fixed the resource file, that I fixed the problem for good - it always seems to work and then it doesn't, every time I do something to fix this. Now your question makes me believe that the resx file contains the reference to the processor and gets rebuilt with a different config than what I want ? – Thalia Mar 29 '12 at 22:36
  • I have discovered something disturbing: I have tried to build the control I have, with no dependency. Also, I have downloaded a book code that builds a custom control. I have looked at it to learn - and it was running under MyCPU - but when I tried tu run as x64, I got an error - the same as for my complicated control: "Could not find type 'Chap15SampleCode.ListSelector'. Please make sure that the assembly that contains this type is referenced..." And "The variable 'ListSelector1' is either undeclared or was never assigned." – Thalia Mar 30 '12 at 18:48
  • There are also several warnings: Possible problem detected while building assembly 'Chap15SampleCode': Referenced assembly 'mscorlib.dll' targets a different processor; Same about System.Data.dll. System.Data as a Reference is in c:\Windows\Microsoft.NET\Framework... (in my projects it was in c:\ProgramFiles(x86)\... and I tried to change it, I couldn't but maybe that is not the problem ?) – Thalia Mar 30 '12 at 18:52
  • Instead of leaving a lot of comments in a row, it's better to just edit your original question to include additional information. (I'm still reading your comments, I will hopefully have a better answer for your soon.) – Michael Edenfield Mar 30 '12 at 19:18