18

Any help please?

I have only one library and it is driving me crazy. this is the error that I receive. I am not using any other dependancies.

Could not load file or assembly 'FOD.Intranet.Lib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=039c1f3a4c719e82' or one of its dependencies. The system cannot find the file specified. 

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.IO.FileNotFoundException: Could not load file or assembly 'FOD.Intranet.Lib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=039c1f3a4c719e82' or one of its dependencies. The system cannot find the file specified.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace: 


[FileNotFoundException: Could not load file or assembly 'FOD.Intranet.Lib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=039c1f3a4c719e82' or one of its dependencies. The system cannot find the file specified.]
   NewCollection.VisualWebPart1.VisualWebPart1UserControl.TodaysNews() +0
   NewCollection.VisualWebPart1.VisualWebPart1UserControl.Page_Load(Object sender, EventArgs e) +52
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +25
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +42
   System.Web.UI.Control.OnLoad(EventArgs e) +132
   System.Web.UI.Control.LoadRecursive() +66
   System.Web.UI.Control.AddedControl(Control control, Int32 index) +350
   NewCollection.VisualWebPart1.VisualWebPart1.CreateChildControls() +155
   System.Web.UI.Control.EnsureChildControls() +146
   System.Web.UI.Control.PreRenderRecursiveInternal() +61
   System.Web.UI.Control.PreRenderRecursiveInternal() +224
   System.Web.UI.Control.PreRenderRecursiveInternal() +224
   System.Web.UI.Control.PreRenderRecursiveInternal() +224
   System.Web.UI.Control.PreRenderRecursiveInternal() +224
   System.Web.UI.Control.PreRenderRecursiveInternal() +224
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3394
Imir Hoxha
  • 1,674
  • 6
  • 31
  • 56

9 Answers9

28

To make Visual Studio adding 3rd party assembly or even your own assembly from other project in solution to GAC please do next:

  1. Open Package.package from Package folder in SharePoint project.

  2. Click Advanced in bottom area.

  3. Click Add and chose which type of assembly you want to add.

  4. In dialog select dll file, chec GAC or BIN, add safe controls and class resources entries if required. Click Ok.

Your assembly will be packaged to WSP, defined in manifest and deployed everytime.

Oleg Savelyev
  • 968
  • 2
  • 8
  • 12
16

Problem Solved!

I thought that Visual Studio was copying the DLL in to the GAC, but apparently not. So I copied it there manually and it works.

One question though, is this normal that visual studio does not copy it to the GAC when I deploy the sharepoint application?

For those who would like to know how to copy the dll to GAC

there are two ways to copy the dll to GAC:

  1. copy the dll manually

    1. Open c:\windows\assembly directory in windows explorer
    2. Open another instance of windows explorer and go to the place where your dll is located, usually in the bin folder. (so now you will have two windows open)
    3. select the dll you would like to copy to gac and drag it inside the assembly directory, c:\windows\assembly
  2. use VS to deploy it for you to GAC.

    1. in your sharepoint project double click on "Package".
    2. Package.Package will open. Look bottom left of your screen and click on "Advanced",
    3. then click on "Add", then select "Add Assembly from project output...".
    4. In the Source project dropdownlist select the project and then click OK.
    5. finally deploy the solution and the dll will be in the GAC.

thank you for your support.

Imir Hoxha
  • 1,674
  • 6
  • 31
  • 56
  • if you want visual studio to do this, make sure you set the property 'copy local' of the reference to true – Daniël Tulp May 22 '14 at 11:52
  • 1
    Note: Never touch the Windows\Assembly folder, copying it manually is a VERY BAD IDEA. Use gacutil /i to install the DLL and gacutil /u to remove it. /i takes the full path while /u takes the dll name without the extension. – David Jul 10 '14 at 08:33
2

For assemblies not in GAC, and which are referred in the build, sometimes this error also happens if the platform target does not match. So match the assembly platform type to the one where it is being used.

enter image description here

Giri
  • 126
  • 1
  • 6
0

for guys still looking into this issue one thing u need to know is there are different GACutils out there , so u need to make sure that ur using correct GACUTIL to deploy the DLL to correct GAC

for eg: if my dll was complied in 3.5 .net framework and my OS version was 64 bit windows it would be in below location

C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\x64

Struggled for 4 stupid days to figure this out

mps
  • 1
  • 1
0

