Topic "Getting error loading dll in Visual Studio 2010"

Author Message
themrkunkel
[View user's profile]

Joined: 2012-11-09
Posts: 1
Location: United States
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
Advertisements
RedJungle
[View user's profile]

Joined: 2012-11-18
Posts: 4
Location: Napier, New Zealand
I'm getting the exact same error.

Specific information is
Visual Studio 2012
.Net 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:

Last edited by RedJungle on 2012-11-19 20:16; edited 1 time in total
RedJungle
[View user's profile]

Joined: 2012-11-18
Posts: 4
Location: Napier, New Zealand
Well I think I found a "work-around".

RedJungle wrote:
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

--snip--
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.
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.
[snip]


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.
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25034
Location: Prague, Czechia
If I understand your problems correctly, the resolution is documented here:
https://winscp.net/eng/docs/library_install#vs
RedJungle
[View user's profile]

Joined: 2012-11-18
Posts: 4
Location: Napier, New Zealand
prikryl wrote:
If I underatand your problems correctly, the resolution is documented here:
https://winscp.net/eng/docs/library_install#vs


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.
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25034
Location: Prague, Czechia
This issue has been added to the tracker:
https://winscp.net/tracker/show_bug.cgi?id=945
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License