473,396 Members | 1,707 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Need to add assembly reference to an ASP.NET page with XML/XSL transform

I have an ASP.NET page that uses a tag:

<asp:Xml id="foo" runat="server" DocumentSource="rss.xml" TransformSource="rss20.xsl" />

This creates a Web page from an XML file that was generated by InfoPath. By default InfoPath inline's their images in base64 encoding. These need to be extracted out to be displayed.

I've got my XSL set up to be able to pull out images and manage them separately. According to Microsoft, they need to be decoded and returned back as an image stream to the src attribute of the img tag.

See: http://www.mcse.ms/archive180-2004-4-605843.html
See: http://blogs.msdn.com/infopath/archi...21/117600.aspx

So I've got some C# code in my XSL that performs this decode operation -- well, that's where I need help. Here's the code:

<msxsl:script language="C#" implements-prefix="cs">
<![CDATA[
Image decode(string s)
{
byte[] image = Convert.FromBase64String( s );
System.IO.MemoryStream memStr = new System.IO.MemoryStream();
memStr.Write( image, 0, image.Length );
System.Drawing.Image img = System.Drawing.Image.FromStream(memStr);
return image;
}
]]>
</msxsl:script>

The problem I'm hitting is that the process is failing on System.Drawing.Image -- it doesn't know what it is. Here's what I get back:
>>>>>>>>>

Server Error in '/' Application.
--------------------------------------------------------------------------------

Script compile errors: file:///c:/inetpub/wwwroot/rss20.xsl(8,1) : error CS0246: The type or namespace name 'Image' could not be found (are you missing a using directive or an assembly reference?)
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Xml.Xsl.XsltException: Script compile errors: file:///c:/inetpub/wwwroot/rss20.xsl(8,1) : error CS0246: The type or namespace name 'Image' could not be found (are you missing a using directive or an assembly reference?)
<<<<<<<<<<<<<<

So my question is how do I add an assembly reference to System.Drawing, and where? This is an ASP.NET page with an XML/XSL transform. I don't have a whole lot of .NET knowledge -- I only JUST discovered I can actually even use C# in XSL (I just tried it out of pure curiosity -- and that gave me some hope!)

Anyone know how to add this assembly reference and where? Thanx!

--
Greg Collins [InfoPath MVP]
Please visit: http://www.InfoPathDev.com

Nov 18 '05 #1
5 8895
Sorry, one modification to the return value of the code, and a slightly different error:

<msxsl:script language="C#" implements-prefix="cs">
<![CDATA[
System.Drawing.Image decode(string s)
{
byte[] image = Convert.FromBase64String( s );
System.IO.MemoryStream memStr = new System.IO.MemoryStream();
memStr.Write( image, 0, image.Length );
System.Drawing.Image img = System.Drawing.Image.FromStream(memStr);
return image;
}
]]>
</msxsl:script>
Error:
Script compile errors: file:///c:/inetpub/wwwroot/rss20.xsl(8,8) : error CS0234: The type or namespace name 'Drawing' does not exist in the class or namespace 'System' (are you missing an assembly reference?)
I've also tried adding to the .aspx page, with no luck, the following:
<%@ import namespace="System.Drawing" %>

I know System.Drawing is there, because if I purposely misspell it to "System.Drawingfoo" then I get an error on this import line.

I've also tried using an import with System.Drawing.Image, with no luck.

--
Greg Collins [InfoPath MVP]
Please visit: http://www.InfoPathDev.com


"Greg Collins [MVP]" <Greg.Collins_AT_InfoPathDev.com> wrote in message news:#X**************@TK2MSFTNGP15.phx.gbl...
I have an ASP.NET page that uses a tag:

<asp:Xml id="foo" runat="server" DocumentSource="rss.xml" TransformSource="rss20.xsl" />

This creates a Web page from an XML file that was generated by InfoPath. By default InfoPath inline's their images in base64 encoding. These need to be extracted out to be displayed.

