我在这里遇到了一个特别棘手的问题,我想在那里提出更多的反馈(我是我工作的公司中唯一的.NET开发人员,因此没有人可以反弹).
我的任务是更换一个老化的VB6编写的ActiveX组件,该组件由包含VB6用量和我正在替换的组件的VB.NET用法的应用程序使用.
我有所有这些组件的完整源代码,所以我可以看到用例.
为了便于讨论,可以调用组件:
MyVb6.dll
MyApp(使用VB.NET和VB6组件)
在构建过程中,MyApp
他们使用TlbImp工具生成一个互操作库:
Interop.MyVb6.dll
用法
在大多数情况下,使用此方法符合预期,使用如下CreateObject()
方法:
Private Property MyProp() As Object
Get
Try
If m_myProp Is Nothing Then
m_myProp = CreateObject("MyVb6.MyVb6Obj")
m_myProp.Initialize()
End If
Catch : End Try
Return m_myProp
End Get
Run Code Online (Sandbox Code Playgroud)
但是在一个例子中,我发现他们似乎已经改变了如何使用这个interop dll的策略,并且他们有一个静态引用它和一个类型属性,例如:
Private Property MyProp() As MyVb6.MyVb6ObjClass 'Whilst this is strongly typed, it is from the interop dll ...
Get
If m_myProp Is Nothing Then
m_myProp = CreateObject("MyVb6.MyVb6Obj")
m_myProp .Initialize()
End If
Return m_myProp
End Get
Run Code Online (Sandbox Code Playgroud)
重建和重新部署整个应用程序的费用是完全不可能的,所以除了替换之外我别无选择MyVb6.dll
.
我希望在这里找到的是这是否是一个实用的解决方案...... …
我不得不处理从我的控制中的数据源抛出我的应用程序的数据集合.其中一些集合包含空值,我宁愿在它们点击我的代码时过滤掉它,而不是在整个地方散布空检查代码.我想以可重用的通用方式执行此操作并编写此方法来执行此操作:
public static void RemoveNulls<T>(this IList<T> collection) where T : class
{
for (var i = 0; i < collection.Count(); i++)
{
if (collection[i] == null)
collection.RemoveAt(i);
}
}
Run Code Online (Sandbox Code Playgroud)
我知道在具体的List类中有RemoveAll()
一个可以使用的方法,如:
collection.RemoveAll(x => x == null);
Run Code Online (Sandbox Code Playgroud)
但是很多返回类型都是基于接口的(IList/IList ...)而不是具体的类型.
我刚刚开始抛出这个奇怪的异常,我完全不确定如何前进并解决它.
[A]System.Net.Http.Headers.MediaTypeHeaderValue cannot be cast to [B]System.Net.Http.Headers.MediaTypeHeaderValue.
Type A originates from 'System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' in the context 'Default' at location 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Net.Http\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Net.Http.dll'.
Type B originates from 'System.Net.Http, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' in the context 'Default' at location 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Net.Http\v4.0_2.0.0.0__b03f5f7f11d50a3a\System.Net.Http.dll'
在此行的客户端上的WebAPI中发生错误:
var data = responsecontent.ReadAsAsync<List<MyClass>>().Result;
我已经在托管API客户端的网站和API解决方案中检查了每个对此DLL的引用.它们都引用了完全相同的dll:
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Net.Http.dll
我注意到API使用的是较新版本的System.Net.Http.Formatting
dll,但它只是次要的版本增量,并且它被更新为依赖于其他东西,所以我厌恶尝试"降级"并在此过程中创建另一个问题.
API System.Net.Http.Formatting是:
\Microsoft.AspNet.WebApi.Client.4.1.0-alpha-121112\lib\net40\System.Net.Http.Formatting.dll
网站System.Net.Http.Formatting是:
\Microsoft.AspNet.WebApi.Client.4.0.30506.0\lib\net40\System.Net.Http.Formatting.dll
我确实发现,即使在下拉菜单中选择了"仅稳定",NuGet也会将alpha软件包作为依赖项下载.
我刚刚开始研究一种新的控制器动作方法,我有点困惑,为什么我看到405.
我已经在我的API上定义了几个GET属性方法,它们都按预期运行.举个例子,这很好用:
[GET("entries/{page}"), JsonExceptionFilter]
public HttpResponseMessage GetEntries(int page)
Run Code Online (Sandbox Code Playgroud)
然而我的新方法定义如下:
[GET("search/{searchTerm}/{page}"), JsonExceptionFilter]
public HttpResponseMessage Search(string searchTerm, int page)
Run Code Online (Sandbox Code Playgroud)
回来了405
如果我访问API上的routes.axd url,我可以在表格中看到如下条目:
GET, HEAD, OPTIONS users/search/{searchTerm}/{page}
Run Code Online (Sandbox Code Playgroud)
这看起来都很正确.在客户端,我在使用HttpClient的两个请求上使用相同的方法:
var response = httpClient.GetAsync(ApiRootUrl + "users/search/" + searchTerm + "/" + page).Result;
Run Code Online (Sandbox Code Playgroud)
从Fiddler那里得到一个得分也会返回405.
即使查看响应中的RequestMessage看起来也是正确的:
"{Method: GET, RequestUri: 'http://localhost:51258/users/search/jam/0'"
Run Code Online (Sandbox Code Playgroud)
完全被这个困扰了.
我还能尝试什么来解释出现什么问题?
我一直试图获得为我的布尔编辑器编写的默认复选框模板,并且由于MVC Razor如何为单个布尔模型属性呈现多个输入元素,我遇到了一个问题.
我定义了这个模板:
@model Boolean?
<div class="check-box">
@Html.CheckBox("", Model.HasValue && Model.Value)
@Html.LabelForWithoutText(m => m, new object())
</div>
Run Code Online (Sandbox Code Playgroud)
如果我手动写出HTML,如:
<div class="check-box">
<input type="checkbox" title="Create?" value="true" name="check" id="chkCreate">
<label title="Create?" for="chkCreate"></label>
</div>
Run Code Online (Sandbox Code Playgroud)
一切正常.
但是当Razor在模型的布尔属性上呈现我的模板时,html是相当不同的.由于MVC如何呈现其他隐藏的输入以将布尔值发布回动作方法.
剃刀版本看起来像这样:
<div class="check-box">
<input type="checkbox" value="true" name="GloballyShare" id="GloballyShare" data-val-required="The GloballyShare field is required." data-val="true">
<input type="hidden" value="false" name="GloballyShare">
<label title="GloballyShare" for="GloballyShare"></label>
</div>
Run Code Online (Sandbox Code Playgroud)
问题是额外的隐藏input
.我不想改变这种行为,因为这将全局影响默认情况下MVC表单的工作方式,我想不出在CSS中处理这种情况的方法.
所以我想知道如何实现这一目标.您可以在此处查看问题的实际示例:
如果您尝试它然后删除隐藏的输入元素并再次尝试它最顶部的复选框开始工作与底部复选框相同
我刚刚在我的WebAPI项目上更新(从v3.x)到最新版本的AttributeRouting,它刚刚开始产生我以前从未见过的错误.
现在无论何时调用API,我都会收到如下错误:
System.InvalidOperationException: The constraint entry 'inboundHttpMethod' on the route with route template 'my/path' must have a string value or be of a type which implements 'IHttpRouteConstraint'.
at System.Web.Http.Routing.HttpRoute.ProcessConstraint(HttpRequestMessage request, Object constraint, String parameterName, HttpRouteValueDictionary values, HttpRouteDirection routeDirection)
at System.Web.Http.Routing.HttpRoute.ProcessConstraints(HttpRequestMessage request, HttpRouteValueDictionary values, HttpRouteDirection routeDirection)
at System.Web.Http.Routing.HttpRoute.GetRouteData(String virtualPathRoot, HttpRequestMessage request)
at AttributeRouting.Web.Http.Framework.HttpAttributeRoute.GetRouteData(String virtualPathRoot, HttpRequestMessage request)
at System.Web.Http.WebHost.Routing.HttpWebRoute.GetRouteData(HttpContextBase httpContext)
at System.Web.Routing.RouteCollection.GetRouteData(HttpContextBase httpContext)
at System.Web.Routing.UrlRoutingModule.PostResolveRequestCache(HttpContextBase context)
at System.Web.Routing.UrlRoutingModule.OnApplicationPostResolveRequestCache(Object sender, EventArgs e)
at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
Run Code Online (Sandbox Code Playgroud)
几个月来它一直没有问题.
非文档详细信息有任何用法更改.我的配置文件看起来正确.
出了什么问题?我找不到其他人举报此事.
我刚刚向我的存储库提交了一些代码更改,并且突然之间(经过数周的好转)。TC 构建开始失败,因为它无法下载 Microsoft.Bcl.Build.1.0.6 的 NuGet 包。
我最终不得不手动将包目录的内容复制到 TC 构建位置,这完全违背了 NuGet 的观点。
我可以检查什么才能找到这个问题的根本原因?
在用于获取包的解决方案中启用了有关 NuGet 的所有内容。
这让我完全难过.太奇怪了.
我定义了这个Ajax函数:
$.ajax({
type: 'GET',
dataType: 'text/HTML',
url: getLicenseeDetailsUrl,
success: function (response) {
$('#licenseeDetails').html('');
$('#licenseeDetails').html(response);
},
error: function (xhr) {
alert('Failed to get licensee details');
}
});
Run Code Online (Sandbox Code Playgroud)
我让它调用我的控制器,它有一个动作,如:
public ActionResult LoadLicenseeDetails(long licenseeId)
{
var model = new LicenseeDetailsViewModel();
var licencesee = _licensingRepository.LoadById(licenseeId);
var licenses = _licensingRepository.LoadLicenses(licenseeId);
model.Licencee = Mapper.Map<Licensee, LicenceeViewModel>(licencesee);
model.Licences = Mapper.Map<IEnumerable<License>, IEnumerable<LicenceViewModel>>(licenses);
return this.PartialView("_LicenseeDetails", model);
}
Run Code Online (Sandbox Code Playgroud)
这一切似乎都按预期工作,没有任何错误,但它最终会触发Ajax错误函数,而不是成功函数.
看着xhr.responseText
我可以看到来自动作控制器的正确响应信息!
所有状态均为200 OK.我到底是做错了什么?
我已经尝试了检查此逻辑的所有排列方式,但找不到正确的语法。
我有以下 Javascript 代码:
var d = $("#myDatepicker1").datepicker("getDate");
if ($.isEmptyObject(d)) {
$("#dailySummaryDateSelector").datepicker("setDate", new Date());
}
Run Code Online (Sandbox Code Playgroud)
当页面加载并被d
评估时,Firebug 将其显示为Object [ ]
在if
我尝试过的声明中:
if (d == null) {
if (d == {}) {
if (d == Object()) {
if ($.isEmptyObject(d)) {
if (d.isEmptyObject()) {
Run Code Online (Sandbox Code Playgroud)
这些都不起作用。据我所知Object [ ]
是一个空对象,那么我如何实际测试并获取if
要执行的语句内容?
我正在努力弄清楚我们应该如何处理在React中提交表单。初次使用的用户,迄今为止失败。
表格中的数据始终为空,意味着json也为空。
据我从所有示例中了解到的,这应该是可行的。
我的组件是一个简单的注册组件:
import * as React from 'react';
import { PropsType } from './Routes';
import { Form, Col, FormGroup, ControlLabel, FormControl, Button } from 'react-bootstrap';
export default class Register extends React.Component<PropsType, any> {
public constructor(props, context) {
super(props, context);
this.handleSubmit = this.handleSubmit.bind(this);
}
public render() {
return <Form horizontal onSubmit={this.handleSubmit} id={'reg-form'}>
<FormGroup controlId="formHEmail">
<Col componentClass={ControlLabel} sm={2}>
Email
</Col>
<Col sm={10}>
<FormControl type="email" placeholder="Email" />
</Col>
</FormGroup>
<FormGroup controlId="formPassword">
<Col componentClass={ControlLabel} sm={2}>
Password
</Col>
<Col sm={10}>
<FormControl type="password" placeholder="Password" …
Run Code Online (Sandbox Code Playgroud) 在过去的几个小时里,我一直在将我的第一个 powershell 脚本放在一起,但我不断看到一个我似乎无法弄清楚的错误。
我正在使用 Powershell ISE 工具来编写和运行脚本。
为了看看它是否在我的脚本中,我创建了一个超级简单的测试脚本,并且我看到了同样的问题。整个测试脚本为:
Test;
function Test
{
New-Item C:\Users\jgreen\Desktop\jammer\ -type directory
}
Run Code Online (Sandbox Code Playgroud)
当我点击Run Script
按钮时,产生的错误是:
Test : The term 'Test' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct
and try again.
Run Code Online (Sandbox Code Playgroud)
如果我Run Script
再次按下按钮,它就会起作用并完成工作。我根本不明白出了什么问题。我根本不明白。我的脚本有问题吗?
为什么一个可以运行的脚本在 PS ISE 中打开后第一次就崩溃了?
asp.net-mvc ×3
c# ×3
javascript ×3
.net ×2
jquery ×2
nuget ×2
ajax ×1
asp.net ×1
checkbox ×1
collections ×1
com ×1
css3 ×1
msbuild ×1
powershell ×1
razor ×1
reactjs ×1
teamcity ×1
typescript ×1
vb.net ×1
vb6 ×1