F# Asp.Net CodeDom ProviderOptions 问题

发布于 2024-08-11 03:05:56 字数 2080 浏览 6 评论 0原文

我正在 IIS 7 上使用 F# 创建 ASP.NET MVC 应用程序。

当我尝试从浏览器运行它时,我遇到了包含以下内容的 YSOD:

[ArgumentNullException:值不能 为空。参数名称:字典]
System.Collections.Generic.Dictionary2..ctor(IDictionary2 字典,IEqualityComparer`1 比较器)+12700827
System.Web.Compilation.CompilationUtil.CreateCodeDomProviderWithPropertyOptions(类型 codeDomProviderType) +84
System.Web.Compilation.CompilationUtil.CreateCodeDomProviderNonPublic(类型 codeDomProviderType) +16
System.Web.Compilation.AssemblyBuilder..ctor(CompilationSection compConfig、ICollection 引用的程序集,编译器类型 编译器类型,字符串 输出程序集名称)+469
System.Web.Compilation.CompilerType.CreateAssemblyBuilder(CompilationSection compConfig、ICollection 引用的程序集、字符串 生成的文件目录,字符串 输出程序集名称)+127
System.Web.Compilation.BuildProvidersCompiler.ProcessBuildProviders() +675 System.Web.Compilation.BuildProvidersCompiler.PerformBuild() +46 System.Web.Compilation.ApplicationBuildProvider.GetGlobalAsaxBuildResult(布尔值 isPrecompiledApp) +11321455
System.Web.Compilation.BuildManager.CompileGlobalAsax() +50 System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +872

我使用 Reflector 查找了该方法,看看它是否可以为我提供更多上下文,发现它在第一行失败。

private static CodeDomProvider CreateCodeDomProviderWithPropertyOptions(Type codeDomProviderType)
{
IDictionary<string, string> providerOptions = new Dictionary<string, string>(GetProviderOptions(codeDomProviderType));
//Snip
}

这让我相信我在 Web.config 中为 F# CodeDom 指定的 propertyOptions是不正确的。但是,如果我删除它们,我会收到相同的错误。

<system.codedom>
 <compilers>
  <compiler language="F#;f#;fs;fsharp" extension=".fs" warningLevel="4" 
            type="Microsoft.FSharp.Compiler.CodeDom.FSharpAspNetCodeProvider, 
                  FSharp.Compiler.CodeDom">
    <providerOption name="CompilerVersion" value="v4.0"/>
    <providerOption name="WarnAsError" value="false"/>
  </compiler>
 </compilers>
</system.codedom>

关于纠正这个错误有什么想法吗?

I'm creating an ASP.NET MVC application using F# on IIS 7.

When I attempt to run it from the browser, I'm met with a YSOD containing the following:

[ArgumentNullException: Value cannot
be null. Parameter name: dictionary]
System.Collections.Generic.Dictionary2..ctor(IDictionary2
dictionary, IEqualityComparer`1
comparer) +12700827
System.Web.Compilation.CompilationUtil.CreateCodeDomProviderWithPropertyOptions(Type
codeDomProviderType) +84
System.Web.Compilation.CompilationUtil.CreateCodeDomProviderNonPublic(Type
codeDomProviderType) +16
System.Web.Compilation.AssemblyBuilder..ctor(CompilationSection
compConfig, ICollection
referencedAssemblies, CompilerType
compilerType, String
outputAssemblyName) +469
System.Web.Compilation.CompilerType.CreateAssemblyBuilder(CompilationSection
compConfig, ICollection
referencedAssemblies, String
generatedFilesDir, String
outputAssemblyName) +127
System.Web.Compilation.BuildProvidersCompiler.ProcessBuildProviders()
+675 System.Web.Compilation.BuildProvidersCompiler.PerformBuild()
+46 System.Web.Compilation.ApplicationBuildProvider.GetGlobalAsaxBuildResult(Boolean
isPrecompiledApp) +11321455
System.Web.Compilation.BuildManager.CompileGlobalAsax()
+50 System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled()
+872

I looked up the method using Reflector to see if it could give me any more context and found that it was failing on the first line

private static CodeDomProvider CreateCodeDomProviderWithPropertyOptions(Type codeDomProviderType)
{
IDictionary<string, string> providerOptions = new Dictionary<string, string>(GetProviderOptions(codeDomProviderType));
//Snip
}

It leads me to believe that the propertyOptions I've specified in my Web.config for the F# CodeDom are incorrect. However, if I remove them I receive the same error.

<system.codedom>
 <compilers>
  <compiler language="F#;f#;fs;fsharp" extension=".fs" warningLevel="4" 
            type="Microsoft.FSharp.Compiler.CodeDom.FSharpAspNetCodeProvider, 
                  FSharp.Compiler.CodeDom">
    <providerOption name="CompilerVersion" value="v4.0"/>
    <providerOption name="WarnAsError" value="false"/>
  </compiler>
 </compilers>
</system.codedom>

Any ideas on correcting this error?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

滿滿的愛 2024-08-18 03:05:56

这是 VS2010 Beta2 中 ASP.NET 的一个错误(现已修复,因此将在下一个版本中起作用)。它会影响任何第 3 方 CodeDOM 提供商,并且我不认为有任何解决方法。

It’s a bug in ASP.NET in VS2010 Beta2 (it has since been fixed, so will work in next release). It affects any 3rd party CodeDOM provider, and I don’t believe there is any workaround.

-黛色若梦 2024-08-18 03:05:56

我找到了问题的原因。

