4

I have a utils class library project that includes some Sharepoint functionality. The project references Microsoft.Sharepoint.dll (copy local is set to false). We have many other projects that reference our utils dll and whenever we build them Microsoft.Sharepoint.Sandbox.dll is copied to the bin folder of these apps. Then when running any of the apps I get the following error:

Could not load file or assembly 'Microsoft.Sharepoint.Sandbox' or one of its dependencies. An attempt was made to load a program with an incorrect format.

Deleting the dll fixes the problem.. Is there a way to stop this Microsoft.Sharepoint.Sandbox.dll from being copied into the bin folder? I don't want to use post build scripts because there are many projects that reference the utils project and we will still have to manually delete the dll when deploying.

I can reproduce as follows:

1) Create a new solution

2) Add a class library project called utils

3) Reference Microsoft.Sharepoint.dll

4) Class1.cs:

namespace Utils
{
    public class Class1
    {

        public void testMeth()
        {
            Microsoft.SharePoint.DefaultItemOpen c; 
        }
    }
}

5) Add a new web project to the solution (WebApplication1)

6) Reference the Utils project and try to run WebApplication1

Edit: Microsoft.Sharepoint.Sandbox is a 64bit dll but I need to target Any CPU.

Is there no way to tell VS to stop pulling across implict references?

woggles
  • 7,444
  • 12
  • 70
  • 130
  • Can anyone else reproduce this? – woggles Jul 12 '12 at 10:18
  • When you add Microsoft.Sharepoint.dll it might have an implicit reference to the Sandbox one. Try adding an explicit reference to the Sandbox one, and then do a Copy Local=False on that. How to add reference: http://sladescross.wordpress.com/2009/10/06/add-microsoft-sharepoint-reference-to-visual-studio/ ----- this link might help a bit too: http://blah.winsmarts.com/2009-12-SharePoint_2010_Sandbox_solutions__Architecture_and_Restrictions.aspx – Colin Smith Jul 17 '12 at 20:21
  • @colinsmith thanks for the comment and links. Im pretty sure it does have an implicit reference to the sandbox dll which is causing this inconvenience. I need a way to tell VS to stop being too clever and for it to not copy across implicit references. – woggles Jul 17 '12 at 21:33
  • @colinsmith I have tried adding it explicitly with copy local set to false with no luck previously. I'll retry in the morning and let you know – woggles Jul 17 '12 at 21:35
  • @colinsmith Adding the ref explicitly in the utils project with copy local set to false doesn't work – woggles Jul 18 '12 at 10:43

3 Answers3

2

How about adding the Microsoft.Sharepoint.Sandbox.dll assembly to GAC? According to MSDN:

If you deploy/copy an application that contains a reference to a custom component that is registered in the GAC, the component will not be deployed/copied with the application, regardless of the Copy Local setting. For more information, see Project References.

Update. If you target Any CPU, you can write a powershell or bat script which enumerates all bin folders and removes all Microsoft.Sharepoint.Sandbox.dll

Andrei Schneider
  • 3,618
  • 1
  • 33
  • 41
  • this works when targeting x64 (the dll no longer gets pulled into the bin folder). Unfortunately we need to target Any CPU because of some old 32bit servers. – woggles Jul 23 '12 at 13:07
1

try going to the project properties screen. The build tab. Change the "platform target" to be x64

Amjid Qureshi
  • 577
  • 1
  • 8
  • 19
0

According to this blog post by Louis Liang, the workaround is to add a post-build event and delete the DLL:

cd $(TargetDir)
del Microsoft.SharePoint.SandBox.dll
Alex Angas
  • 59,219
  • 41
  • 137
  • 210
  • Yep that works when building but unfortunately not when publishing the solution – woggles Nov 19 '12 at 06:46
  • @woggles I see... is there a way to customise the publishing process in a similar way? I know you don't want to use scripts like this but it seems the only option. – Alex Angas Nov 20 '12 at 01:18
  • 1
    Looks like it might be possible with a bit of work...see http://stackoverflow.com/questions/1360579/post-publish-events. – woggles Nov 20 '12 at 06:48