Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

RedJungle

Re: Getting error loading dll in Visual Studio 2010

@martin: Well yes and no... you are correct that the resolution you documented was the core of what I used, But at RunTime .NET 4.5 was reporting that it couldn't "find" the assembly of WinSCP.dll, so while the solution required a rename of the WinSCP.dll to WinSCPnet.dll in order to set a reference to it, the Original WinSCP.dll is also required in the bin directory. So to be clear in order to avoid GAC deployment and support Bin Deployment / xcopy you need to...

  • Make a copy of WinSCP.dll and rename it to WinSCPnet.dll
  • In Visual Studio 2012 project set a reference to newly created WinSCPnet.dll
  • Compile and set up WinSCP calls in project
  • Include BOTH WinSCP.dll and WinSCP.exe in solution with Build Action None and copy to output

In order for it to run you will then end up with the following 3 assemblies in your bin

  • WinSCP.exe
  • WinSCP.dll
  • WinSCPnet.dll

I would like to suggest that perhaps it would make sense to rename the WinSCP.dll to be WinSCPNet.dll as part of the compile then you wouldn't need the original workaround or this extra workaround, and the usage / target of the components would be self documenting.
RedJungle

Re: Getting Same Error

Well I think I found a "work-around".

So the fix was interesting, I renamed the WinSCP.dll to WinSCPnet.dll, then I included in my project BOTH the originally named WinSCP.dll and the WinSCP.exe as no action but always copy to output directory.

So by referencing the WinSCPnet.dll in the project I can then use the Library, but then during runtime the project doesn't actually use or look for the WinSCPnet.dll, instead it loads and uses the WinSCP.dll. And everything seems to work...

If you agree this is a reasonable way to solve this problem I will add it to the Wiki.
RedJungle

Getting Same Error

I'm getting the exact same error.

Specific information is
Visual Studio 2012
.NETt Framework 4.5
WinSCP 5.1.1
Renamed WinSCP.dll to WinSCPnet.dll
Both WinSCP.exe and WinSCPnet.dll are in Bin directory.
WinSCPnet.dll is correctly registered in Project and Project is compiling

If I leave the default name of WinSCP.dll, I am unable to register the DLL within the project, if I rename it as per the instruction Wiki, as you can see in the below exception details the system is still trying to load WinSCP.dll.

Exception Details below
System.BadImageFormatException was unhandled
HResult=-2146234344
Message=Could not load file or assembly 'WinSCP, Version=1.0.2.2735, Culture=neutral, PublicKeyToken=b5f19f5762436b89' or one of its dependencies. The module was expected to contain an assembly manifest.
Source=FtpCsvBL
FileName=WinSCP, Version=1.0.2.2735, Culture=neutral, PublicKeyToken=b5f19f5762436b89
FusionLog==== Pre-bind state information ===
LOG: User = CELESTIALTEMPLE\Matthew.Hintzen
LOG: DisplayName = WinSCP, Version=1.0.2.2735, Culture=neutral, PublicKeyToken=b5f19f5762436b89
(Fully-specified)
LOG: Appbase = file:///C:/Projects/BST Clients Direct/Scantron/IPaper/IPaperRinconBridge/IPaperRinconBridgeUI/bin/Debug/
LOG: Initial PrivatePath = NULL
Calling assembly : FtpCsvBL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Projects\BST Clients Direct\Scantron\IPaper\IPaperRinconBridge\IPaperRinconBridgeUI\bin\Debug\IPaperRinconBridgeUI.vshost.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Post-policy reference: WinSCP, Version=1.0.2.2735, Culture=neutral, PublicKeyToken=b5f19f5762436b89
LOG: Attempting download of new URL file:///C:/Projects/BST Clients Direct/Scantron/IPaper/IPaperRinconBridge/IPaperRinconBridgeUI/bin/Debug/WinSCP.DLL.
LOG: Attempting download of new URL file:///C:/Projects/BST Clients Direct/Scantron/IPaper/IPaperRinconBridge/IPaperRinconBridgeUI/bin/Debug/WinSCP/WinSCP.DLL.
LOG: Attempting download of new URL file:///C:/Projects/BST Clients Direct/Scantron/IPaper/IPaperRinconBridge/IPaperRinconBridgeUI/bin/Debug/WinSCP.EXE.
ERR: Failed to complete setup of assembly (hr = 0x80131018). Probing terminated.


StackTrace:
at Scantron.IPaper.BL.FtpDownload..ctor(String directoryPath, String ftpUri, String ftpUserName, String ftpPassword)
at Scantron.IPaper.UI.Main.ImportButton_Click(Object sender, EventArgs e) in c:\Projects\BST Clients Direct\Scantron\IPaper\IPaperRinconBridge\IPaperRinconBridgeUI\Main.cs:line 155
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at Scantron.IPaper.UI.Program.Main() in c:\Projects\BST Clients Direct\Scantron\IPaper\IPaperRinconBridge\IPaperRinconBridgeUI\Program.cs:line 15
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
themrkunkel

Getting error loading dll in Visual Studio 2010

Could not load file or assembly 'WinSCP, Version=1.0.2.2735, Culture=neutral, PublicKeyToken=b5f19f5762436b89' or one of its dependencies. The module was expected to contain an assembly manifest.

I renamed the dll to WinNetSCP to avoid issues with the WinSCP.exe, not sure if that would have anything to do with this.

Not sure what I need to do to resolve.

Thanks