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"

asked 01 Apr '16, 07:45

HansTSD's gravatar image

HansTSD
1304813
accept rate: 50%

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?

(01 Apr '16, 08:34) Volker Barth
Replies hidden

The ResizeFile returns a Int. Same as the SA function. The parameters are matching also.

(01 Apr '16, 08:40) HansTSD

Just a stupid assumption from my side. Have you configured SA to use CLR 4.0? (or do you have .NET 4.0 installed)

(01 Apr '16, 08:54) Vlad

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

(01 Apr '16, 09:17) HansTSD
Replies hidden

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.

(01 Apr '16, 09:34) Volker Barth
1

I changed the .Net framework (in C#) to 3.5. Problem solved.

(01 Apr '16, 10:29) HansTSD
Replies hidden
1

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?

(02 Apr '16, 16:01) Vlad
showing 4 of 7 show all flat view

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.

permanent link

answered 04 Apr '16, 02:34

HansTSD's gravatar image

HansTSD
1304813
accept rate: 50%

edited 04 Apr '16, 04:48

Volker%20Barth's gravatar image

Volker Barth
29.6k293444650

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×16

question asked: 01 Apr '16, 07:45

question was seen: 805 times

last updated: 04 Apr '16, 04:48