RegAsm error: Cannot write to the registry key.


C:\Temp\ClassLibrary1\ClassLibrary1\bin>regasm ClassLibrary1.dll

Microsoft (R) .NET Framework Assembly Registration Utility 1.1.4322.573

Copyright (C) Microsoft Corporation 1998-2002.  All rights reserved.

                                                                                                               .            

Types registered successfully

                                                                                                                  .                                              

C:\Temp\ClassLibrary1\ClassLibrary1\bin>regasm ClassLibrary1.dll /u

Microsoft (R) .NET Framework Assembly Registration Utility 1.1.4322.573

Copyright (C) Microsoft Corporation 1998-2002.  All rights reserved.

                                                                            .            

RegAsm error: Cannot write to the registry key.

 

 

You may receive this error when attempting to unregister your PIA (Primary Interop Assembly).  This is an issue where regasm fails to delete a registry key when cleaning up the registration of your PIA.  The registry key that fails to get deleted is something like HKEY_CLASSES_ROOT\TypeLib\<GUID>\X.x where X.x is the version number of your PIA that you specify using the PrimaryInteropAssemblyAttribute class.  Typically you set this in your assemblyinfo file.  In vb this would look like:

 

<Assembly: PrimaryInteropAssembly(1, 0)>

 

The good news is that there are no real harmful side effects of this registry key remaining in the registry.  If you’d like you can manually remove the key using regedit.exe.  If there are no other typelib versions registered you cal also remove the HKEY_CLASSES_ROOT\TypeLib\<GUID> key as well.  You will not encounter this error unless you have the PrimaryInteropAssembly attribute set for your assembly.

Comments (0)

Skip to main content