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: