The Application of fo-dicom in AspNet WebApi throws an exception: No codec registered for tranfer syntax:, webapifo-dicom

Source: Internet
Author: User

The Application of fo-dicom in AspNet WebApi throws an exception: No codec registered for tranfer syntax:, webapifo-dicom
Background: In a Dicom Web Service, the WADO-RS needs to parse TransferSyntax, and then the DicomFile. ChangeTransferSyntax method in fo-dicom is used. Code similar to: var df = DicomFile. Open (samplesDir + @ "\ User Submitted \ overlays. dcm"); df = df. ChangeTransferSyntax (DicomTransferSyntax. 2000lossless );
Problem: The above code runs normally in the Console (exe) and throws an exception in the WebApi service: No codec registered for tranfer syntax:
Cause: After viewing the fo-dicom source code, we found that DicomCodec was 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 (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 (catiner); foreach (var lazy in container. getExports <IDicomCodec> () {var codec = lazy. value; log. debug ("Codec: {0}", codec. transferSyntax. UID. name); _ codecs [codec. transferSyntax] = codec ;}}
When it is the Console, the above path is the path of the exe, so the MEF mechanism can find Dicom. Native. DLL, and then you can get the Codecs.
When it is AspNet WebApi, the above path is C: \ Windows \ Microsoft. NET \ Framework \ v4.0.30319 \ Temporary ASP. NET Files \ root \ e298f90d \ bf8a423a \ assembly \ dl3 \ 2196513d \ b06fccd3_jwbd001. Each DLL is in an independent path, and Dicom cannot be found in the WebApi dll path. native. DLL, so Codecs cannot be obtained, and thus the exception No codec registered for tranfer syntax is thrown:
Solution: In WebApiConfig. add the following code to the Register Method: var path = Path. getDirectoryName (new Uri (Assembly. getExecutingAssembly (). codeBase ). localPath); Dicom. imaging. codec. dicomTranscoder. loadCodecs (path, "Dicom. native *. dll ");

Copyright Disclaimer: This article is an original article by the blogger. You are welcome to reprint it. Please sign it only.

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.