SISS package gets corrupted while using custom dlls - c#

I've created a SSIS package (SQL Server Data Tools for Visual Studio 2013) for importing some data. Long story short, I need to embeed some dlls to be called in runtime using this method:
Embedding assemblies inside another assembly
Tried outside SSIS script component and is working.
Problem is, when you try to add a .dll as a resource the package gets corrupted and throws
Is there any workaround to use custom assemblies into a SSIS package without deploying them or fix this error?
Thank you

Looks like the problem is because the .dll is stored as bytes in the XML file of the package, and probably finds some character not allowed.
The workaround was transform that .dll into a Base64String, embeed it as a resource on the project and then do the way back.

Related

could not load file or assembly 'newtonsoft.json'

am create a desktop application using wpf. am installd newtonsoft.json(using package manager) for json parsing. after am successfully build and run my application.
then iam copy the appliction.exe from project source > bin > debug to my Destop. then am attempt to run exe from Desktop, but i got an error message
like this
could not load file or assembly 'newtonsoft.json' ..... system cannot find
the path
what is the issue? any missing
The exe needs to be able to link to the dll when you run it. That's why it works in your debug folder (the newtonsoft dll is there if you look), while it's presumably not in your desktop.
You can either:
1) Make sure the dll is included with the exe (copy it to your desktop, for example). If you distribute the exe in a zip file, just include the dll. If you use an installer, make sure it also installs the dll to the same folder.
OR
2) ILMerge the DLL directly into your exe - this means the exe contains the entire DLL and will always be able to find it. There are NuGet packages that can do this for you autonatically. Try adding "MSBuild.ILMerge.Task" via NuGet, and then build your project again.
(There are other solutions but they're generally terrible, like PATH, so I'm not going to explain how they work).
Personally, I'd usually recommend the former - just include the DLL. Look inside folders where you have software on your PC (e.g. most folders in Program Files) - you'll see that's how it's usually done, with DLLs installed as separate files. ILMerge can get messy if you don't know what you're doing and you start doing weird things with your DLLs.

c# script task SSIS include/access dll from reference not in GAC

I have:
SSIS/.dtsx package with a script task in SSIS that I added references to. It works fine locally (assuming the .dlls are in the GAC).
When depolying on the server it failes (assuming the .dlls are NOT references in the GAC) and I can not add them.
The SSIS package is stored in Integration Services on the SQL server in the Stored Packages - MSDB
The job runs on a schedule
I do not have access or the ability to add .dlls or add items to the GAC on the server.
What I need to do is find a way to include the .dll in the script task inside the SSIS package so that the References point to those .dlls instead of any in the GAC.
I searched quite a bit and could not find a way to do this. Is it even possible? If so what/how do I do it?
Locally it does work, in server it cannot find a required reference. what referenced dll is missing? you know it?
Once you know what dll you need, get a copy of it and, even if you cannot install it on the server GAC, you can deploy it in the same folder you deploy your executable.
At runtime, your executable will first try to load the dll from the same folder, if not found, it will try searching in GAC.

A reference to .dll could not be added. Please make sure that the file is accessible, and that it is a valid assembly or COM component

