WCF unable to load DLLImported dll - wcf

I have a WCF service which references LevelDB-sharp (https://github.com/meebey/leveldb-sharp) which in turn references (DllImport) leveldb.dll.
Everything runs perfectly on my development machine, but as soon as I deploy it to live, I get the error message
The server encountered an error processing the request. The exception
message is 'Unable to load DLL 'leveldb.dll': The specified module
could not be found. (Exception from HRESULT: 0x8007007E)
I've tried putting the dll in the web service directory, the bin subdirectory, system32 and also system32\inertsrv and keep getting the same error.
I've also tried hard coding a path into the DllImport calls.
What am I missing?

DllImport calls does not follow the normal .net probing path ,it will look through windows PAth variable paths.
Since you have already tried to put the dll to inetsrv and system32,I guess your IIS webapplication pool may be running on 32bit mode.Are you running your application pool in 32 bit mode ?
If so, Please try and put the leveldb.dll in your syswow64 folder or
C:\Windows\SysWOW64\inetsrv folder

Related

asp.net core 2.1 HTTP Error 502.5

When I am trying to run my solution I am getting In the browser:
HTTP Error 502.5 - Process Failure
Debugging stops almost immediately after it starts and there is no error message inside visual studio.
In the output window this is the only message:
The program '[30700] dotnet.exe' has exited with code -2147450730 (0x80008096).
The project was working fine, I just installed a nuget package and this started happening. I tried deleting it and removing the package cache but it still happens.
Event viewer shows error with IIS Express AspNetCore Module.
Application 'MACHINE/WEBROOT/APPHOST/PROJECTNAME' with physical root 'E:\path\ProjectName\' failed to start process with commandline 'e:\program files (x86)\microsoft visual studio\2017\community\common7\ide\extensions\microsoft\web tools\projectsystem\VSIISExeLauncher.exe -argFile "C:\Users\username\AppData\Local\Temp\tmp49E1.tmp"', ErrorCode = '0x80004005 : 0.
I am a bit lost as there is no error to go on.
Any ideas?
Well! This is due to appropriate .NET Core SDK missing problem. Your project's package versions are higher than the SDK version installed on your machine.
Download the latest version v2.1.401 (at the time of that answer) from here: Download .NET Core SDK and install it.
Now restart your computer and run the project again.
Hope your problem will be solved!
Although it was already answered, I'll post here my solution for the same problem (HTTP Error 502.5 when starting my webapp on Asp.NET CORE 2.1, error code 0x80004005) that has a different reason, as reference of another possibility.
Short Answer:
If the name of the application has a space (character) on it, the current version of Visual Studio (15.8.9) has a bug, that doesn't include quotes to make it a literal string argument on the moment of execution (through commandline) on the web.config file, generated when publishing your webapp.
Example:
web.config generated by Visual Studio (version 15.8.9 - Date: 2018-Nov-05):
[...]
<aspNetCore processPath="dotnet" arguments=".\My Web App.dll" stdoutLogEnabled=... />
[...]
web.config with correct quotation:
[...]
<aspNetCore processPath="dotnet" arguments='".\My Web App.dll"' stdoutLogEnabled=... />
[...]
You can see on the attribute arguments on the second example, that I included (manually) single quotes, making it pass the full string ".\My Web App.dll" as the argument on the moment of execution.
Detailed Answer:
Every time I update my Visual Studio for a newer SDK (and using the most recent version of Asp.net Core in my application) it give me the Http Error 502.5, IF i do not update the runtime libraries on my server too. So, obviously the first thing that I did was update the runtime libraries on the server (which always solved this problem to me), but this time it didn't worked.
So, starting to troubleshoot, I just tried to start my webapp from the command line (prompt), and it started perfectly.
So, I knew that there was something wrong with the way my webapp was being started. The starting configuration (on asp.net core) is in the web.config file.
[...]
<aspNetCore processPath="dotnet" arguments=".\My Web App.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
[...]
In Asp.net Core, the web application is started/executed from the commandline (prompt) on windows, by IIS (i'm strictly speaking of common scenario).
Till now, it always had a .exe file between the published files, that started the whole thing, and this was the file called by IIS Module through commandline.
Since Asp.net CORE 2.1 (and some minor update that i don't know exactly), there is no .exe file, and the PATH of Web App is passed by argument. So you have the command that is dotnet and a argument to this command that is specified as argument attribute, on the web.config file. (as shown in the example above)
Taking a look on my published web.config file, you can see the processPath and arguments attributes. In the previous test, I knew that dotnet was a recognized command, since I was able to start my webapp on windows command prompt. Then, looking carefully the arguments attribute, I saw that there was no (surrounding) quotation for the value, that contained space characters in it.
So in the startup of my webapp, instead the dotnet command receive the full path .\My Web App.dll, it was receiving 3 different arguments: .\My , Web , App.dll .
Since the value of the arguments attribute is passed through commandline, it has to have quotation when passed to the commandline, becoming a literal string.
So I mannualy added the necessary surrounding quotation on the arguments attribute value, in the web.config file, and my web app started to work perfectly!
To see the example of the bug, and how to correct it, just take a look on the "Short Answer" examples.
Other useful information (for Asp.net Core 2.0 and up, with Windows / IIS):
If you had a web application that was working, and is not anymore, giving the error 502.5:
It's probably a versioning problem of the runtime libraries. Your webapp is asking for newer asp.net core libraries, and your server doesn't have them yet.
Just update the runtime libraries on your server, and it should solve the problem. Download it from Microsoft (for the current version which is Asp.net Core 2.1, you can download from this link: https://www.microsoft.com/net/download/dotnet-core/2.1).
How to start your webapp manually, for better troubleshooting:
Open the windows command prompt, and try to execute the command dotnet. If it's not recognized, than you have to install (or repair) the asp.net core module and dependencies (google is your friend. Just search how to install asp.net core). Alternatively, you can check the Asp.net Core runtime libraries version with the command dotnet --version.
Once the dotnet command is recognized, you can start your webapp manually.
Navigate to the folder where is your webapp files (usually will be in inetpub, wwwroot, etc..). Then, locate the .dll file that is your application's assembly. Usually, it will have the name of your application (pretty easy, right!?). Then, execute it with the command dotnet ".\My Web App.dll".
Example:
If there is a error, you will see some useful information on the prompt window. If the webapp starts correctly, then it's some issue with the startup configuration, probably web.config file.
Another method to see more detailed information on asp.net core failure:
https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/troubleshoot?view=aspnetcore-2.1#application-event-log
Access the Application Event Log:
Open the Start menu, search for Event Viewer, and then select the Event Viewer app.
In Event Viewer, open the Windows Logs node.
Select Application to open the Application Event Log.
Search for errors associated with the failing app. Errors have a value of IIS AspNetCore Module or IIS Express AspNetCore Module in the
Source column.
Details of my issue:
When executing requests, the error presented was: HTTP Error 502.5 - Process Failure.
Looking on the Events Viewer (Windows Server), the information was: "Application ' ... My Web App' with physical root 'C:\ ... \ ... \' failed to start process with commandline 'dotnet .\My Web App.dll', ErrorCode = '0x80004005 : 1."
So my error code was: 0x80004005 , and the subcode was 1.
Hope it helps somebody :)

Assemblies Failing to load in shadow copied AppDomain

I write the xunit.net test runner for ReSharper, and I've got an issue in the 8.0 release - I'm seeing assemblies failing to load in a shadow copied AppDomain. The same code and test project work fine in the 7.1 release. I don't understand why, though.
When running tests, ReSharper spawns an executable that loads my plugin. I use xunit.net's API to create an AppDomain that has shadow copy enabled. The test project assembly is copied into the shadow copy cache, and starts to load. It copies a dependency into the cache, and loads it - an older version of FakeItEasy, which uses Assembly.LoadFile to load all of the assemblies in the current directory, which is the bin\Debug folder of the test project. So, FakeItEasy loads these assemblies into the Neither load context. Since it's using LoadFile, it bypasses the shadow copy cache, and the files are loaded direct from the bin\Debug folder.
After this, the dependencies of the test project fail to load, resulting in a FileNotFoundException. Fusion binding logs show that it tries to load them, but they don't get copied in the shadow copy cache, and they fail to load. I can't see why. Here's the binding failure:
LOG: This bind starts in default load context.
LOG: No application configuration file found.
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/temp/todonancy/TodoNancyTests/bin/Debug/Nancy.Testing.DLL.
LOG: Assembly download was successful. Attempting setup of file: C:\temp\todonancy\TodoNancyTests\bin\Debug\Nancy.Testing.dll
LOG: Entering download cache setup phase.
LOG: Assembly Name is: Nancy.Testing, Version=0.17.1.0, Culture=neutral, PublicKeyToken=null
ERR: Setup failed with hr = 0x80070003.
ERR: Failed to complete setup of assembly (hr = 0x80070003). Probing terminated.
If I disable shadow copy cache, or use a newer version of FakeItEasy that doesn't use LoadFile, it all works. However, I can't blame the older vesion of FakeItEasy - I have users seeing the same errors with other projects and assemblies, all solved by disabling shadow copy cache.
Also, this scenario does work with ReSharper 7.1 - same plugin code and same test project. The only difference is the host application, but I can't see it doing anything different - there are no other assembly resolve event handlers subscribed, for example. The only real difference is that the 7.1 host uses remoting to talk to the Visual Studio application, and the 8.0 uses simple TCP sockets.
Does anyone have any idea why this is failing in the 8.0 version, and yet running with 7.1?
EDIT (07/08/2013):
I've managed to make it fail with a simple test:
[Fact]
public void Thing()
{
Assert.NotNull(Nancy.Bootstrapper.AppDomainAssemblyTypeScanner.Assemblies);
}
Using a copy of the Nancy class added straight into the project (with the referenced ScanMode and AssemblyExtensions classes). The only other content in the project is a reference to xunit.dll and xunit.extensions.dll.
It doesn't fail every time, it's frustratingly intermittent, but I can get it to throw a FileNotFoundException in this call to Assembly.ReflectionOnlyLoadFrom while trying to load the test assembly from the bin\Debug folder.
Here's the fusion log from the exception:
Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
Running under executable C:\Program Files (x86)\JetBrains\ReSharper\v8.0\Bin\JetBrains.ReSharper.TaskRunner.CLR4.MSIL.exe
--- A detailed error log follows.
=== Pre-bind state information ===
LOG: Where-ref bind. Location = C:\Users\Matt\Code\scratch\WeirdXunitFailures\WeirdXunitFailures\bin\Debug\WeirdXunitFailures.dll
LOG: Appbase = file:///C:/Users/Matt/Code/scratch/WeirdXunitFailures/WeirdXunitFailures/bin/Debug
LOG: Initial PrivatePath = NULL
Calling assembly : (Unknown).
===
LOG: This is an inspection only bind.
LOG: No application configuration file found.
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Attempting download of new URL file:///C:/Users/Matt/Code/scratch/WeirdXunitFailures/WeirdXunitFailures/bin/Debug/WeirdXunitFailures.dll.
ERR: Failed to complete setup of assembly (hr = 0x80070003). Probing terminated.
Unfortunately, this tells me nothing - the file:// url is valid, and the shadow copy cache contains xunit.dll and WeirdXunitFailures.DLL (the test project). Also, the Modules window in the debugger is showing me that WeitdXunitFailures.dll is already loaded, from the shadow copy cache location.
And again, the really weird thing is that the 7.1 runner works just fine.
EDIT:
In fact, I can get it to fail simply by calling:
[Fact]
public void Thing()
{
Assembly.ReflectionOnlyLoadFrom(#"C:\Users\Matt\Code\scratch\WeirdXunitFailures\WeirdXunitFailures\bin\Debug\xunit.dll");
Assembly.ReflectionOnlyLoadFrom(#"C:\Users\Matt\Code\scratch\WeirdXunitFailures\WeirdXunitFailures\bin\Debug\xunit.extensions.dll");
Assembly.ReflectionOnlyLoadFrom(#"C:\Users\Matt\Code\scratch\WeirdXunitFailures\WeirdXunitFailures\bin\Debug\WeirdXunitFailures.dll");
}
These are the project dll and the two xunit dlls. It's still very intermittent, but seems to be most easily reproduced after a complete rebuild, although it does still occur after several successful runs (so it's not the rebuild that's at fault)
Phew. The problem was (naturally) a subtle change in behaviour in ReSharper 8.
The test runner process API has a method to tell the main ReSharper process (i.e. devenv.exe) the location of the temp folder used for the test run - the shadow copy cache. This is because the test runner process usually can't delete the cache folder because it's still in use. ReSharper will then make several attempts to delete the folder for you, allowing time for the process to die gracefully.
ReSharper 7.1 would delete this folder at the end of a test run, or if the run was aborted.
ReSharper 8 deletes the folder as soon as you call you the method. The nunit test runner tells ReSharper about it at the end of the test run. I was telling it about it at the start. And so ReSharper would happily come along, while my tests were running, and delete whatever it could from the shadow copy cache, making it look like the shadow copy cache was properly broken.
I think I'll be filing a bug :)

Could not load file or assembly 'xx.DLL' or one of its dependencies. The specified module could not be found.?

I am having third party dll called "xx.DLL",i included in my web project, i copied and paste the project into IIS wweroot folder.I am using IIS7.5,then when i try to browse my application, i am getting the following error "Could not load file or assembly 'xx.DLL' or one of its dependencies. The specified module could not be found."
Its working fine in local PC's, but when i try to host and browse in Windows Server 2008 R2 Enterprise Service Pack 1(64-bit OperationSystem) i am getting the following error.
I don't know what is the problem ?
Any ideas?

Error in registering COM server from bat file lauched from RunOnce

I am currently working on my product installation in Windows XP 64-bit machine. I am trying to register my COM modules as part of installation. I am doing this by adding an entry in 'RunOnce' (registry) key to launch a bat file and registration is done from that bat file.
All my COM dlls are registered correctly but two of the COM servers (.exe) showing error that it failed to load one of its dependency dll. But the same dll is statically linked with another COM server and this server registered successfully !
And surprisingly running the same bat file directly(double clicking on it) doesn't generate any errors and its works fine for all assemblies!. I have checked this in couple of my test machines only of the machines showing this behavior. Unfortunately that't the customer tool machine.
Its not dependency dll not available issue. Because after registering all files by directly running the bat file, I could reproduce this again by adding a key in RunOnce manually and restarting the machine.
Additional info, I am accessing this machine remotely via logmein.
Exact error message: "This application has failed to start because XXX.dll was not found. Re-installing the application may fix this problem".
This XXX.dll is not available in the same path but its in another folder and its path is available in path variable.
bat file content is;
"C:\WINDOWS\system32\regsvr32.exe" RemoteControlHandler.dll
"C:\WINDOWS\system32\regsvr32.exe" ProcPgmHandler.dll
"C:\WINDOWS\system32\regsvr32.exe" GEM300Handler.dll
"C:\WINDOWS\system32\regsvr32.exe" ICEScreenAdapter.ocx
HIB.exe /regserver //Throws error
JobManager.exe /regserver
Cim300Adapter.exe /regserver
GemEquipmentCtrl.exe /regserver //Throws error
Hope this information is enough for experts, feel free to ask if you need any additional information.
Nixon

How Do I Get The Resource DLL Code Samples In The Windows SDKs To Compile And Run?

I am currently trying to build a Resource DLL on on Windows Server 2003 and 2008. I am currently working with the Resource DLL code samples supplied with the Windows SDKs, and I can't get them to work.
On Windows Server 2008 I succeeded compiling the Windows 7 SDK ClipBook Server sample, but couldn't get it to properly work in the cluster. When I insert the resource as a resource type to the cluster using "cluster restype /create /dll" it works, but the resource is listed with an unknown type instead of a ClipBook Server type, as I think it should have as it is the type defined in the Resource DLL's code.
I also succeed in creating a resource of that type, but I can never get it to go Online. I always get the error:
System error 5079 has occurred (0x000013d7).
The specified node does not support a resource of this type. This may be due to version inconsistencies or due to the absence of the resource DLL on this node.
And this is despite the fact that the resource is located on all the nodes in the cluster including the one I try to start the resource on.
On Windows Server 2003, I'm working with the Platform SDK version 5.2, and I can't even get the ClipBook Server Resource DLL code sample to compile. I always get MIDL1001 Error saying that it cannot open the file cluscfgserver.idl. I added the path of the file's location to the include path of the project. That didn't work. When I tried to hard-code the path of the file, I got several linker errors when trying to link with this file.
If anyone knows anything about any of these problems, I would appreciate any input.
Those examples are old and busted. Here are a few things I had to go through to get the similar "File Share Sample" to work:
Convert the project to x64 (supposedly 32 bit resources still work, but I haven't been able to verify that)
Add the module definition file (.def) to the linker input property page so that the Startup function is exposed
There were several spots in code where CompareString is used to check the resource type name and 0 is expected on success, but it actually returns CSTR_EQUAL (3).
This is probably why you get the "(Unknown Type)" name.
To register the resource extension, cluster.exe won't accept spaces in the dll name, so in my case I had to use cluster /REGADMINEXT:'FILESH~2.dll'
Only the Property Sheet extension interface is supported, everything else (context menu, wizards) has been removed as of Server 2008
Check the extension DLL stdafx.cpp sources for the Resource Type "ClipBook Server". It should be "ClipBook Server Sample": const WCHAR g_wszResourceTypeNames[] = L"ClipBook Server Sample\0"