Wrong Interop.Shell32.dll being loaded suddenly - c#

I have a program that has been working just fine, however when I made a small change to the way the program loads from its ini, the zipping function stops working. I stepped through the program and found the error to be occuring on the following line:
var fs = File.Create(zipPath);
fs.Write(emptyZip, 0, emptyZip.Length);
fs.Flush();
fs.Close();
var sc = new Shell32.ShellClass();
var srcFlder = sc.NameSpace(program.Path); //THIS LINE
var destFlder = sc.NameSpace(zipPath);
var items = srcFlder.Items();
destFlder.CopyHere(items, 20);
System.Threading.Thread.Sleep(500);
ZippedPrograms.Add(zipPath);
I double checked the variables program.Path and others being sent to the ShellClass(), and they are not null or empty. This is the actual error that pops up when the program gets to this line:
Doing some googling I find that apparently the Shell32.dll I have referenced in my program does not work right with 7 (or server 2008, the target environment), and I needed to reference the XP version instead (52kb versus 48kb dll size). One of the links where I found this info: click me.
So I created a virtual machine and installed WinXP Professional on it, and navigated to C:\WINDOWS\system32\ and copied the Shell32.dll located there to my host computer. Strange enough, the DLL is ~8mb in size rather than the 52kb I was expecting. When I add it as a resource from VS2012, I browse to the copied file and add it (with copy local), but then for some reason it ends up being 48kb in size and the program continues to crash at the above mentioned line.
I have tried using DotNetZip along with other C# libraries for zip management, and for some reason they never work properly (creating corrupted ZIP files, not creating them at all, refusing to add random files/folders to the archive, etc). Before this issue the program was working flawlessly, so more than anything I am confused as to why all of a sudden it is not working and why the Shell32.dll is not A) the 8mb version I reference, and B) 'stripped down' to 48kb. On top of that, I checked the current deployment of the program, which lacks some features of the current version, among other things, and the DLL there is the 48kb size, and this particular deployment has worked with no problems.
I should also mention that I am currently running Windows 8 Pro, and developing in VS2012. The deployment environment is Windows Server 2008 R2. I originally wrote this program in VS2010 on Windows 8 Ultimate. When I opened the project for the first time in VS2012, there was no upgrade dialogue. All OS's listed (except WinXP Pro) are x64.
Has anyone had any experience with these issues/happenings? Any insight/tips/solutions will be greatly appreciated.
Thank you!

Dragging across an outdated system dll to a newer version of Windows is something that's just bound to fail, especially if it's (as in this case), a COM interop DLL. If Windows 8 is running a COM service, it's going to be running it with its "own" version of the DLL. If you then try to interact with it using an interface DLL for a different version, you'll get an interface mismatch. As you've seen, E_NOINTERFACE.
You're trying to use a version 6 DLL to communicate with a version 8 service. It's bound to run into problems.
The difference in size might have something to do with Visual Studio stripping the deployment DLL down to just the interfaces, instead of including all the implementation.

Related

C# Project : Build Folder : Build a project on a computer and run it on another computer

I have a C# project. To run it, I need to provide 2 arguments.
I want to create a build folder, that I can just copy/paste on another computer and run in the future. First, I build the project on a computer, then I copy/paste the build folder on another computer (I use Remote Desktop Connection). The build folder contains executable, configuration file (XML) and .dll files.
When I run the program on the second computer, I had this response on the console : System.Runtime.InteropServices.COMException (0x80040154): Retrieving the COM class factory for component with CLSID {99AEA70E-4D13-44BF-A878-33345CBFCBC8} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
I checked .NET Version on both computer and it is the same version.
I tried different case of build (Configuration : Release and Platform : Any CPU/x64/x86).
I saw some things like ClickOnce but I can't use it because of the 2 arguments.
Moreover, to run this project, I use a UI (same for both computer). The UI work on both computer. This update configuration file and run the project. On the first computer (we build the project on this one), the program works correctly. On the second computer, the UI works and when I run the program through UI, I have the issue above.
Are there any solution to fix this issue ?
I found some solution but they are old and they doesn't work.
As mentioned in the comment, you are using a COM Component, which might need to be installed on your second computer as well.
There may be a way, when you locate the references, find the respective DLLs and copy them with your Executable. If you have a look at the RedemptionLoader, Dmitri is doing exactly, what you need to do, to load the types from the DLLs in there.
However, make sure to have everything in one assembly, that uses the types in question, when using them without installing the COM Component. Otherwise you will get weird error messages.
Thanks for your answers. It helps me to understand the issue.
So, this program permits to do some things with Photoshop. On the first computer, I have Photoshop CS6 and on the a second one I have Photoshop CC. To fix the issue, I will create a build folder for Photoshop CS6 and another one for Photoshop CC.
I tried to copy/paste the build folder from the first computer (with Photoshop CS6) on a third computer, with Photoshop CS6 too. This works !
The issue was caused by the version of Photoshop.

Can't run a windows form app on other PC, can't find a dll from a project of the same solution