Microsoft.FSharp.Compiler.CodeDom.FSharpAspNetCodeProvider.FileExtension 被硬编码为“fs”。

System.CodeDom.Compiler.CodeDomCompilationConfiguration..ctor() 内部,为每种允许的语言创建了 CompilerInfo。在创建此文件时找不到 FSharp 的 CompilerInfo。

internal CodeDomCompilationConfiguration()
{
this._compilerLanguages = new Hashtable(StringComparer.OrdinalIgnoreCase);
this._compilerExtensions = new Hashtable(StringComparer.OrdinalIgnoreCase);
this._allCompilerInfo = new ArrayList();
CompilerParameters compilerParams = new CompilerParameters();
compilerParams.WarningLevel = 4;
string codeDomProviderTypeName = "Microsoft.CSharp.CSharpCodeProvider, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
CompilerInfo compilerInfo = new CompilerInfo(compilerParams, codeDomProviderTypeName);
compilerInfo._compilerLanguages = new string[] { "c#", "cs", "csharp" };
compilerInfo._compilerExtensions = new string[] { ".cs", "cs" };
compilerInfo._providerOptions = new Dictionary<string, string>();
compilerInfo._providerOptions["CompilerVersion"] = "v4.0";
this.AddCompilerInfo(compilerInfo);
compilerParams = new CompilerParameters();
compilerParams.WarningLevel = 4;
codeDomProviderTypeName = "Microsoft.VisualBasic.VBCodeProvider, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
compilerInfo = new CompilerInfo(compilerParams, codeDomProviderTypeName);
compilerInfo._compilerLanguages = new string[] { "vb", "vbs", "visualbasic", "vbscript" };
compilerInfo._compilerExtensions = new string[] { ".vb", "vb" };
compilerInfo._providerOptions = new Dictionary<string, string>();
compilerInfo._providerOptions["CompilerVersion"] = "v4.0";
this.AddCompilerInfo(compilerInfo);
//Snip
}

FileExtension 与 System.CodeDom.Compiler.CodeDomProvider.GetCompilerInfoForExtensionNoThrow 中的 _compilerExtensions 进行比较,后者(在“fs”的情况下)向 System.CodeDom 返回 null。 Compiler.CodeDomProvider.IsDefinedExtension 然后将向 System.Web.Compilation.CompilationUtil.GetProviderOptions 返回 false,后者返回导致 ArgumentNullException 的 null。

感谢您为我指明了正确的方向,@Brian

I found the cause to the problem.

The Microsoft.FSharp.Compiler.CodeDom.FSharpAspNetCodeProvider.FileExtension is hardcoded to "fs".

Inside of System.CodeDom.Compiler.CodeDomCompilationConfiguration..ctor() CompilerInfos are created for each of the allowed languages. A CompilerInfo for FSharp is not found within the creation of this.

internal CodeDomCompilationConfiguration()
{
this._compilerLanguages = new Hashtable(StringComparer.OrdinalIgnoreCase);
this._compilerExtensions = new Hashtable(StringComparer.OrdinalIgnoreCase);
this._allCompilerInfo = new ArrayList();
CompilerParameters compilerParams = new CompilerParameters();
compilerParams.WarningLevel = 4;
string codeDomProviderTypeName = "Microsoft.CSharp.CSharpCodeProvider, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
CompilerInfo compilerInfo = new CompilerInfo(compilerParams, codeDomProviderTypeName);
compilerInfo._compilerLanguages = new string[] { "c#", "cs", "csharp" };
compilerInfo._compilerExtensions = new string[] { ".cs", "cs" };
compilerInfo._providerOptions = new Dictionary<string, string>();
compilerInfo._providerOptions["CompilerVersion"] = "v4.0";
this.AddCompilerInfo(compilerInfo);
compilerParams = new CompilerParameters();
compilerParams.WarningLevel = 4;
codeDomProviderTypeName = "Microsoft.VisualBasic.VBCodeProvider, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
compilerInfo = new CompilerInfo(compilerParams, codeDomProviderTypeName);
compilerInfo._compilerLanguages = new string[] { "vb", "vbs", "visualbasic", "vbscript" };
compilerInfo._compilerExtensions = new string[] { ".vb", "vb" };
compilerInfo._providerOptions = new Dictionary<string, string>();
compilerInfo._providerOptions["CompilerVersion"] = "v4.0";
this.AddCompilerInfo(compilerInfo);
//Snip
}

The FileExtension is compared against _compilerExtensions in System.CodeDom.Compiler.CodeDomProvider.GetCompilerInfoForExtensionNoThrow which (in the case of "fs") returns null to System.CodeDom.Compiler.CodeDomProvider.IsDefinedExtension which will then return false to System.Web.Compilation.CompilationUtil.GetProviderOptions that returns the null that was causing the ArgumentNullException.

Thanks for pointing me in the right direction, @Brian

昇り龍 2024-08-18 03:05:56

也许 Brian 指出的错误可以通过在 web.config 中指定更多信息来解决:

type="Microsoft.FSharp.Compiler.CodeDom.FSharpAspNetCodeProvider, 
      FSharp.Compiler.CodeDom,
      Version=1.9.7.8, 
      Culture=neutral, 
      PublicKeyToken=a19089b1c74d0809"

Perhaps the bug Brian noted can be worked around by specifying some more info in web.config:

type="Microsoft.FSharp.Compiler.CodeDom.FSharpAspNetCodeProvider, 
      FSharp.Compiler.CodeDom,
      Version=1.9.7.8, 
      Culture=neutral, 
      PublicKeyToken=a19089b1c74d0809"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文