Applying fo-dicom in the AspNet WebApi throws an exception: No codec registered for Tranfer syntax:

Source: Internet
Author: User

Background:in making a dicom Web Service, where Wado-rs needs to parse Transfersyntax, then it uses the Dicomfile.changetransfersyntax method in fo-dicom. code similar to:var df = dicomfile.open (SamplesDir + @ "\user submitted\overlays.dcm");df = df. Changetransfersyntax (dicomtransfersyntax.jpeg2000lossless);
Problem:The above code is working properly in the console (EXE) and throws an exception in the WEBAPI service: No codec registered for Tranfer syntax:
Reason: After viewing fo-dicom source code, it is found that Dicomcodec is initialized with MEF in the static construction method of Dicomtranscoder.        Code similar to: Static Dicomtranscoder () {loadcodecs (null, "Dicom.native*.dll"); }
public static void Loadcodecs (string path = null, string search = null) {if (path = = null) { Path = Path.getdirectoryname (The new Uri (assembly.getexecutingassembly (). CodeBase).            LocalPath); }
var log = LogManager.Default.GetLogger ("Dicom.Imaging.Codec");
var Catalog = (search = = null)? New Directorycatalog (PATH) : New Directorycatalog (path, search);var container = new Compositioncontainer (catalog);foreach (var lazy in container. Getexports<idicomcodec> ()) {var codec = lazy.                Value; Log. Debug ("Codec: {0}", Codec.                TransferSyntax.UID.Name); _codecs[codec.            Transfersyntax] = codec; }        }
As the console, the above path is the path of the EXE, so the MEF mechanism can find Dicom.Native.DLL, and then you can take the codecs.
when WEBAPI for ASPNET, the above path is C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP. files\root\e298f90d\ bf8a423a\assembly\dl3\2196513d\b06fccd3_417bd001, each DLL is under a separate path, causing the path of the DLL in WEBAPI to not find Dicom.Native.DLL, so codecs is not taken, This throws an exception no codec registered for Tranfer syntax:
Workaround:Add the following code to the Webapiconfig.register method:var path = Path.getdirectoryname (The new Uri (assembly.getexecutingassembly (). CodeBase). LocalPath);Dicom.Imaging.Codec.DicomTranscoder.LoadCodecs (Path, "Dicom.native*.dll");

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Applying fo-dicom in the AspNet WebApi throws an exception: No codec registered for Tranfer syntax:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.