I have a C# script to resize jpg files. It is a rather simple script using the Microsft System.Drawing dll.
But when I execute the SQL function fn_tsd_net_resizeimage() I got a error.
The sp_test() is working fine, that function does not have dependencies.
The manual is not very clear about how to make 'complex' functions like this, with dependencies, working.
The dll is build as x64.
I tried the following things:
- installed the dll in the GAC
- copied the dll into bin64
- also tries with copying the System.Drawing into bin64
- add the the .Net folder to the PATH
None of these work.
Question: how to fix this..?
Below you will find the two SA fucntions and the C# script.
SELECT "DBA"."fn_tsd_net_resizeimage"('d:/fotos/001/abbnana.jpg','d:/temp/t.jpg',100,100)
The error:
Procedure 'fn_tsd_net_resizeimage' terminated with unhandled exception
'Kan bestand of assembly System.Drawing, Version=4.0.0.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a of een van de
afhankelijkheden hiervan niet laden. Deze assembly is gebouwd
SQLCODE=-91, ODBC 3 State="HY000"
In english it is something like
"....could not load assembly ..xxx.. or one of the dependenies. This assembly is build SQLCode...."
The sp_test() is working well.
//C# script:
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
public class Resize
{
public static string Test(string one, string two)
{
return one + two ;
}
public static int ResizeFile(string filein, string fileOut, int width, int height)
{
Image imageIn = Image.FromFile(filein);
Image imageNew = ResizeImage(imageIn, new Size(width, height));
imageNew.Save(fileOut);
return 1;
}
public static Image ResizeImage(Image image, Size size, bool preserveAspectRatio = true, bool mayGrow = false)
{
.
.
return newImage;
}
}
SQL Anywhere functions.
//This one works fine.
ALTER FUNCTION "DBA"."sp_tst"(
in "as_file_in" long varchar,
in "as_file_out" long varchar
)
returns long varchar
external name 'd:\wintreeapps\bin\TSDSAaddons.dll::Resize.Test( string, string) string' language "CLR"
//Problem about dependecy
ALTER FUNCTION "DBA"."fn_tsd_net_resizeimage"(
in "as_file_in" long varchar,
in "as_file_out" long varchar,
in "ai_width" integer,
in "ai_height" integer )
returns integer
external name 'd:\wintreeapps\bin\TSDSAaddons.dll::Resize.ResizeFile( string, string, int, int) int' language "CLR"
asked
01 Apr '16, 07:45
HansTSD
220●13●15●21
accept rate:
20%
Can't comment on the failing loading of the System.Drawing assembly - however, are you sure the return types of your CLR function (Image) and the SQL declaration (int) do fit - and those for the image and size parameters?
The ResizeFile returns a Int. Same as the SA function. The parameters are matching also.
Just a stupid assumption from my side. Have you configured SA to use CLR 4.0? (or do you have .NET 4.0 installed)
Mmm... configure SA to use a specific .NET version? Could be the answer, did I missed something in the manual..? I did not configure anything.
Testing with SA 16.0.0.2043 Windows 10
I don't think you have missed something - cf. that v16 doc page and particularly the comments - IMHO you should be fine with .NET 4.
I changed the .Net framework (in C#) to 3.5. Problem solved.
could you please write the answer, and approve it? What I want to know is what you exactly changed in your code? Or, e.g. have you removed .NET 4.0 and installed 3.5?