{"record":{"id":"60fe84831ed5732b","repo":"icsharpcode/ILSpy","slug":"cannot-decompile-this-assembly-to-a-sdk-style-proj","errorCode":null,"errorMessage":"Cannot decompile this assembly to a SDK style project. Use default project format instead.","messagePattern":"Cannot decompile this assembly to a SDK style project\\. Use default project format instead\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"ICSharpCode.Decompiler/CSharp/ProjectDecompiler/ProjectFileWriterSdkStyle.cs","lineNumber":175,"sourceCode":"\t\t\t}\r\n\t\t}\r\n\r\n\t\t/// <summary>\r\n\t\t/// Gets the target framework moniker for the specified module and project.\r\n\t\t/// </summary>\r\n\t\t/// <param name=\"module\">The module for which to get the target framework moniker.</param>\r\n\t\t/// <param name=\"project\">The project information provider.</param>\r\n\t\t/// <returns>The target framework moniker.</returns>\r\n\t\t/// <exception cref=\"NotSupportedException\">Thrown if the target framework moniker cannot be determined.</exception>\r\n\t\tprotected virtual string GetTargetFrameworkMoniker(MetadataFile module, IProjectInfoProvider project)\r\n\t\t{\r\n\t\t\tvar targetFramework = TargetServices.DetectTargetFramework(module);\r\n\t\t\tif (targetFramework.Identifier == \".NETFramework\" && targetFramework.VersionNumber == 200)\r\n\t\t\t\ttargetFramework = TargetServices.DetectTargetFrameworkNET20(module, project.AssemblyResolver, targetFramework);\r\n\r\n\t\t\tif (targetFramework.Moniker == null)\r\n\t\t\t{\r\n\t\t\t\tthrow new NotSupportedException($\"Cannot decompile this assembly to a SDK style project. Use default project format instead.\");\r\n\t\t\t}\r\n\r\n\t\t\treturn targetFramework.Moniker;\r\n\t\t}\r\n\r\n\t\tstatic void WriteOutputType(XmlTextWriter xml, bool isDll, Subsystem moduleSubsystem, ProjectType projectType)\r\n\t\t{\r\n\t\t\tif (!isDll)\r\n\t\t\t{\r\n\t\t\t\tswitch (moduleSubsystem)\r\n\t\t\t\t{\r\n\t\t\t\t\tcase Subsystem.WindowsGui:\r\n\t\t\t\t\t\txml.WriteElementString(\"OutputType\", \"WinExe\");\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tcase Subsystem.WindowsCui:\r\n\t\t\t\t\t\txml.WriteElementString(\"OutputType\", \"Exe\");\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t}\r","sourceCodeStart":157,"sourceCodeEnd":193,"githubUrl":"https://github.com/icsharpcode/ILSpy/blob/60c08fcb74fcc183130f73c861ed35cf944d0bf1/ICSharpCode.Decompiler/CSharp/ProjectDecompiler/ProjectFileWriterSdkStyle.cs#L157-L193","documentation":"NotSupportedException from ProjectFileWriterSdkStyle.GetTargetFrameworkMoniker when TargetServices.DetectTargetFramework(module).Moniker is null. An SDK-style .csproj requires a TargetFramework moniker; if the assembly's target framework cannot be detected (no TargetFrameworkAttribute and the resolver cannot classify the references), no valid moniker exists, so the SDK writer refuses to proceed. The message tells you to use the default (non-SDK) project format instead.","triggerScenarios":"Exporting an assembly to a project with settings.UseSdkStyleProjectFormat = true when the assembly has no determinable target framework, e.g. COM/WinMD interop, an unmapped legacy framework, a native/pinvoke-only assembly, or a resolver that cannot see the framework references.","commonSituations":"Old .NET 2.0/3.5 assemblies without TargetFrameworkAttribute and an incomplete resolver; mixed-mode/native assemblies; assemblies stripped of references.","solutions":["Pre-check with WholeProjectDecompiler.CanUseSdkStyleProjectFormat(module) and fall back to the default writer when it returns false.","Set settings.UseSdkStyleProjectFormat = false to emit the default non-SDK project format, which does not require a moniker.","Provide a working IAssemblyResolver so TargetServices can resolve framework references and derive the moniker."],"exampleFix":"// before\nsettings.UseSdkStyleProjectFormat = true;\nprojectDecompiler.DecompileProject(module, targetDir); // throws if TFM undetectable\n\n// after\nsettings.UseSdkStyleProjectFormat = WholeProjectDecompiler.CanUseSdkStyleProjectFormat(module);\nprojectDecompiler.DecompileProject(module, targetDir);","handlingStrategy":"fallback","validationCode":"if (settings.UseSdkStyleProjectFormat && !WholeProjectDecompiler.CanUseSdkStyleProjectFormat(module))\n    settings.UseSdkStyleProjectFormat = false; // fall back to the default project format","typeGuard":null,"tryCatchPattern":"try {\n    projectDecompiler.DecompileProject(module, targetDirectory);\n} catch (NotSupportedException) {\n    settings.UseSdkStyleProjectFormat = false;\n    projectDecompiler.DecompileProject(module, targetDirectory);\n}","preventionTips":["Pre-check CanUseSdkStyleProjectFormat before export.","Keep the assembly resolver populated so framework detection succeeds."],"tags":["project-export","sdk-style","target-framework","metadata"],"backgroundTag":null,"analyzedSha":"60c08fcb74fcc183130f73c861ed35cf944d0bf1","analyzedAt":"2026-08-13T11:34:51.223Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}