I've got my XSL set up to be able to pull out images and manage them separately. According to Microsoft, they need to be decoded and returned back as an image stream to the src attribute of the img tag.

See: http://www.mcse.ms/archive180-2004-4-605843.html
See: http://blogs.msdn.com/infopath/archi...21/117600.aspx

So I've got some C# code in my XSL that performs this decode operation -- well, that's where I need help. Here's the code:

<msxsl:script language="C#" implements-prefix="cs">
<![CDATA[
Image decode(string s)
{
byte[] image = Convert.FromBase64String( s );
System.IO.MemoryStream memStr = new System.IO.MemoryStream();
memStr.Write( image, 0, image.Length );
System.Drawing.Image img = System.Drawing.Image.FromStream(memStr);
return image;
}
]]>
</msxsl:script>

The problem I'm hitting is that the process is failing on System.Drawing.Image -- it doesn't know what it is. Here's what I get back:
>>>>>>>>>

Server Error in '/' Application.
--------------------------------------------------------------------------------

Script compile errors: file:///c:/inetpub/wwwroot/rss20.xsl(8,1) : error CS0246: The type or namespace name 'Image' could not be found (are you missing a using directive or an assembly reference?)
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Xml.Xsl.XsltException: Script compile errors: file:///c:/inetpub/wwwroot/rss20.xsl(8,1) : error CS0246: The type or namespace name 'Image' could not be found (are you missing a using directive or an assembly reference?)
<<<<<<<<<<<<<<

So my question is how do I add an assembly reference to System.Drawing, and where? This is an ASP.NET page with an XML/XSL transform. I don't have a whole lot of .NET knowledge -- I only JUST discovered I can actually even use C# in XSL (I just tried it out of pure curiosity -- and that gave me some hope!)

Anyone know how to add this assembly reference and where? Thanx!

--
Greg Collins [InfoPath MVP]
Please visit: http://www.InfoPathDev.com

Nov 18 '05 #2
PL

I had the exact same problem trying to do sql queries inside a msxsl:script block.

I posted a question about that a while ago and got no helpful replies at all.

The only thing I could deduct is that it's actually a documentation error,
that is you cannot use ANY assembly inside a script block, only the
listed default ones.

One way to solve I guess is to skip the inline xmlns:script blocks and
attach an object to the transform instead, there are some articles about
how to do that.

Then you just write your own class and attach it, then call whatever methods
you need from inside the xls.

Let me know if you find another solution, seems this should work accroding to docs.

PL.

"Greg Collins [MVP]" <Greg.Collins_AT_InfoPathDev.com> wrote in message news:Oj**************@TK2MSFTNGP15.phx.gbl...
Sorry, one modification to the return value of the code, and a slightly different error:

[snip]
Nov 18 '05 #3
What were the steps you used to make this work? I'm still fairly new to ASP.NET, C# and the .NET Framework, so specifics, or even a walkthrough, would be helpful.

By the way, another change to the code quoted earlier is that I would be returning "img" and not "image". (Sorry -- I was doing a lot of playing around with the code earlier, and pasted it in to the posting before cleaning it back up, so I missed a few things) :o)

--
Greg Collins [InfoPath MVP]
Please visit: http://www.InfoPathDev.com

"PL" <pb****@yahoo.se> wrote in message news:eF**************@tk2msftngp13.phx.gbl...

I had the exact same problem trying to do sql queries inside a msxsl:script block.

I posted a question about that a while ago and got no helpful replies at all.

The only thing I could deduct is that it's actually a documentation error,
that is you cannot use ANY assembly inside a script block, only the
listed default ones.

One way to solve I guess is to skip the inline xmlns:script blocks and
attach an object to the transform instead, there are some articles about
how to do that.

Then you just write your own class and attach it, then call whatever methods
you need from inside the xls.

Let me know if you find another solution, seems this should work accroding to docs.

PL.

