Hadoop Streaming, C#, & Azure with External Libraries - c#

I'm using Hadoop Streaming to run a mapreduce job in C# on a Linux cluster in Azure. However, I need to use the MathNet.Numerics library. I grabbed the dll using the NuGet package manager then included the dll as a reference file and in a lib folder as well as ensured that the build action is set to: Embedded Resource.
Whenever I try to run the following command:
hadoop jar ./hadoop-streaming-2.6.0.jar -input wasb:///CSV/ -output
wasb:///Output/reducer1.txt -file ./Mapper.exe -mapper Mapper.exe
-file ./Reducer.exe -reducer Reducer.exe
I get the following error in my output file:
System.IO.FileNotFoundException: Could not load file or assembly
'MathNet.Numerics, Version=3.11.0.0, Culture=neutral, PublicKeyToken=null'
or one of its dependencies.
File name: 'MathNet.Numerics, Version=3.11.0.0, Culture=neutral, PublicKeyToken=null'
I've also tried to copy to MathNet.Numerics.dll to the cluster and include the file with a tag in the initial command:
hadoop jar ./hadoop-streaming-2.6.0.jar -input wasb:///CSV/ -output
wasb:///Output/reducer1.txt -file ./Mapper.exe -mapper Mapper.exe
-file ./Reducer.exe -reducer Reducer.exe -file ./MathNet.Numerics.dll
but had the same result.

On windows in VS 2014+
-Right click on "references", in the solution explorer.
-Select: Manage NuGet Packages
Click Browse, then type in the library your trying to install, it should grab everything you need including dependencies.
On Linux with Mono:
-https://docs.nuget.org/contribute/setting-up-the-nuget-development-environment
-Scroll down to the Linux install instructions
I have not used NuGet on Mono, but I assume it should work exactly the same way. I would at least try it to see if you're simply missing a dependency somewhere, as it should auto-magically get them for you.

Related

Running in VS2019 Admin Cmd window -- gacutil.exe error: "Failure adding assembly to the cache. The system cannot find the file specified."

