![]() |
|
can you use Ab2d.ReaderSvg library from a service ? - Printable Version +- AB4D Forum (https://forum.ab4d.com) +-- Forum: Products Forums (https://forum.ab4d.com/forumdisplay.php?fid=4) +--- Forum: ViewerSvg and Ab2d.ReaderSvg (https://forum.ab4d.com/forumdisplay.php?fid=6) +--- Thread: can you use Ab2d.ReaderSvg library from a service ? (/showthread.php?tid=46) |
can you use Ab2d.ReaderSvg library from a service ? - grendo - 07-04-2010 Hi, I want to use ReaderSvg to convert a svg file to xaml on the fly in a webservice something like the code below. byte[] byteArray = Encoding.ASCII.GetBytes(svg); using (MemoryStream stream = new MemoryStream(byteArray)) { Ab2d.ReaderSvg svgReader = new Ab2d.ReaderSvg(); svgReader.Read(stream); SilverlightXamlWriterSettings settings = new SilverlightXamlWriterSettings(SilverlightXamlWriterSettings.SilverlightVersionType.Silverlight_4); string xaml = svgReader.GetXaml(settings); return xaml; } As it pops up the evaluation screen on the webs server I get The calling thread must be STA, because many UI components require this. Is there a way to use this library without UI ? RE: can you use Ab2d.ReaderSvg library from a service ? - abenedik - 07-06-2010 The problem is not UI related but related to the fact that WPF only works on STA thread apartment. A user had the same problems before and this is what he did to solve the problem: You have to create a STA thread on the server and run it in. The exception we got when doing this is specific to framework 3.5 SP1 and have been solved in a hotfix which is available here: https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=361469 Below is a small web sample of doing the STA thread. It should be noted that using this sample you will probably get memory leaks because Microsoft does not support using WPF object server-side. We are doing some more WPF stuff server-side like scaling and converting bitmap images so we have created classes to load WPF in a separate AppDomain which then can be unloaded to avoid the memory leak issues. This is not included in the sample. Here is the sample. To use it just create a new web application in visual studio (using framework 3.5), add references to PresentationCore, PresentationFramework, WindowsBase, Ab2d.ReaderSvg and put this in the code-behind of the default.aspx page: Code: protected void Page_Load(object sender, EventArgs e) |