"Greg Collins [MVP]" <Greg.Collins_AT_InfoPathDev.com> wrote in message news:Oj**************@TK2MSFTNGP15.phx.gbl...
Sorry, one modification to the return value of the code, and a slightly different error:

[snip]
Nov 18 '05 #4
PL
> What were the steps you used to make this work? I'm still fairly new to ASP.NET,
C# and the .NET Framework, so specifics, or even a walkthrough, would be helpful.
Actually the samples are pretty few on this subject as well but you use the AddExtensionObject
and AddParam in the XsltArgumentList class.

These articles have some .NET examples in them (look somewhere at the bottom of both):
http://msdn.microsoft.com/msdnmag/issues/02/03/xml/
http://msdn.microsoft.com/library/de...hancingxsl.asp

Here's a sample from the first MS article, in this sample they created a class called Person
with the public method SayHello and then add it to the transform with AddExtensionObject

The XSL:

<xsl:transform version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:obj="urn:person"

<xsl:output method="text"/>
<xsl:template match="/">
name: <xsl:value-of select="obj:get-name()"/>
age: <xsl:value-of select="obj:get-age()"/>
greeting: <xsl:value-of select="obj:SayHello('Michi')"/>
</xsl:template>
</xsl:transform>

The VB.NET code

XslTransform xslt = new XslTransform();
xslt.Load(stylesheet);
XPathDocument doc = new XPathDocument(filename);
XsltArgumentList xslArg = new XsltArgumentList();

// Create a Person object
Person obj = new Person();
obj.name = "Michi";
obj.age = 6;

// Add it to the transform
xslArg.AddExtensionObject("urn:person", obj);
xslt.Transform(doc, xslArg, Console.Out);

Hope this helps.
PL.
Nov 18 '05 #5
Hi Greg,

PL's answer is correct, you'd better use extension objects. I am responsible
to fix this problem in Framework 2.0. If you have Beta1, you may try the
following:

<msxsl:script language="..." implements-prefix="...">
<msxsl:assembly name="myassembly.dll"/>
...
</msxsl:script>

Thanks,
Anton

This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use. © 2004 Microsoft Corporation. All rights
reserved.
Nov 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Mountain Bikn' Guy | last post by:
This code (adapted from the examples in the docs) doesn't make complete sense to me. I have it working, but I'm wondering why I need to declare an assembly reference in 2 places. TIA. Dave ...
3
by: Helene Day | last post by:
I am trying to access the Word Objects from a .NET project. I have some sample from http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odc_vsto2003_ta/html/WordObject.asp and I...
2
by: PL | last post by:
According to the documentation I'm supposed to be able to use any classes in the ..NET framework inside a msxml:script block if I use a fully qualified path. I'm trying to test the XSL sheet...
1
by: Rui Macdonald | last post by:
I trying some asp from angGoGo PhotoControl and when I star it on my computer always gives the following message, Can you please help me? :-( ------------------------------------------- ...
3
by: Richard Lewis Haggard | last post by:
We are having a lot of trouble with problems relating to failures relating to 'The located assembly's manifest definition with name 'xxx' does not match the assembly reference" but none of us here...
0
by: =?Utf-8?B?SmFtZXM=?= | last post by:
I'm stuck with the following error... Does anyone know how to correct the reference? I've not idea why it is referencing 'Copy of...' Server Error in '/Client1' Application....
4
by: =?Utf-8?B?V2FubmFiZQ==?= | last post by:
I developed, and ran successfully, a web application on my development box, but cannot get it to run on the server. The error I am getting is: Compiler Error Message: CS0234: The type or...
0
by: JB | last post by:
I have an ASP project written years ago that I have recently started to try and update. It was written by someone who used to work here before me, and the source code I have is in a major mess. ...
2
by: Febria | last post by:
Dear, all... I have some problem with my application. I used UltraWebGrid component in my web application. Unfortunately, when I tried to run the web, the error page displayed: The located...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.