(First things first, I'm kind of new on this type of programming)
I'm trying to make a windows form application where i request data from a PLC so it can be stored in a access database. This application is going to be running on a different computer.
On the solution i created and besides my project I'm using an existing project that works "like" the communication between the app and the PLC, it is called LibplctagWrapper (on my main project I create a reference to this last one)
(https://www.mesta-automation.com/how-to-communicate-to-an-allen-bradley-plc-with-c-and-libplctag-ethernet-ip-library/),
and it works on my PC, but every time y copy the Bin folder to the new computer, then run the app, it opens, but a warning popup messages appears. Saying: Unable to load DLL "plctag.dll": The specified module could not be found. (Exception from HRESULT: 0x8007007E).
The LibplctagWrapper is in another directory than my Solution and Main Project so I moved it to C: so the direction will be the same on the new computer. But it doesn't work.(copy the LibplctagWrapper in C: of the new pc as well)
Moved the entire solution/main project to C: as well... the same result.
Instead of just the bin folder i copied the entire project folder... im thinking the problem goes with the fact that the LibplctagWrapper is not in the same direction? but I don't know how to place it in the same direction... I search on visual studio but I never saw the option to move it.
Unable to load DLL "plctag.dll": The specified module could not be found. (Exception from HRESULT: 0x8007007E).
This error message is quite generic, missing dependencies can cause it as well as the mentioned module not being present at all. Check the Dependency Walker ( http://www.dependencywalker.com/) to discover required C++ runtimes or something alike. Remember to take x86/x64 into consideration.
#JavierMata - I think you have probably resolved this issue, but for others encountering something similar you can use the recently released official wrappers which can be downloaded via nuget. Github link: https://github.com/libplctag/libplctag.NET
The libplctag.NativeImport package handles loading the appropriate C runtime so you don't have to.

C# System.DllNotFoundException

I have a simple application using a product activation system offered by cryptlex (cryptlex.com).
The program works correctly on my computer, but when I try to run the program on another machine it returns this error:
I've already made sure that the dll is inside the executable folder and everything looks OK.
When I remove all part of cryptlex the program works perfectly on any machine (x86-x64)
I used depencywalker to check for errors and found these two in the executable that uses cryptlex:
Windows 7 64bits,
.NET Version: 4.0
You can use Process Monitor to record all file activities of the program. Set a filter for your executable. After reproducing the error, save the log as XML file.
Then run ProcMon Analyzer (note: I'm the author of it). It will analyze the file and give a list of DLLs that were not found.
You could also do that manually, but note that some DLLs may not be found at first, but later be found when looking in the %PATH% environment variable etc. The tool will remove all those entries which have PATH NOT FOUND first but SUCCESS later.
While the DLL is present, have you checked the bitrate?
Most C# projects default to building against Any CPU - if the DLL is specific to a bitrate (ie x86 or x64) then it might be that the program picks the wrong bitrate on end machines (usually x86) but the right one on your machine (x64). This is usually best resolved by building out different x86 and x64 versions; it's messier, but only .NET itself is good at using the Any CPU paradigm.
The exception should have detail about what DLL in particular was not found - maybe look closer?
GPSVC and IESHIMS missing should not be a problem; as indicated by the hour glass, they're deferred dependencies anyway.

Fail to load DLL in Windows 2008 R2 having full permissions control

I have developed an C# application that run very well in local.
But there is a problem when i put on the server.
The application uses a DLL library in his references (A.dll) and in a point of the execution the A.dll creates in the Temp directory another DLL (embedded in it, let's call it B.dll).
But when the A.dll try to load the B.dll an exception is threw:
system.invalidoperationexception: failed to load B.dll
I have not access at the DLLs source, are libraries.
So recap:
The process have the full control permission on the file and path.
(cheked)
Is running like Administrator. (checked)
In my application if I try to open the dll in binary mode, the
operations have no problems.
Runs well on every OS that i have tested (Windows 8_64 / XP_32 /
2008_32 / 7_64), but fails with 2008 R2 64.
I have tried to ReDownload, rename, reinstall the B.DLL, i have putted the program in the same path of the B.DLL, etc etc, with no results.
So at this point I think that is a security problem on the server, like "Processes cannot load DLLs" or something similar.
The exception:
http://i.imgur.com/NmB2Fth.png?1
Anyone can suggest me any solution? Would i check better? Where?
P.S
IF i try to register the dll i got the same error of this:
Register DLL file on Windows Server 2008 R2
The solution was simple.
I have used a very useful tool named Event Viewer (Start->Execute->eventvwr.exe)
When i started my application a new error event was showed on the Windows Logs->Applications:
Activation context generation failed for "C:\Temp\APP\myfile.dll".
Dependent Assembly Microsoft.VC90.CRT,processorArchitecture="x86",
publicKeyToken="1fc8b3b9a1e18e3b",type="win32",version="9.0.21022.8" could not be found.
Please use sxstrace.exe for detailed diagnosis.
A quick search and the result was that the server needed the Visual C++ Runtime for x86 (x86 because my application works in the 32bit application pool)
Once installed this package: http://www.microsoft.com/en-us/download/details.aspx?id=5582
Everything worked like a charm.
I hope this will help anyone to save some time!!

What is needed to run XSP as a standalone server on Windows?

I'm trying to setup a minimal copy of XSP for Windows for students to use in an ASP.NET intro course. They have Visual C#, and I don't want to confuse matters by giving them Mono per se. I don't want to use IIS for various reasons. I did a similar thing previously for JSP with a zipped copy of Jetty, which worked splendidly.
As an experiment I've installed Mono 2.10.9, and can successfully run XSP directly from the installation. However, the executable (xsp2.exe) is in lib\mono\2.0\winhack, and the server environment is in lib\xsp\test. I want to create a directory containing a minimal set of files (xsp2.exe, xsp.exe.config, Mono.WebServer2.dll, and whatever else is needed) which I can zip up and give to the students. However, all I get is a "File Not Found" exception for Mono.WebServer2.
I copied Mono.WebServer2.dll across, and then got the same for Mono.Security. When I copied Mono.Security.dll, the error refers to Mono.WebServer2 "or one of its dependencies" (without telling me which one).
Can anyone tell me what I need as a minimal setup please?

Categories

Resources