Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7566421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:24:30+00:00 2026-05-30T14:24:30+00:00

I am trying to add user-defined aggregates to a SQL Server 2008 database whose

  • 0

I am trying to add user-defined aggregates to a SQL Server 2008 database whose schema is defined in my Visual Studio 2010 solution file. The code for this custom aggregate lives in a SQLCLR project within the same solution, but I am having a lot of difficulty getting my unit tests to pass. For unit testing this project, I am using a method similar to the one here to get the byte string of the assembly. The test suite or a post-build event needs to automatically update my script to create the assembly each time, because after any sort of MSBuild (from the command line or Visual Studio), the assembly bits change.

The script seems to be updating its assembly bit string to correctly match the current assembly bits for each run. But the unit test still fails, with an underlying SQLException saying, “CREATE ASSEMBLY failed because it could not open the physical file “0xDEADBEEF”: 3(The system cannot find the path specified.). (I’ve removed the real assembly bits from that message.) Why would this error come up when the assembly bits appear to be correct? How should I fix this?

The length of the actual assembly bit string is about 16 KB. Would this be a problem? Does CREATE ASSEMBLY need to have the bits for the whole assembly or just a header, and how would I get only the header?

We already have the unit test infrastructure in place to deploy this database, including running pre- and post-deployment scripts. We also have an authorization set up that our user-defined functions and aggregates need to have.

Here is my post-deployment script:

IF EXISTS (SELECT name FROM sys.assemblies WHERE name = 'foo')
   DROP ASSEMBLY foo
go

-- The assembly bits change after every build from the command line or Visual Studio.  
-- This variable needs to change each time the foo assembly changes.
declare @assemblyBits as varchar(max)
-- This string is really about 15000 characters, including some newlines which are removed
-- in the next block.  Word-wrapping this line or not word-wrapping it seems to have no 
-- effect.
set @assemblyBits = '0x42'

-- Trim whitespace from assembly bits.
declare @sanitizedBits as varchar(max)
set @sanitizedBits = Replace(Replace(Replace(@assemblyBits, Char(10), ''), Char(13), ''), Char(9), '')

CREATE ASSEMBLY foo
AUTHORIZATION bar
from @sanitizedBits 
GO

IF EXISTS (SELECT name FROM sysobjects WHERE name = 'Product')
   DROP AGGREGATE Product
go

CREATE AGGREGATE [Aggregations].[Product]
    (@value float,
    @weight float)
    RETURNS float
    EXTERNAL NAME foo.[foo.Product]
go
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T14:24:32+00:00Added an answer on May 30, 2026 at 2:24 pm

    use dynamic sql if you have the content as a string

        EXEC ('CREATE ASSEMBLY foo AUTHORIZATION bar from ' + @sanitizedBits )
    

    Normally you pass in a varbinary

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I'm trying to add some ability to my project to allow user-defined properties
I'm planning a data warehouse migration to SQL Server 2008, and trying to think
I am trying to add a user-defined plane object to a priority queue: int
I’m trying to create a COM User Defined Function automation add in for Excel
Defined a SQL Server, which only user x (in the domain) is allowed to
Im trying to add a timer to my game so that the user knows
I'm trying to add the distance from the user's position to a selected annotation's
I am currently trying to add a JavaScript confirm message when a user attempts
I'm trying to add a $('body').live('click') listener after the user clicks on a div.
i'm trying to add some navigation arrows which allow the user to go to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.