icsharpcode/ILSpy · error · NotSupportedException
Cannot decompile this assembly to a SDK style project. Use d
Error message
Cannot decompile this assembly to a SDK style project. Use default project format instead.
What it means
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.
Source
Thrown at ICSharpCode.Decompiler/CSharp/ProjectDecompiler/ProjectFileWriterSdkStyle.cs:175
}
}
/// <summary>
/// Gets the target framework moniker for the specified module and project.
/// </summary>
/// <param name="module">The module for which to get the target framework moniker.</param>
/// <param name="project">The project information provider.</param>
/// <returns>The target framework moniker.</returns>
/// <exception cref="NotSupportedException">Thrown if the target framework moniker cannot be determined.</exception>
protected virtual string GetTargetFrameworkMoniker(MetadataFile module, IProjectInfoProvider project)
{
var targetFramework = TargetServices.DetectTargetFramework(module);
if (targetFramework.Identifier == ".NETFramework" && targetFramework.VersionNumber == 200)
targetFramework = TargetServices.DetectTargetFrameworkNET20(module, project.AssemblyResolver, targetFramework);
if (targetFramework.Moniker == null)
{
throw new NotSupportedException($"Cannot decompile this assembly to a SDK style project. Use default project format instead.");
}
return targetFramework.Moniker;
}
static void WriteOutputType(XmlTextWriter xml, bool isDll, Subsystem moduleSubsystem, ProjectType projectType)
{
if (!isDll)
{
switch (moduleSubsystem)
{
case Subsystem.WindowsGui:
xml.WriteElementString("OutputType", "WinExe");
break;
case Subsystem.WindowsCui:
xml.WriteElementString("OutputType", "Exe");
break;
}
View on GitHub (pinned to 60c08fcb74)
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.
Example fix
// before settings.UseSdkStyleProjectFormat = true; projectDecompiler.DecompileProject(module, targetDir); // throws if TFM undetectable // after settings.UseSdkStyleProjectFormat = WholeProjectDecompiler.CanUseSdkStyleProjectFormat(module); projectDecompiler.DecompileProject(module, targetDir);
Defensive patterns
Strategy: fallback
Validate before calling
if (settings.UseSdkStyleProjectFormat && !WholeProjectDecompiler.CanUseSdkStyleProjectFormat(module))
settings.UseSdkStyleProjectFormat = false; // fall back to the default project format Try / catch
try {
projectDecompiler.DecompileProject(module, targetDirectory);
} catch (NotSupportedException) {
settings.UseSdkStyleProjectFormat = false;
projectDecompiler.DecompileProject(module, targetDirectory);
} Prevention
- Pre-check CanUseSdkStyleProjectFormat before export.
- Keep the assembly resolver populated so framework detection succeeds.
When it happens
Trigger: 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.
Common situations: Old .NET 2.0/3.5 assemblies without TargetFrameworkAttribute and an incomplete resolver; mixed-mode/native assemblies; assemblies stripped of references.
Related errors
- types contains null element
- Could not find type definition {fullTypeName} in type system
- definitions contains null element
- Error decompiling @{MetadataTokens.GetToken(entity.MetadataT
- Unexpected member type
AI-assisted analysis of icsharpcode/ILSpy@60c08fcb74 (2026-08-13).
Data as JSON: /api/errors/60fe84831ed5732b.
Report an issue: GitHub.