Ok now i will try to explain my problem as much as possible. I want to use popular compression algorithm 7zip at my c# project
There is already NuGet package for 7zip
Now when i install 7zip page https://www.nuget.org/packages/SevenZipSharp/0.64.0 it installs fine however it gives error when i try to run
An unhandled exception of type 'SevenZip.SevenZipLibraryException' occurred in SevenZipSharp.dll
Additional information: Can not load 7-zip library or internal COM error! Message: failed to load library
So i decide to add dll file manually and i get this error below
---------------------------
Microsoft Visual Studio
---------------------------
A reference to 'D:\51_doktora tez projesi\program_crawler\doktora_tez_projesi_crawler_program\ExternalDLLs\7z_9_38_2015_01_03.dll' could not be added. Please make sure that the file is accessible, and that it is a valid assembly or COM component.
---------------------------
OK
---------------------------
Ok but i found a solution and it works that way
First install nuget package
And before start calling functions set path
SevenZip.SevenZipExtractor.SetLibraryPath("SevenZipSharp.dll");
SevenZip.SevenZipCompressor.SetLibraryPath("SevenZipSharp.dll");
Ok second question which is also interesting
I wanted to use latest version of 7zip DLL file. So downloaded it from official website : https://sourceforge.net/projects/sevenzip/files/7-Zip/9.38/
Downloaded MSI installed and got 64bit dll file. However when i try to reference this file, it fails with error message above: Please make sure that the file is accessible, and that it is a valid assembly or COM component.
However the trick works again
I install NuGet 7zip package. Then before calling functions i set these 2 lines of code and it uses latest version of DLL file
SevenZip.SevenZipExtractor.SetLibraryPath("ExternalDLLs/7z_9_38_2015_01_03.dll");
SevenZip.SevenZipCompressor.SetLibraryPath("ExternalDLLs/7z_9_38_2015_01_03.dll");
So i am looking for answers why all these happens? Why i can not directly add as a reference the DLL file however the trick works?
windows 8.1 64bit, Visual Studio 2013 update 3 WPF application
Part of your problem most likely stems from the fact that SevenZipSharp is merely a wrapper for the 7z.dll, which to the best of my knowledge is a c++ dll. The project page, for SevenZipSharp, also mentions that any compatible dll can be used and needs to be specified:
SevenZipSharp requires a 7-zip native library to function. You can specify the path to a 7-zip dll (7z.dll, 7za.dll, etc.) in LibraryManager.cs at compile time, your app.config or via SetLibraryPath() method at runtime. + "7z.dll" is the default path. For 64-bit systems, you must use the 64-bit versions of those libraries.
7-zip ships with 7z.dll, which is used for all archive operations (usually it is "Program Files\7-Zip\7z.dll"). 7za.dll is a light version of 7z.dll, it supports only 7zip archives. You may even build your own library with formats you want from 7-zip sources. SevenZipSharp will work with them all.

Visual Studio - Referencing third party DLL

I am using Visual Studio 10 within a C# MVC appliction.
I have a qustion on a .dll reference. I am using a third party reference called
Ionic.Zip.dll. What I am not sure about is that it currently points to a location on my C: drive.
How and what is the best practice for me to put this .dll so that when I check in the project, others can also see this .dll without it blowing up.
Thanks
I would typically put a Library folder in my application structure, place the 3rd party dll in that folder, and then reference that dll. Then ensure that the library folder is checked into your source control.
Now, anyone that pulls your source will have the required dll.
Even easier...simply add a reference to DotNetZip via NuGet, the Visual Studio Package Manager:
http://nuget.org/packages/DotNetZip
And you shouldn't have to worry about it.
The best way is to use Nuget.
But in some cases Nuget is not available or not getting compative, so as our friend says, its better put a Library folder in application structure, place the 3rd party dll in that folder, and then reference that dll. Then ensure that the library folder is checked into source control. Now, anyone that pulls source will have the required dll.

How do you manage generated code in Visual Studio - in particular, creating DLLs from .idls

I'm trying to add a generated COM interop assembly project to my solution, and the only solution I could come up with feels really nasty.
I created a .net dll project, removed all .cs files from it and then created the following post-build event:
call "$(DevEnvDir)..\tools\vsvars32.bat"
midl.exe $(ProjectDir)relative-path-to-my-idl\MyComName.idl /tlb MyComName.tlb
tlbimp.exe /keyfile:path-to-my-key\k.snk MyComName.tlb
Essentially, I first create an empty DLL, then overwrite it with a real interop DLL. And there's no dependency management here - it's created every time.
Is there a better way to do this?
The MIDL compilation can be handled by making the COM interop project a managed C++ project (instead of a C# project) then adding the idl and h to the project as regular source files.
You can overcome the dependency problem by using MSBuild tasks directly instead of a PostBuild batch file, which line up nicely with the MSBuild dependency system.
However, why are you generating the file manually from an idl? When I need COM interop, I just import it and put the generated assembly (*.Interop.dll) into version control. This way, you always have the version you need and it's already ready to use, and Visual Studio can find the interop DLL before the first build, i.e. Intellisense is there right from the beginning.
Now some people won't like to check in a binary file, which I typically agree with, but well, if it works... :)
Of course, my method won't work if building the COM server is part of building the solution. In this case, just try to put the generation into the MSBuild script to get rid of the dependency thing, unless Visual Studio accepts a reference to a solution-internal non-.NET-COM project.

Categories