SharpCrafters Forum – Error while loading the assembly (AMD64)

SharpCrafters Support Forum

        


Error while loading the assembly (AMD64) Expand / Collapse
Author
Message
Posted 4/23/2009 12:36:52 PM


Community Member
An error occurs during build process in Visual Studio 2005 class library project. There is a reference to assembly Microsoft.Office.Server.Search.dll which is build in processorArchitecture=AMD64. This assembly is installed into the GAC, however build task avoids to load it from there and keeps looking for it in another locations.
Finally the assembly is found, but loading process fails for some reasons.

Platform target for our project is "Any CPU", however depending on developer machine there is Sharepoint 32bit or 64bit installed and the processorArchitecture for some Sharepoint dlls (in this case Microsoft.Office.Server.Search.dll) may vary on different development workstations. On my particular machine it is x64 version, which causes the error, because build task is looking for MSIL or 32 version.

Stack trace:

Error 27 Unhandled exception: PostSharp.CodeModel.BindingException: Error while loading the assembly "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\ISAPI\Microsoft.Office.Server.Search.dll": Could not load file or assembly 'Microsoft.Office.Server.Search, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' or one of its dependencies. An attempt was made to load a program with an incorrect format.
===== PostSharp Assembly Binder =================
Resolving the assembly name 'Microsoft.Office.Server.Search'.
Looking in GAC for Microsoft.Office.Server.Search, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c.
Looking in GAC for Microsoft.Office.Server.Search, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c, processorArchitecture=x86.
Looking in GAC for Microsoft.Office.Server.Search, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c, processorArchitecture=MSIL.
Probing the file C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\ISAPI\Microsoft.Office.Server.Search.dll because this file was explicitely added to the search path.
This file has version 12.0.0.0. This is the higher version probed so far.
Loading assembly from file {C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\ISAPI\Microsoft.Office.Server.Search.dll}.
System.BadImageFormatException: Could not load file or assembly 'Microsoft.Office.Server.Search, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' or one of its dependencies. An attempt was made to load a program with an incorrect format.
File name: 'Microsoft.Office.Server.Search, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'
  at System.Reflection.Assembly.nLoadFile(String path, Evidence evidence)
  at System.Reflection.Assembly.LoadFile(String path)
  at PostSharp.CodeModel.AssemblyLoadHelper.LoadAssemblyFromFile(String fileName, Evidence assemblySecurity) in p:\branches\1.5\Core\PostSharp.Core\CodeModel\AssemblyLoadHelper.cs:line 174



=================================================

   
  at PostSharp.CodeModel.AssemblyLoadHelper.ManageAssemblyLoadException(String assemblyName, Exception e) in p:\branches\1.5\Core\PostSharp.Core\CodeModel\AssemblyLoadHelper.cs:line 108
  at PostSharp.CodeModel.AssemblyLoadHelper.LoadAssemblyFromFile(String fileName, Evidence assemblySecurity) in p:\branches\1.5\Core\PostSharp.Core\CodeModel\AssemblyLoadHelper.cs:line 181
  at PostSharp.CodeModel.AssemblyLoadHelper.LoadAssemblyFromFile(String fileName) in p:\branches\1.5\Core\PostSharp.Core\CodeModel\AssemblyLoadHelper.cs:line 157
  at PostSharp.CodeModel.Domain.GetAssembly(IAssemblyName assemblyName, BindingOptions bindingOptions) in p:\branches\1.5\Core\PostSharp.Core\CodeModel\Domain.cs:line 430
  at PostSharp.CodeModel.Domain.GetAssembly(IAssemblyName assemblyName) in p:\branches\1.5\Core\PostSharp.Core\CodeModel\Domain.cs:line 368
  at PostSharp.CodeModel.AssemblyRefDeclaration.GetAssemblyEnvelope() in p:\branches\1.5\Core\PostSharp.Core\CodeModel\AssemblyRefDeclaration.cs:line 153
  at PostSharp.Extensibility.Tasks.MulticastAttributeTask.AssemblyHasInheritedAttributes(AssemblyRefDeclaration assemblyRef) in p:\branches\1.5\Core\PostSharp.Core\Extensibility\Tasks\MulticastAttributeTask.cs:line 2749
  at PostSharp.Extensibility.Tasks.MulticastAttributeTask.ProcessInheritedAttributesAcrossAssemblies() in p:\branches\1.5\Core\PostSharp.Core\Extensibility\Tasks\MulticastAttributeTask.cs:line 2172
  at PostSharp.Extensibility.Tasks.MulticastAttributeTask.Execute() in p:\branches\1.5\Core\PostSharp.Core\Extensibility\Tasks\MulticastAttributeTask.cs:line 207
  at PostSharp.Extensibility.Project.ExecutePhase(String phase) in p:\branches\1.5\Core\PostSharp.Core\Extensibility\Project.cs:line 1224
  at PostSharp.Extensibility.Project.Execute() in p:\branches\1.5\Core\PostSharp.Core\Extensibility\Project.cs:line 1267
  at PostSharp.Extensibility.PostSharpObject.ExecuteProjects() in p:\branches\1.5\Core\PostSharp.Core\Extensibility\PostSharpObject.cs:line 617
  at PostSharp.Extensibility.PostSharpObject.InvokeProject(ProjectInvocation projectInvocation) in p:\branches\1.5\Core\PostSharp.Core\Extensibility\PostSharpObject.cs:line 548
  at PostSharp.MSBuild.PostSharpRemoteTask.Execute(PostSharpTaskParameters parameters, TaskLoggingHelper log) in p:\branches\1.5\Core\PostSharp.MSBuild\PostSharpRemoteTask.cs:line 113 DMS

Updated:

Probably the issue is located in FindAssemblyInCache method. Maybe be the logic of this method could be changed in the way, which allows to load processorArchitecture=AMD64 dlls from the GAC for "Any CPU" projects if MSIL and 32bit are not found there.
Post #3028
Posted 4/28/2009 9:00:59 AM


Gael Fraiteur

SharpCrafters
The cause is that PostSharp is in a 32-bit process (inside Visual Studio), so it cannot load 64-bit assemblies.

Use the MSBuild property PostSharpUseCommandLine=True to execute PostSharp as a new process -- which will be a 64-bit one.

See <!-- m --><a class="postlink" href="http://www.postsharp.org/tracker/view.php?id=334">http://www.postsharp.org/tracker/view.php?id=334</a><!-- m --> and monitor this issue for follow-up.

-gael
Post #3029
Posted 4/28/2009 10:50:07 AM


Community Member
I used the workaround you suggested (<PostSharpUseCommandLine>True</PostSharpUseCommandLine>) and I'm using postsharp.exe from PostSharp-1.5.3.508-Release-x64.msi , but it seems that it is still using x86 mode (look at the attachment) and the problem still occurs:

error: Unhandled exception: Error while loading the assembly "C:\Program Files\C
ommon Files\Microsoft Shared\Web Server Extensions\12\ISAPI\Microsoft.Office.Ser
ver.Search.dll": Could not load file or assembly 'Microsoft.Office.Server.Search
, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' or one of
its dependencies. An attempt was made to load a program with an incorrect format
.
===== PostSharp Assembly Binder =================
Resolving the assembly name 'Microsoft.Office.Server.Search, Version=12.0.0.0, C
ulture=neutral, PublicKeyToken=71e9bce111e9429c'.
Probing the file C:\Program Files\Common Files\Microsoft Shared\Web Server Exten
sions\12\ISAPI\Microsoft.Office.Server.Search.dll because this file was explicit
ely added to the search path.
This file has version 12.0.0.0. This is the higher version probed so far.
Loading assembly from file {C:\Program Files\Common Files\Microsoft Shared\Web S
erver Extensions\12\ISAPI\Microsoft.Office.Server.Search.dll}.
       System.BadImageFormatException: Could not load file or assembly 'Microso
ft.Office.Server.Search, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9b
ce111e9429c' or one of its dependencies. An attempt was made to load a program w
ith an incorrect format.
File name: 'Microsoft.Office.Server.Search, Version=12.0.0.0, Culture=neutral, P
ublicKeyToken=71e9bce111e9429c'
  at System.Reflection.Assembly.nLoadFile(String path, Evidence evidence)
  at System.Reflection.Assembly.LoadFile(String path)
  at PostSharp.CodeModel.AssemblyLoadHelper.LoadAssemblyFromFile(String fileNam
e, Evidence assemblySecurity) in p:\branches\1.5\Core\PostSharp.Core\CodeModel\A
ssemblyLoadHelper.cs:line 174
Post #3030
Posted 4/28/2009 10:57:06 AM


Gael Fraiteur