Running in VS2019 Admin Cmd window -- gacutil.exe error: "Failure adding assembly to the cache. The system cannot find the file specified."
GAC util path: C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.7.2 Tools\gacutil.exe
Command line: gacutil.exe -i "DuraSysOrdFuncs.dll" -r FILEPATH "C:\Windows\DuraSysOrdFuncs.dll" ""
I picked this version of GACUtil just because the C# library was built with a target framework of .Net 4.7. It isn't clear to me that it much matters.
Doesn't matter what I put in the 3rd parameter of -r. Doesn't matter where I put my assembly on my local disk. Same error message.
I'm trying to put this in GAC because I need to call it from an SSIS package running on SQL Server 2016. I have opened Sysinternals ProcMon per a suggestion of #HansPassant in a different post. Not familiar with tool so haven't found the file location error. . . if that is the actual issue.
Any input much appreciated
The answer, as the commenters noted, and as ProcMon indicates, is to just include the path for the .net assembly you're registering: gacutil.exe -i "C:\YourAssemblyFileLocation\YourDLL.Dll" That's all it takes. . .you don't normally need -r parameters, etc. Thanks!
You can use powershell to register assemblies into GAC. It doesn't need any specific installation.
Set-location "C:\Temp"
[System.Reflection.Assembly]::Load("System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
$publish = New-Object System.EnterpriseServices.Internal.Publish
$publish.GacInstall("C:\Temp\myGacLibrary.dll")
If you need to get the name and PublicKeyToken, refer How do I find the PublicKeyToken for a particular dll?

How to Publish an WinForms into 1 executable?

I wanted to Publish a WinForm (.Net framework) as an executable (JUST 1 File). I had tested different ways of doing it.
I had tried
dotnet publish -r win-x64 /p:PublishSingleFile=true /p:IncludeNativeLibrariesForSelfExtract=true --output ../result
Error: C:\Program
Files\dotnet\sdk\5.0.302\Microsoft.Common.CurrentVersion.targets(3746,5):
error MSB4062: The "Microsoft.Build.Tasks.AL" task could not be loaded
from the assembly Microsoft.Build.Tasks.Core, Version=15.1.0.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a. Confirm that the
declaration is correct, that the assembly and all its
dependencies are available, and that the task contains a public class
that implements Microsoft.Build.Framework.ITask.
[C:\RPIC\PICDashboard\PICDashboard\PICDashboard\PICDashboard.csproj]
and
msbuild /t:Publish /p:PublishSingleFile=True /p:IncludeNativeLibrariesForSelfExtract=True /p:SelfContained=True /p:Configuration=Release /p:Platform="Any CPU" /p:RuntimeIdentifier=win-x64 /p:OutputPath=../result
msbuild works without error but it produces many files as what's in the Debug and Release folder. It also give me a warning
C:\RPIC\PICDashboard\PICDashboard\PICDashboardSetup\PICDashboardSetup.vdproj.metaproj : warning MSB4078: The project file "PICDashboardSet
up\PICDashboardSetup.vdproj" is not supported by MSBuild and cannot be built.
I had also tried
dotnet msbuild -target:Publish -property:PublishSingleFile=True -property:IncludeNativeLibrariesForSelfExtract=True -property:SelfContained=True -property:Configuration=Release -property:RuntimeIdentifier=win-x64 -property:Platform="Any CPU" -property:OutDir=../result
Error: C:\Program
Files\dotnet\sdk\5.0.302\Microsoft.Common.CurrentVersion.targets(3746,5):
error MSB4062: The "Microsoft.Build.Tasks.AL" task could not be loaded
from the assembly Microsoft.Build.Tasks.Core, Version=15.1.0.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a. Confirm that the
declaration is correct, that the assembly and all its
dependencies are available, and that the task contains a public class
that implements Microsoft.Build.Framework.ITask.
[C:\RPIC\PICDashboard\PICDashboard\PICDashboard\PICDashboard.csproj]
Is there any way that allows me to publish WinForms as a single exe?
"Any way" - yes, though I can't say "always"/"for all" applications and its dependencies.
Also, the following is done in Visual Studio (not dotnet cli - I haven't tried) with a trivial "Hello World" Windows Forms app (no external dependencies)
In your Application Build properties -> Release Configuration set Debugging information to None
In your Publish Settings
Result (in the bin\Release\net5.0-windows\publish\ folder set above):
Running an awesome app :)
Hth...
Which IDE version are u using. You cam choose produce single file in publish setting (1click publish method for vs2019)

Unable to connect to SQlite using mono

In my program I have this simple code:
using System;
using System.Data;
using Mono.Data.SqliteClient;
....
IDbConnection cnx = new SqliteConnection("URI=file:reestr.db");
cnx.Open();
....
And this is how I compile it:
$ mcs Test.cs -r:System.Data.dll -r:mono.data.sqliteclient.dll
It compiles ok. But when I run it with ./Test.exe, I get this error messages:
Missing method .ctor in assembly ....
Unhandled Exception:
System.IO.FileNotFoundException: Could not load file or assembly 'Mono.Data.SqliteClient, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756' or one of its dependencies.
File name: 'Mono.Data.SqliteClient, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756'
I'm not sure what I'm doing wrong here and how to repair it.
PS. I'm using Ubuntu as my OS.
It appears that Mono.Data.SqliteClient can not find the native SQLite binaries:
Prerequisites If you do not have SQLite, download it. There are
binaries for Windows and Linux. You can put the .dll or .so along side
your application binaries, or in a system-wide library path.
Ref: http://www.mono-project.com/docs/database-access/providers/sqlite/
To obtain pre-compiled native binaries (or source) for your platform:
http://www.sqlite.org/download.html
Also if you have the SQLite native shared libraries installed, are they available via dlopen? If not, you can assign the LD_LIBRARY_PATH env. var so Mono can find them at runtime.
Linux Shared Library Search Path From the dlopen(3) man page, the
necessary shared libraries needed by the program are searched for in
the following order:
A colon-separated list of directories in the user’s LD_LIBRARY_PATH
environment variable. This is a frequently-used way to allow native
shared libraries to be found by a CLI program. The list of libraries
cached in /etc/ld.so.cache. /etc/ld.so.cache is created by editing
/etc/ld.so.conf and running ldconfig(8). Editing /etc/ld.so.conf is
the preferred way to search additional directories, as opposed to
using LD_LIBRARY_PATH, as this is more secure (it’s more difficult to
get a trojan library into /etc/ld.so.cache than it is to insert it
into LD_LIBRARY_PATH). /lib, followed by /usr/lib.
Ubuntu Notes:
$ sudo apt-get install sqlite
$ ls -1 /usr/lib/libsqlite*
/usr/lib/libsqlite.so.0
/usr/lib/libsqlite.so.0.8.6
$ export LD_LIBRARY_PATH=/usr/lib:$LD_LIBRARY_PATH
$ mono ./Test.exe
I solve the problem in my Mac in this way. Right Click in Mono.Data.Sqlite on References and click in Local Copy. This make mono copy dll to debug folder and your application will find the library.
OBS: Sorry for my bad english.

BLToolkit-mysql-connector exception: Could not load file or assembly MySql.Data, Version=6.9.7.0

I am using BLToolKit (ver. 4.3.2.0) and MySql Connector (BLToolkit.Data.DataProvider.MySql.4 of version 4.3.2.0) from NuGet.
When I run my web.app in the mono-environment all work perfectly. But on the IIS I get an exception:
FileLoadException: Could not load file or assembly 'MySql.Data, Version=6.9.7.0, Culture...
What is wrong?
UPD: also I used the MySql.Data (from NuGet), version 6.9.8.0
Just a guess: Is the corresponding assembly in the same folder as your program (should be a library file like "MySql.dll" or "MySql.Data.dll")?
EDIT: This problem has been reported previously:
Could not load file or assembly 'MySql.Data, Version=6.2.2.0
I had the samen problem and resolved it with a copy of the previous version.
- Download the version you need from https://downloads.mysql.com/archives/c-net/
- install the connector on a PC (not the one you are using, it won't install
- copy the folder MySQL Connector Net 6.9.5 from C:\Program Files (x86)\MySQL to the same folder on your PC.
- In Visual studio: remove the MySQL.Data-reference.
- Add the reference again using 'Addreference / Browse'
- Choose MySQL.Data.dll in the folder C:\Program Files (x86)\MySQL\MySQL Connector Net version\Assemblies\v4.5

Can't build NUnit testing project under Mono and Linux

I have a complex solution (developed under Windows, deployed under GNU\Linux) with a number of unit-testing projects, using NUnit 2.9.3.
Here's a reference from project:
<Reference Include="nunit.framework, Version=2.9.3.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\Program Files\NUnit 2.9.3\bin\net-4.0\nunit.framework.dll</HintPath>
</Reference>
I downloaded and built NUnit 2.9.3 from source:
$ xbuild solutions/MonoDevelop/NUnit.Framework.sln /p:Configuration=Release
and installed into GAC:
$ gacutil /i solutions/MonoDevelop/bin/Release/nunit.framework.dll
$ gacutil /l nunit.framework
The following assemblies are installed into the GAC:
nunit.framework, Version=2.9.3.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77
Number of items = 1
and deleted local mono nunit installation:
$ rm /usr/lib/mono/2.0/nunit*
$ rm /usr/lib/mono/4.0/nunit*
but when I try to build my solution:
$ xbuild MySolution.sln | grep error
: error CS0006: Metadata file `/usr/lib/mono/2.0/nunit.framework.dll' could not be found
What do I wrong?
Build tools do not normally resolve assemblies from the GAC (except possibly as a last resort). On .NET they they "assembly folders" registered in the registry. On Mono they use "pkgconfig". You may have removed the nunit assemblies but you did not remove or fix the pkgconfig ("pc") file that tells xbuild and MonoDevelop where to find the dll.
This kind of stuff is why it's a bad idea to alter things installed by packages. You should either uninstall the package properly, or use the appropriate environment variables to override packaged stuff.
In this case, I would suggest you create a pc file for your new nunit assemblies, and put it into the /usr/local/lib/pkgconfig directory (/usr/local is the prefix for installing stuff you build from source), or put it somewhere else and have that somewhere else included in the PKG_CONFIG_PATH environment variable.
See also:
The MonoDevelop FAQ entry
And for some general background on configuring Mono environments, see:
Parallel Mono Environments
How not to break Mono installations
What I will try is to copy the NUnit 2.9.3 to my source file folder such as (solution folder)\lib. Then add this reference locally and make sure the tag matches this local path.
When that is configured, I think xbuild should use this local copy directly instead of reading GAC or other preconfigured paths. If not, I will report a bug to Mono team.
The /pkg option of the mono compiler worked fine for me ...
dmcs test.cs /r:System.Configuration.dll /r:System.dll /pkg:nunit
FWIW, I installed nunit using the apt-get package manager (on Ubuntu) ...
sudo apt-get install nunit

Categories

Resources