【发布时间】:2020-08-15 02:19:48
【问题描述】:
问题:我在 @Scripts.Render("~bundles/jquery") 上收到 NullReferenceException。
我昨晚部署并进行了测试,一切都很好。今天早上醒来,决定检查网站并注意到它。我也没有碰过任何奇怪的东西。
这不会在本地发生!!!!!!
代码片段
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/bootstrap")
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
BundleConfig
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js"));
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery.validate*"));
// Use the development version of Modernizr to develop with and learn from. Then, when you're
// ready for production, use the build tool at https://modernizr.com to pick only the tests you need.
bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
"~/Scripts/modernizr-*"));
bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
"~/Scripts/bootstrap.js"));
bundles.Add(new StyleBundle("~/Content/css").Include(
"~/Content/bootstrap.css",
"~/Content/site.css"));
}
我尝试过的事情:
- 重建 + 完全部署
- 重置/回收
- 使用硬编码版本重命名捆绑包 有什么建议吗?这是与 Minify 相关的吗?
编辑#1
编辑#2 我可以确认在访问 https://example.com/Scripts/jquery-3.4.1.min.js 时看到正在加载 JS 文件
编辑#3 我尝试替换所有捆绑引用以从 Scripts & Content 文件夹中提取,现在我遇到了一些奇怪的 jQuery 错误...注意,我更喜欢使用捆绑。
<link href="~/Content/Site.css" rel="stylesheet" />
<link href="~/Content/bootstrap-theme.min.css" rel="stylesheet" />
<link href="~/Content/bootstrap.min.css" rel="stylesheet" />
<script src="~/Scripts/modernizr-2.8.3.js"></script>
<script src="~/Scripts/jquery-3.4.1.min.js"></script>
<script src="~/Scripts/bootstrap.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
编辑#4 我有一个使用最新 CDN 的 Bootstrap 解决方案,但我更喜欢使用标准捆绑。
【问题讨论】:
-
您可以尝试在本地调试您的捆绑包,就像在生产环境中一样,将这一行放在您的 RegisterBundles 中:BundleTable.EnableOptimizations = true;我怀疑你的本地正在工作,因为它实际上并没有在调试时捆绑
-
真正的问题是,为什么会突然出现捆绑问题?它在生产/发布中按预期工作。是否有任何与捆绑相关的 IIS 配置设置可能导致它?
-
我刚刚启用了优化,现在它发生在本地。
System.NullReferenceException: 'Object reference not set to an instance of an object.' Microsoft.Ajax.Utilities.FunctionObject.SafeIsReferenced(Syste[..] -
错误堆栈跟踪是否显示任何以任何布局视图或资源文件结尾的行号?
-
它在 OP 中基本上是一样的。 @Scripts.Render("~/bundles/jquery")
标签: javascript asp.net asp.net-mvc