none
cannot register exception has been thrown by the target of an invocation

    Question

  • I have a C# class library project. But when I compile it. It shows an error stating

    "Error 1 Cannot register assembly "D:\Maverick\Projects\U2CME\SRC\Marketing\MarketingPlugIn\bin\Debug\MarketingPlugIn.dll". Exception has been thrown by the target of an invocation."


    Adeel
    Tuesday, September 06, 2011 12:51 PM

Answers

All replies

  • I have  a C# based COM class library project. I created its Setup and Deployment and in the properties of Primary output set the "Register" Property to "vsdrpCOMRelativePath". But while installing its not registering the DLL as a result this IE Plugin is not working. You can see the source code in this location, with the file name "Marketing.zip"

    https://skydrive.live.com/#!/?cid=615ed451fd83a613&sc=photos&uc=1&id=615ED451FD83A613%21276

     


    Adeel
    Tuesday, September 06, 2011 12:04 PM
  • You should verify that the file exists where you think it does (make sure the path is correct) and that there is sufficient privileges to access that file.

    Make sure D is not a network path or mapped drive.

    May also be that UAC is blocking the program. You can temporarily disable UAC in control panel.

    If this is an external library you're referencing, you should reference it from outside of the build directory so that it always exists and isnt deleted when you do a clean. (Put it in a shared folder in the project root).

    Verify the architecture is correct (x86 vs x64 vs AnyCPU) and if the library is not .NET, you have the correct runtime installed. (Such as Visual C++ 2008 Runtime)

     

    Tuesday, September 06, 2011 3:04 PM
  • UAC is already turned off. Its the primary output file that by default gets tored in Application folder that is specified in file section. D is a local drive not a network. It is my library project in which it showing this error at first place :(
    Adeel
    • Proposed as answer by mlukasz Thursday, September 04, 2014 9:59 AM
    Thursday, September 08, 2011 4:26 AM
  • Hello Adeel,

    Welcome to the MSDN Forum.

    I have download your project from this link: Public - Windows Live( named Marketing) which is related from the other post you created: Registring a Class Library. And I tested it.

    Firstly I have got the same error as you said and failed to build the project. If I deleted the MarketingPlugIn.dll and MarketingPlugIn.pdb file from debug and Release directory and rebuilt the project, the project success built and it works well with the IE.  See the picture please:

     

    Also we need run the Visual Studio as the Administrator.

    Hope it helps.


    Best Regards,
    Rocky Yue[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, September 08, 2011 5:15 AM
    Moderator
  • I always clean before rebuilding all in which it deletes the output and pdb files, still i tried to manually follow your steps and now it says

    Error 1 Cannot register assembly "D:\Maverick\Projects\U2CME\SRC\Marketing\MarketingPlugIn\bin\Debug\MarketingPlugIn.dll". Exception has been thrown by the target of an invocation.

    Then I deleted both the Debug and release folders and till the same error persisted :(


    Adeel
    Thursday, September 08, 2011 5:42 AM
  • OK, could you check your IE's Add-on?

    And check the registry

    If they existed, delete them by hand. And then, rebuild the project.

    PS: All of the step must run as a Administrator.


    Best Regards,
    Rocky Yue[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, September 08, 2011 5:49 AM
    Moderator
  • In your case it was able to register. In my case even before registering during compilation this error is generated. When its not registered it will not be displayed in Add-ons list as well as registry


    Adeel
    Thursday, September 08, 2011 6:54 AM
  • Try to down load these two file from this link:

    https://skydrive.live.com/#!/?cid=59becb459468ca88&sc=documents&uc=2&id=59BECB459468CA88%21117

    I have installed them successfully.


    Lucky Dog
    Thursday, September 08, 2011 7:02 AM
  • What did you do with the original source code?
    Adeel
    Thursday, September 08, 2011 7:21 AM
  • Nothing.
    Lucky Dog
    Thursday, September 08, 2011 7:58 AM
  • Hi Adeel,

    I finally find an issue with your code:

     

         RegistryKey ourKey = registryKey.OpenSubKey(guid);//in the BHO.cs RegisterBHO method

    Try to change the code as bellow:

     

     

    RegistryKey ourKey = registryKey.OpenSubKey(guid,true);//in the BHO.cs RegisterBHO method
    

    It should be due to the OpenSubKey which is read_only method.

     

    Hope it helps.


    Best Regards,
    Rocky Yue[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    Thursday, September 08, 2011 8:02 AM
    Moderator
  • now while compiling it say...

    "C:\Windows\Microsoft.NET\Framework\v3.5\Microsoft.Common.targets(3019,9): error MSB3213: Cannot register type library "D:\Maverick\Projects\U2CME\SRC\Marketing\MarketingPlugIn\bin\Debug\MarketingPlugIn.tlb". Error accessing the OLE registry. (Exception from HRESULT: 0x8002801C (TYPE_E_REGISTRYACCESS))"


    Adeel
    Thursday, September 08, 2011 9:00 AM
  • Uncheck the Register for COM interop in the project's properties Build tag.

    And this is a solution from MSDN for your reference:

    http://social.msdn.microsoft.com/Forums/en-US/netfx64bit/thread/253110bc-5fee-478f-a2eb-e1d5ec6039af/

    Hope it helps. 


    Best Regards,
    Rocky Yue[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by maverick786us Thursday, September 08, 2011 10:00 AM
    Thursday, September 08, 2011 9:24 AM
    Moderator