SharpCrafters
Are you sure the command-line utility is executed?
What is the last line of your trace stack?
In your first post, it was:

at PostSharp.MSBuild.PostSharpRemoteTask.Execute(PostSharpTaskParameters parameters, TaskLoggingHelper log) in p:\branches\1.5\Core\PostSharp.MSBuild\PostSharpRemoteTask.cs


i.e., it was the MSBuild task.

You should see PostSharp.Console in the stack trace.

-g
Post #3031
Posted 4/28/2009 11:51:39 AM


Community Member
In the output I see (btw, why x64 setup uses "program files (x86)" folder?):

"C:\Program Files (x86)\PostSharp 1.5\PostSharp.exe"    "C:\Program Files (x86)\PostSharp 1.5\Default.psproj" "obj\Debug\Before-PostSharp\ITDev.SharePoint.DMS.dll" "/P:Output=obj\Debug\ITDev.SharePoint.DMS.dll " "/P:ReferenceDirectory=N:\Projects\DMS\DMS " "/P:Configuration=Debug " "/P:Platform=AnyCPU " "/P:SearchPath=bin\Debug\,obj\Debug\, " "/P:IntermediateDirectory=obj\Debug\PostSharp " "/P:CleanIntermediate=False " "/P:MSBuildProjectFullPath=N:\Projects\DMS\DMS\DMS.csproj " "/P:SignAssembly=true " "/P:PrivateKeyLocation=N:\CodeSigning\ITDevKey.snk " "/P:ResolvedReferences=C:\Windows\Microsoft.NET\Framework\v2.0.50727\Accessibility.dll,Solution\Assemblies\AjaxControlToolkit.dll,Solution\Assemblies\ITDev.SharePoint.FieldTypes.FilteredLookup.dll,Packages\FilteredLookup\Solution\Assemblies\ITDev.SharePoint.FieldTypes.FilteredLookup.LookupDataSource.dll,..\..\..\Lib\Own\ITDev.SharePoint.Utilities.TraceLog.dll,N:\SharePoint\Workflow\ITDev.SharePoint.Workflow.Common\ITDev.SharePoint.Workflow.Common\bin\Debug\ITDev.SharePoint.Workflow.Common.dll,..\..\..\Lib\3rdparty\Manco.Licensing.Medium.dll,C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\ISAPI\Microsoft.Office.Server.dll,C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\ISAPI\Microsoft.Office.Server.Search.dll,..\..\..\Lib\Own\Microsoft.SharePoint.ApplicationPages.dll,C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\ISAPI\Microsoft.SharePoint.dll,C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\ISAPI\Microsoft.SharePoint.Publishing.dll,C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\ISAPI\Microsoft.SharePoint.Security.dll,C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\ISAPI\microsoft.sharepoint.WorkflowActions.dll,C:\Program Files (x86)\PostSharp 1.5\PostSharp.Laos.dll,C:\Program Files (x86)\PostSharp 1.5\PostSharp.Public.dll,C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Data.dll,C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll,C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Drawing.dll,C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.EnterpriseServices.dll,C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Web.dll,N:\Lib\3rdparty\System.Web.Extensions.dll,C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Web.Services.dll,C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.0\System.Workflow.Activities.dll,C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.0\System.Workflow.ComponentModel.dll,C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Xml.dll "
Post #3032
Posted 4/28/2009 12:17:34 PM


Gael Fraiteur

SharpCrafters
Platform is platform-neutral, so it is installed in x86.

But the command-line should be executed in 64 bit by default.

You may try to force a platform by using corflags.exe on PostSharp.

-g
Post #3033
Posted 4/28/2009 1:37:48 PM


Community Member
ok, coreflags.exe did the trick - oryginally postsharp.exe has 32bit flag.
thank you very much.
Post #3034
Posted 2/9/2010 1:06:39 PM


Community Member
Hi Team,

I am new to MSBuild, can you please give me details to configure my website and MSBuild to use PostSharp and make to use the 64 bit dll

Lakshmi
Post #3035
Posted 2/10/2010 3:45:32 PM


Gael Fraiteur

SharpCrafters
The best is probably to use PostSharp 2.0 since the problem has been solved there.
Post #3036
« Prev Topic | Next Topic »


All times are GMT +1:00, Time now is 11:44am

Powered By InstantForum.NET v4.1.4 © 2010
Execution: 0.215. 8 queries. Compression Disabled.