I am trying to put together some build scripts with a .NET project, and deploy some CLR code to SQL Server. I have signed the assembly and can deploy it as a stored procedure if I build the DLL in Visual Studio by choosing "Build." Running the stored procedure works fine after deployment under a login for EXTERNAL ACCESS.
However, if I compile the DLL with an MSBuild script, I get the following error in SQL Server after deployment (same process) and trying to run the stored procedure:
Msg 10314, Level 16, State 11, Line 5 An error occurred in the Microsoft .NET Framework while trying to load assembly id 65562. The server may be running out of resources, or the assembly may not be trusted with PERMISSION_SET = EXTERNAL_ACCESS or UNSAFE. Run the query again, or check documentation to see how to solve the assembly trust issues. For more information about this error: System.IO.FileLoadException: Could not load file or assembly 'assembly, Version=126.96.36.199, Culture=neutral, PublicKeyToken=ea3705e3b2b05e85' or one of its dependencies. The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047) System.IO.FileLoadException: at System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection) at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) at System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) at System.Reflection.Assembly.Load(String assemblyString)
My MSBuild file just calls build on the project file in my solution:
<MSBuild Projects="Project1/Project1.csproj" Targets="Build" />
I suspected it might be a target framework problem (I need this to be .NET 2.0, and it is configured for that), but using
/p:TargetFrameworkVersion=v2.0 still didn't work.
Why are these 2 compilations different?
Edit: I am trying to compile for Any CPU
Figured it out:
Rookie mistake. For some reason, MSBuild does not use the default target assembly platform. This msbuild call works to force the platform to assemble:
msbuild script.msbuild /p:Platform="AnyCPU" /p:Configuration=Release
Thanks to this link for tipping it off (although "Any CPU" with a space didn't work):
User contributions licensed under CC BY-SA 3.0