This error is coming because your dll file and project files are in different folder.

Adding Visual Studio 3rd party assembly like SelectPdf.dll or SelectHtmlToPdf.dll etc.

You just need to put your dll file in the same folder and add reference to this file.

Step : Create a folder name externaldll and put all dll files here.

Nicolas Perraut
  • 797
  • 1
  • 9
  • 32
0
  • Does the version number match?
  • It's weird to see you're trying to load a .lib file instead of a dll. Perhaps you wanted to load a dll instead?
  • To debug this kind of problems, try Fusion Logging
  • You say you're using only one library, but that library might have some dependencies you're not aware of. This SO question deals with listing the dependencies of a managed .NET assembly.
Community
  • 1
  • 1
dario_ramos
  • 7,118
  • 9
  • 61
  • 108
  • Hi Dario_ramos, I am loading a dll but the name of the assembly is FOD.Intranet.Lib.dll – Imir Hoxha Dec 06 '11 at 20:23
  • That's not the problem, then. I'd try fusion logging – dario_ramos Dec 06 '11 at 20:27
  • 1
    I created a demo library which has a single method which adds two number together and I reference it from a sharepoint project. I got the same error as the above. Now, when I used an asp.net project it works fine. it does not complain about the dll. – Imir Hoxha Dec 06 '11 at 20:49
  • There must be something wrong with your Sharepoint project configuration. Don't know much about Sharepoint, but you might want to invistigate how dll lookup works in Sharepoint – dario_ramos Dec 06 '11 at 20:57
  • Thanks Dario for your help. I will look further into it but it is making me crazy. – Imir Hoxha Dec 06 '11 at 20:58
  • Did you try fusion logging? Since it logs all .NET assembly loading attempts, it'll tell you all the locations where Sharepoint is trying to find the dll, and if it's a dependency thing, it'll tell what's missing. Strong name validation, if you're using it, can cause loading troubles too. – dario_ramos Dec 06 '11 at 21:00
0

Please try to unreference the DLL then re reference it again and rebuild you project. Also Check to ensure that the version matchs what is in the project web config

  • Hi Lafama, thanks for your reply. I dereference it and re-referenced it again but it does not work. In the webconfig do I have to see the class library dll or the project that is using the dll? I did not find the any reference to this namespace FOD.Intranet.Lib in the webconfig. – Imir Hoxha Dec 06 '11 at 20:21
0

Assuming that you have access to SharePoint server, try the following. Some random thoughts and no specific order.

  • Deploy the assembly to GAC or copy the dll to the bin folder of your web application
  • Add the assembly info in your web.config assemblies section and in the safe controls section.
  • If you are developing a web part, make sure to add its reference in the safe controls section of the web parts (although i don't think this is your problem)
  • Signing the assembly with a strong name might help in some cases.
  • If you have custom dependencies then you need to do the follow the same steps for all the dependencies (other than .net framework and SharePoint related)

Are you developing your SharePoint project (do you mean web part?) using visual studio? Are you referencing it in your SharePoint project? You need to give us more details on your development environment to be able to pinpoint the problem.

Ken
  • 734
  • 2
  • 8
  • 22
0

If you are using the code Page.Load("control_path..."). make sure that the actual ascx file you load does not have any directives that include the assembly from your exception message

<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
Maks Matsveyeu
  • 866
  • 5
  • 11
  • Hi Maks, I am using the Import statement in the user control. I need to access the library in .ascx file. – Imir Hoxha Dec 07 '11 at 08:59
  • 1
    So this IS actually a dependency. You gotta put this library (FOD.Intranet.Lib) into the solution. Please let me know if you need help with adding a custom assembly into a wsp. – Maks Matsveyeu Dec 07 '11 at 10:24
  • When I add a reference to the assembly, I see that Visual studio copies it into the Bin folder and I see it in the references folder in visual studio. What am I doing wrong? – Imir Hoxha Dec 07 '11 at 11:47
  • Please have a look at this article. http://blog.mastykarz.nl/including-additional-assemblies-wsp-visual-studio-sharepoint-development-tools/ it has a step-by-step guide how to add an assembly to a package. your case is more simple. you have to add AN EXISTING ASSEMBLY instead of PROJECT OUTPUT. and check the DEPLOYMENT TARGET to GAC. And you do not have to add SafeControls. – Maks Matsveyeu Dec 08 '11 at 13:11