none
Build Fails with "cannot register assembly" error

    Question

  • My team is using TFS and Team Build to automate build/deploy procedures.  In building one of our solutions I get the following error:

    C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets(2720,9): error MSB3216: Cannot register assembly "[ASSEMBLY PATH AND NAME HERE]" - access denied. Access to the registry key 'HKEY_CLASSES_ROOT\[ASSEMBLY NAME HERE]' is denied.

    So, I check out the Microsoft.Common.targets file, line 2720, and find this:

        <!--

        ***********************************************************************************************

        ***********************************************************************************************

                                                                    UnmanagedRegistration Section

        ***********************************************************************************************

        ***********************************************************************************************

        -->

     

        <!--

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

                                            UnmanagedRegistration

       

        Registers the main assembly for COM interop.

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

        -->

        <PropertyGroup>

            <UnmanagedRegistrationDependsOn></UnmanagedRegistrationDependsOn>

        </PropertyGroup>

        <Target

            Name="UnmanagedRegistration"

            Condition="'$(RegisterForComInterop)'=='true' and '$(OutputType)'=='library'"

            DependsOnTargets="$(UnmanagedRegistrationDependsOn)"

            >

     

            <RegisterAssembly

                Assemblies="@(_OutputPathItem->'%(FullPath)$(TargetFileName)')"

                TypeLibFiles="@(_OutputPathItem->'%(FullPath)$(TargetName).tlb')"

                AssemblyListFile="@(_UnmanagedRegistrationCache)"

                CreateCodeBase="true">

     

                <Output TaskParameter="TypeLibFiles" ItemName="FileWrites"/>

               

            </RegisterAssembly>

     

        </Target>

    Note that this section is worrying about COM interop.  None of our assemblies are marked for COM interop.  Does anyone have any idea what might be going on here?

    For a point of clarification, this error is the ONLY error in the build.  Furthermore, I can build the solution successfully using VSTS, i.e. right-click Build (or Rebuild) on the solution in solution explorer.

    Wednesday, November 01, 2006 10:18 PM

Answers

  • Have you tried removing the COM component registration?

    I would expect that making the account that is used for the build service (Team Build Service in Windows services) an administrator would be more than enough to access that part of the registry.  It might be good to double check the account being used for the service.

    Buck

    Tuesday, November 14, 2006 4:14 PM

All replies

  • As a follow up, it turns out that my dll references a COM component, but is not itself marked as COM Interoperable.  So, it’s possible that the Team Build is trying to register only the COM component.

    I have granted my Team Build user account administrative rights on the Build server, but I’m still seeing the same error.

    Does anyone have any ideas on this one?

    1)       What rights does my Team Build user account need to write to the registry?

    2)       How can I ensure that only the COM component is registered?

    3)       Can I avoid registry altogether for this COM control since it is referenced directly by the assembly that uses it?

    Thursday, November 02, 2006 3:29 PM
  • Have you tried removing the COM component registration?

    I would expect that making the account that is used for the build service (Team Build Service in Windows services) an administrator would be more than enough to access that part of the registry.  It might be good to double check the account being used for the service.

    Buck

    Tuesday, November 14, 2006 4:14 PM
  • I'm getting the same error.  the user the service is running as is administrator, and i'm still getting the same error.  Why is it doing anything to the registry during the compile?  does anyone know?
    • Proposed as answer by shafiya Saturday, February 18, 2012 11:13 AM
    • Unproposed as answer by shafiya Saturday, February 18, 2012 11:13 AM
    Tuesday, February 13, 2007 9:46 PM
  • You need to restart the Team Build Service before its new privileges will be available.
    When I made the service account local admin, I still had this problem, after restarting the service the team build succeeded.
    Pulling the service account out of the local Administrators group also resulted only after restarting the service in the same error.

    Tuesday, February 27, 2007 1:49 PM
  • I don't believe this has anything to do with using TFS. I'm getting the same error without using TFS. I have a class that is referencing COM objects. The class is set to System.Runtime.InteropServices.ComVisible(true) and in the project properties I have Register for COM Interop checked. Getting the exact same error as you.
    Wednesday, August 24, 2011 4:53 PM
  • I also don't understand why the registry would be touched during compile. Can anyone explain?

    Thanks...

    Friday, February 10, 2012 10:02 AM
  • HI Holf,

    Well, I do know that under Project Settings > Build > Output there is the checkbox "Register for COM interop".  If checked, then presumably MSBuild will try to register the assembly just like it would on your development environment.

    What I am trying to work out is how I can have the setting set within my workspace and unset in the build.

    Tuesday, November 06, 2012 5:54 PM
  • Well, I've worked out what was wrong in my situation.
    For some reason Team Foundation Build is building wiht the "Debug" configuration instead of "Release" Configuration and when I check the "Register for COM interop" setting for the project it was ticked for Debug and unticked for Release (the config I WANT to compile against).

    You may want to check the "Register for COM interop" setting under different Configurations too.

    Thursday, November 15, 2012 5:27 PM