The Dev Guy

The Dev Guy

Sunday, February 19, 2012

Dynamics SL 2011 SDK and Visual Studio 2010, 32 and 64 bit issues

Goal 
To Develop in Visual Studio 2010 projects that create custom screens in Microsoft Dynamics SL 2011.  

Environment
64-bit Everything: SQL Server, Application Server and your development machine are all 64 bit. Note SL is still a 32 bit app.

Issue
            You create a project in VS 2010 for SL Dynamics and put any control on the screen from the Dynamics SAFControl Collection. You run the screen or you compile and run the exe. You get an error stating:
Description:
Stopped working
Problem signature:
Problem Event Name: CLR20r3
Problem Signature 01: gevci00.exe
Problem Signature 02: 1.0.0.0
Problem Signature 03: 4f1d46a9
Problem Signature 04: Microsoft.VisualBasic
Problem Signature 05: 8.0.0.0
Problem Signature 06: 4ca2d138
Problem Signature 07: 5b
Problem Signature 08: 2c
Problem Signature 09: System.IO.FileNotFoundException
OS Version: 6.1.7601.2.1.0.16.7
Locale ID: 1033
Read our privacy statement online:
If the online privacy statement is not available, please read our privacy statement offline:
C:\Windows\system32\en-US\erofflps.txt

Notice that the error is a File not found error. What is basically happening is that VS 2010 is confusing SL 2011 Components and assuming they are 64 bit. It cannot find the dll in the location where it looks for 64 bit components.  
            This problem existed in VS 2008 as well. But things were less 64 bit in those days. Now the entire platform is 64 bit, everything but SL.
            The reason for this is that the existing articles out there don’t give the best way to get around this issue. They list all the work arounds no matter how silly or single machine based:
http://blogs.msdn.com/b/visualstudio/archive/2010/06/19/resgen-exe-error-an-attempt-was-made-to-load-a-program-with-an-incorrect-format.aspx
for completeness they get an A++ but for getting me quickly through an issue I had the grades are not so high. So here I walk through the best steps to get around this issue.

Resolution
           
The steps:
1)      Make ResGen.exe 32 bit
2)      Change Project File to have new entry
3)      Change Properties of project Target CPU.
Step One
This step will make all references be treated as 32 bit. If your project uses 64 bit references and 32 bit then you will get file not found errors for 64 instead of 32. Same error in a different direction. So keep that in mind but when creating SL screens you are most likely still all 32 bit.
-Goto Start > Run > type cmd and hit enter
-Type following and hit enter:     
Cd “%ProgramFiles(x86)%\Microsoft SDKs\Windows\v7.0A\Bin”
-Type following and hit enter:     
Corflags /32Bit+ /Force ResGen.exe

Step Two
·         Open Notepad.
·         Click on open and go to your project directory.
·         select the ProjectName.vbproj file.
·         The File starts like this:
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
  <PropertyGroup>
    <ProjectType>Local</ProjectType>
    <MyType>WindowsForms</MyType>
    <ProductVersion>8.0.50727</ProductVersion>
·         Change to:
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
  <PropertyGroup>
    <ResGenToolArchitecture>Managed32Bit</ResGenToolArchitecture>
    <ProjectType>Local</ProjectType>
    <MyType>WindowsForms</MyType>
    <ProductVersion>8.0.50727</ProductVersion>
·         Hit Save


Step Three
·         Open Project in Visual Studio
·         Select the Project Level in Project Explorer
·         Right Mouse and select properties > Click on Compile > Advanced Compile Options


·         Change Target CPU to x86
·         Hit Save


Conclusion 

            The documentation on work arounds for 64 bit issues with VS 2010 are numerous, none specifically state what is best for Dynamics SL 2011. This attempts to do that.