I have an ASP.NET application, which has two references added: MapServer and GDAL. These two DLL's uses a bunch of other DLL's, and all of them are in my applications /bin directory.
When I run the application on my own PC in Visual Studio 2010 it runs fine. When I upload it to my Windows 2008 server with IIS it throws this exception:
Could not load file or assembly 'gdal_csharp' or one of its dependencies.
An attempt was made to load a program with an incorrect format.
When running the application through Visual Studio on the server it runs fine.
I've even tried adding the /bin directory to the PATH enviroment variable, and restarting the server. No luck though.
My guess is that the DLL is a 32-bit only DLL that you are trying to run in a x64-environment. Can you try to set the app-pool to 32-bit only?
Update: a simple instruction is here: http://help.webcontrolcenter.com/KB/a1114/how-to-enable-a-32-bit-application-pool-in-iis7-dedicatedvps.aspx
You need to register the dll at GAC: http://en.wikipedia.org/wiki/Global_Assembly_Cache
As already mentioned you may be missing something from the GAC.
To see whats happening you could try turning on Fusion Logging, this will enable you to view all of the assembly load failures.
Back to Basics: Using Fusion Log Viewer to Debug Obscure Loader Errors
Related
I am suddenly seeing this error when running my app (published on Azure app service:
Could not load file or assembly 'Microsoft.SharePoint.Client, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' or one of its dependencies. The system cannot find the file specified. at SharePointLibrary.SPClient.GetAllUsers()
at ADVWKSP.Managers.UserManager.GetUsers() in C:\Users\bassie\source\repos\TFS\ADVWKSP\ADVWKSP\Managers\UserManager.cs:line 21
It runs fine on my machine, and it used to run fine after publish but now it just suddenly starts crying about this file missing.
I checked in Kudu and I can only see the SharePoint.Client.Runtime:
Why? How can I ensure that all required libraries are published with the project. Why did this suddenly stop working?
The hosting environment of azure web app contains a standard installation of .Net framework 2.0 to .Net framework 4.5.
If your application referenced assemblies which is not build in .Net framework, you have to "include" them with your deploy package.
Even these are Microsoft assemblies.
Setting the Copy Local property to True for the referenced assembly may fix it.
1.In Solution Explorer find your project's reference to the library.
2.Right click and choose Properties.
3.In the Properties window set Copy Local to True.
As you said, it works locally on IIS Express, please try to deploy your website content manually to Azure via KUDU or FTP client and find out whether it works or not.
Adding the following parameter
/deployonbuild=false
to the msbuild command line fixed the issue.
I faced the similar kind of issue when my app service function version was 3, but function source was targeted function version 4. updating the app service sorted the issue
While using a native dll dependency on a asp.net web project and debugging in VS2015 with IIS express I'm getting the dreaded:
Could not load file or assembly 'XXX.DLL' or one of its dependencies. The specified module could not be found.
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 'XXX.DLL' or one of its dependencies. The specified module could not be found.
HOWEVER the same dependency works fine in a simple forms app on the same machine - hence I assume all the dependencies and co-dependencies are present
maybe you have some clues, how can this be?
What I already tried:
putting all the potential dependencies in the web project output folder
putting all the potential dependencies in the /system32/ path
putting all the potential dependencies in the /system32/inetsrv and /sysWOW64/inetsrv
installing c++ redistributables (2010, 2012, 2013)
I 'unblocked' the dlls as they "came from another computer" (CASpol)
dependency walker did not give any clear results
process monitor did not give any clear results
some details:
VS2015 Community, running on an Azure VM with Windows Server 2012 (test system), clean install
the app uses CGAL and BOOST libraries (c++).
'Dependency tree' is as follows: C# wrapper references a CLR C++ project which in turn references the native C++ (only this one uses CGAL/Boost);
The C# wrapper is then used in the forms app (works) or the asp.net web app (doesn't work);
Putting Cgal dlls (around 6 files) into the bin output folder was enough to run the forms app.
PS: of course on my 2 dev machines (Win 7, Win 10) the asp.net project works swimmingly - but these contain dedicated installs of the huge c++ references.
PPS: I currently really prefer to use iis express due to external reasons. I have to simulate deploying the app on a clean-ish Win10 laptop, in a dev environment, with minimal external installations
PPPS it seems the win10 dev machine isn't working after all - edit: this was the key clue, see my answer below and Ho do I reference native files in IIS express?
I'm a bit stuck right now, thanks.
Solution: on Win 10 I copied the dll output (\bin folder) into the Program Files (x86)\IIS Express folder (as I am using the 32-bit version).
Apparently, this wasn't needed on Win7 - I will have to investigate why
I found this solution in:
Ho do I reference native files in IIS express?
EDIT: another, more elegant (?) solution is to disable shadow-copying in web.config as in http://faithlife.codes/blog/2013/05/using-native-dlls-from-asp-net-apps/
"The simplest solution I’ve found is to turn off shadow copying, which causes the DLLs to be loaded directly from the bin directory.(...) Just add a hostingEnvironment element to your web.config:"
<configuration>
...
<system.web>
...
<hostingEnvironment shadowCopyBinAssemblies="false" />
I have a multi-project solution (C#) that I am trying to deploy to one of our test servers. All the projects are being built for x64, with the 'Prefer 32 bit' disabled where applicable.
Some of the projects reference a SQLite dll set that uses the SQLite Encryption Extension (not managed by nuget). When I build and install the solution on my local dev machine, the application and windows service are able to function properly, no problems.
When I try to install the same package on one of our test servers, running 64-bit Windows Server 2012, I get the "Unable to load DLL 'SQLite.Interop.dll': The specified module could not be found." whenever I try to communicate with the SQLite database. I have triple checked that all the appropriate DLLs are in the program folder after installation.
In my VS solution, I have tried creating the x86/x64 folders, setting Copy to Always, but to no avail. I have also copied the DLLs from my local install folder into the server folder just to see if something got messed up along the way.
Could it be a permissions issue? I'm an elevated user but not a full admin on the server, whereas I'm a full admin on my machine. I've tried manually modifying the permissions on the program folder to see if that was an issue, but had no luck with that either.
So to summarize, the project is being explicitly built for x64, it has the right DLLs in the right folders, and it works on a local install. I'm at a loss as to why it won't work on the server install. I've looked through countless threads on StackOverflow, MSDN, and SQLite's website, all usually suggesting the x86/x64 folders, but that hasn't been working for me. I'm hoping someone can help me out here.
Thanks!
Was actually able to figure it out after a bit more debugging. The Visual C++ runtime that was installed on the server wasn't the right version. I added the Merge Module to the installer for the version my project was expecting, reinstalled the app on the server, and now it's working beautifully.
For those who have this issue, look for the right version of the VC++ runtime in C:\Program Files(x86)\Common Files\Merge Modules. If you don't know what version you need, use something like dependency walker on the machine that is throwing the error. Mine told me I was missing VC140, so that's the module I copied into my project and added to the installer.
I've looked at similar questions on SO, but nothing quite matches my issue as far as I can tell.
The exception message:
Could not load file or assembly 'CrystalDecisions.ReportAppServer.ClientDoc, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304' or one of its dependencies. The system cannot find the file specified.
The file is in my GAC. I am developing on a 32 bit machine (Windows 7) running VS2010, everything is .NET4. The target hosting machine is 64-bit Win 2008 R2. My local machine has the CR installation for VS2010; the hosting machine has the 64-bit runtimes for VS2010. I am compiling all my code in "Any CPU" mode for this web application.
It is blowing my mind that it cannot find the file in the GAC. This is an IIS application; is there some sort of permissions issue? I would think IIS would have access to the GAC.
Some suggestions of what to do would be appreciated.
It turns out the answer was ridiculously simple, but mystifying as to why it was necessary.
In the IIS Manager on the server, I set the application pool for my web application to not allow 32-bit assemblies.
It seems it assumes, on a 64-bit system, that you must want the 32 bit assembly. Bizarre.
1) Change your .net profile from Client profile to to .Net Framework 4.0
http://msdn.microsoft.com/en-us/library/bb398202.aspx
2) Check your Embed Interop Types flag
http://weblogs.asp.net/cazzu/archive/2011/03/11/check-your-embed-interop-types-flag-when-doing-visual-studio-extensibility-work.aspx
Regarding the 64-bit system wanting 32-bit support. I don't find it so bizarre:
Although deployed to a 64-bit system, this doesn't mean all the referenced assemblies are necessarily 64-bit Crystal Reports assemblies. Further to that, the Crystal Reports assemblies are largely just wrappers to a collection of legacy DLLs upon which they are based. Many 32-bit DLLs are required by the primarily referenced assembly. The error message "can not load the assembly" involves these DLLs as well. To see visually what those are, go to www.dependencywalker.com and run 'Depends' on the assembly in question, directly on that IIS server.
You simply need to install Crystal Report Report Run Time downloads on Deployment Server. If problem still appears, then place check asp_client folder in your project main folder.
I am developing on a 64bit version of Windows 7, running MOSS (SharePoint), this is my dev machine.
Now when I deploy my web service app to a test server Windows 2003 32bit (no Sharepoint installed) I get this error.
Could not load file or assembly 'Microsoft.SharePoint.Library, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' or one of its dependencies. The system cannot find the file specified
The DLL has clearly been copied to the bin directory (Microsoft.Sharepoint.dll).
Any ideas?
If you are using sharepoint dll's it will only work on a machine with sharepoint installed.
Even if you managed to hack it and get it to work, you would probably be breaking a license agreement.
There is a way to load Sharepoint libraries in a development console with windows XP, Vista or Seven.
See here: http://fernandof.wordpress.com/2008/02/11/how-to-install-the-sharepoint-2007-vs-2005-extensions-on-a-workstation/
[O]pen the regedit and create the following keys and the string value:
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\12.0]
"Sharepoint"="Installed"
That’s it! You have fooled the installer into running on a
workstation. Easy. I also recommend adding the core SharePoint
assemblies into the [GAC] using gacutil. Those assemblies can be found
by default in any [SharePoint] machine under the folder: C:\Program
Files\Common Files\Microsoft Shared\web server extensions\12\ISAPI.
This is almost certainly a dependency issue. The DLL is dependent on another DLL which isn't in the GAC or on the probing path. The two tools you need to figure this out are FUSLOGVW.EXE and Process Monitor
Fusion Log viewer will allow you to look at assembly bind successes and failures as your application loads. It's part of the Windows SDK.
http://msdn.microsoft.com/en-us/library/e74a18c4(VS.71).aspx
FUSLOGVW needs admin privs to run correctly.
If that doesn't work another tactic is to use Process monitor to look at which files aren't getting loaded and which folders are being searched.
http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx
However. Without SharePoint installed I wouldn't expect this to work.
Ade
From MSDN:
"The CI build environment for the Training Management application does not perform any tests that require a live instance of SharePoint. All the unit tests use mocks that replace the actual SharePoint instance and services. Building the code and running the unit tests only requires that the following SharePoint assemblies are installed on the CI build server:
Microsoft.SharePoint
Microsoft.SharePoint.Security
Microsoft.SharePoint.WorkflowActions
Supporting referenced assemblies"
http://msdn.microsoft.com/en-us/library/ff647619.aspx
Don't mix 64-bit and 32-bit for dev / testing / production. This will never work reliably if at all.
Well what about other dlls referenced by the Sharepoint dll? With long dependency chains it can be quite difficult to diagnose these sort of problems. In such situations I find the fusion log viewer extremely useful. It is a part of framework SDK - open the SDK Command prompt and type fuslogvw. It is pretty obvious from there