cancel
Showing results for 
Search instead for 
Did you mean: 

CLR with depencies, does not work

hansg
Explorer
0 Kudos
3,152

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:

  1. installed the dll in the GAC
  2. copied the dll into bin64
  3. also tries with copying the System.Drawing into bin64
  4. 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"

Accepted Solutions (1)

Accepted Solutions (1)

hansg
Explorer
0 Kudos

I saw in the installed software from Windows 10 that the .Net framework 3.5 and 4.5/6 were installed, not a 4.0. Therefore I changed, the "Target framework" from v4.0 to v3.5.

That solved the problem.

Answers (0)