Monday, March 31, 2014

How to reference a .dll out of the GAC in BIDS or Visual Studio and other fun challenges.

Tonight I helped a friend with code. She wanted to reference a static method in a static class in an .rdl report in SSRS. We struggled to get SSRS to reference a .dll she made in Visual Studio. We got past that challenge and then hit another where we were told that partially trusted callers were not allowed, so I cannot say that my evening was a success. Oh well, let me show off what I did learn:

  1. We had to install a .dll in the GAC and that means that the .dll has to be signed (or at least so in her environment). To sign a .dll go to a project's properties in Visual Studio. Pick "Signing" at the "tabs" at the left. Click "Sign the assembly" and then just pick "<New...>" at "Choose a strong name key file:" Make up a name and a password. Finally publish your .dll somewhere.
  2. We put the .dll in the GAC. To do so, at the Visual Studio Command Prompt run a command like so: "gacutil –i C:\Whatever\YourAssemblyHere.dll"
  3. To reference a .dll back out of the GAC you have to jump through a few hoops as suggested here and here. First navigate to C:\Windows\assembly\GAC_MSIL\ at a command prompt then run a command like so: "cd YourAssemblyHere" ...to drill into a folder that has the same name as your assembly. Run a "dir" command here to see a list of folders in that folder. There will be a folder with a funny name like "1.0.0.0__992b220d2c0fa2a6" and you should drill into that folder next. Inside you should see your .dll. You need to take the full path to the .dll as you've just uncovered it and then paste that into the "File name:" field one sees when browsing for a reference when attempting to add a reference in Visual Studio. For some infuriating reason you cannot just navigate to the .dll in the assembly folder at Visual Studio and expect it to make the appropriate association. The stuff nested in C:\Windows\assembly\ will behave oddly when you try to browse into it from Visual Studio.

No comments:

Post a Comment