标签: invalidoperationexception

asp.net-mvc3 EditorFor模板名称问题

关于来自MVC3的editorFor helper我有一个奇怪的问题.事情是这样的:我正在尝试显示一个checkboxList,如果我不调用明确的模板名称,它就可以工作.但是,如果我尝试使用模板名称,它会抛出一个异常,说我正在尝试传递一个通用列表,当我应该简单地传递我的viewModel.我将展示一些代码以使其更易理解:

视图模型

public class ChkViewModel
{
  public string ContractName {get;set;}
  public string Contract {get;set;}
  public bool Checked {get;set;}
}
Run Code Online (Sandbox Code Playgroud)

EditorFor Template(称为ContractTemplate)

@model Models.ChkViewModel
<p>
    @Html.HiddenFor(x => x.Contract )
    @Html.LabelFor(x => x.ContractName , Model.ContractName )
    @Html.CheckBoxFor(x => x.Checked, new { @class = "chkContract" })
&nbsp;       
</p>  
Run Code Online (Sandbox Code Playgroud)

摘自我的观点

<div id="contractContainer">
  @Html.EditorFor(item=>item.ContractList)
</div>
Run Code Online (Sandbox Code Playgroud)

这很好用.但它试图这样做:

<div id="contractContainer">
  @Html.EditorFor(item=>item.ContractList, "ContractTemplate")
</div>
Run Code Online (Sandbox Code Playgroud)

它抛出了InvalidOperationException我必须传递一个简单的ChkViewModel而不是GenericList ChkViewModel的说法.

我只是问这个,因为我试图创建另一个复选框列表,我无法使它工作(甚至不显示复选框),当我试图设置模板名称,这样我至少可以看到复选框,它抛出了那个错误.

asp.net-mvc invalidoperationexception editorfor

7
推荐指数
1
解决办法
4219
查看次数

在MVC Action中启动和忘记异步任务

我有一个标准的,非异步的动作,如:

[HttpPost]
public JsonResult StartGeneratePdf(int id)
{
    PdfGenerator.Current.GenerateAsync(id);
    return Json(null);
}
Run Code Online (Sandbox Code Playgroud)

这个想法是我知道这个PDF生成可能需要很长时间,所以我只是启动任务并返回,而不是关心异步操作的结果.

在默认的ASP.Net MVC 4应用程序中,这给了我这个很好的例外:

System.InvalidOperationException:此时无法启动异步操作.异步操作只能在异步处理程序或模块中启动,或者在页面生命周期中的某些事件中启动.如果在执行页面时发生此异常,请确保将页面标记为<%@ Page Async ="true"%>.

哪种与我的场景无关.调查它我可以将标志设置为false以防止此异常:

<appSettings>
    <!-- Allows throwaway async operations from MVC Controller actions -->
    <add key="aspnet:AllowAsyncDuringSyncStages" value="true" />
</appSettings>
Run Code Online (Sandbox Code Playgroud)

/sf/answers/1066168141/
http://msdn.microsoft.com/en-us/library/hh975440.aspx

但问题是,通过启动这个异步操作并从同步MVC控制器动作中忘记它有什么危害吗?我能找到的一切都建议让控制器异步,但这不是我想要的 - 没有意义,因为它应该总是立即返回.

asp.net asynchronous invalidoperationexception synchronous controller-action

7
推荐指数
1
解决办法
5025
查看次数

.NET Core 2.x Identity int 外键不能以 int 主键为目标

我有一个运行 .net core 2.x 的 Web 应用程序(最终刚刚从 .net core 1.x 升级),并且我已经将大部分内容从 .net core 1.x 移植到 2.x。然而,我的身份实现遇到了砖墙。它在 .net core 1.x 上运行良好,但现在它拒绝了。

该实现在 Entity Framework Core 上运行,并首先构建数据库(在预先存在的数据库中实现)。

我的问题是,当我现在尝试使用 .net core 2.x 登录时,我收到一条错误消息,指出:

InvalidOperationException:从 'AspNetUserRole.AspNetRole' 到具有外键属性 {'RoleId' : int} 的 'AspNetUserRole.AspNetRole' 的关系无法定位主键 {'Id' : int},因为它不兼容。为此关系配置一个主键或一组兼容的外键属性。

对我来说,这完全没有意义。int外键如何与int主键不兼容?

上下文和类的实际实现如下(这是一个非常简单的实现):

public partial class AspNetUser : IdentityUser<int>
{ }
public partial class AspNetRole : IdentityRole<int>
{ }
public partial class AspNetRoleClaim : IdentityRoleClaim<int>
{ }
public partial class AspNetUserClaim : IdentityUserClaim<int>
{ } …
Run Code Online (Sandbox Code Playgroud)

c# invalidoperationexception entity-framework-core asp.net-core asp.net-core-identity

7
推荐指数
1
解决办法
1万
查看次数

接受List <CustomObject>的ASP.NET Web方法失败,"Web服务方法名称无效".

我想创建一个接受自定义对象列表的Web方法(通过jQuery/JSON传入).

当我在本地运行网站时,一切似乎都有效.jQuery和ASP.NET,每个人都很高兴.但当我把它放在我们的一台服务器上时,它会爆炸.在ajax请求之后,jQuery获得500错误,响应为:

System.InvalidOperationException:EditCustomObjects Web服务方法名称无效.

这是Web服务方法:

[WebMethod]
public void EditCustomObjects(int ID, List<CustomObject> CustomObjectList)
{
  // Code here
}
Run Code Online (Sandbox Code Playgroud)

我的jQuery代码(我觉得不重要,因为错误似乎发生在Web服务级别):

var data = JSON.stringify({
  ID: id,
  CustomObjectList: customObjectList
});

$.ajax({
  type: "POST",
  url: "/manageobjects.asmx/EditCustomObjects",
  data: data,
  contentType: "application/json; charset=utf-8",
  async: false,
  dataType: "json",
  success: function(xml, ajaxStatus) {
    // stuff here
  }
});
Run Code Online (Sandbox Code Playgroud)

customObjectList初始化如下:

var customObjectList = [];
Run Code Online (Sandbox Code Playgroud)

我像这样添加项目(通过循环):

var itemObject = { 
  ObjectTitle = objectTitle,
  ObjectDescription = objectDescription,
  ObjectValue = objectValue
}

customObjectList.push(itemObject);
Run Code Online (Sandbox Code Playgroud)

那么,我在这里做错了吗?有没有更好的方法将数据数组从jQuery传递到ASP.NET Web服务方法?有没有办法解决"Web服务方法名称无效".错误?

仅供参考,我在Windows Server 2003机器上运行.NET 2.0,我从这个站点获得了上述代码:http://elegantcode.com/2009/02/21/javascript-arrays-via-jquery-ajax …

asp.net jquery web-services asmx invalidoperationexception

6
推荐指数
1
解决办法
1万
查看次数

WPF DataGrid ComboBox导致InvalidOperationException

当我尝试编辑组合框列的值时,我从我的数据网格获得InvalidOperationException(在AddNew或EditItem事务期间不允许"DeferRefresh").我显示的项目都引用了同一列表中的另一个项目,所以这就是我使用组合框的内容.它与datagrid绑定到同一个集合.我正在处理的应用程序是针对.NET 3.5,但是我已经在.NET 4中组建了一个完全相同的示例,因为数据网格是内置的.以下是datagrid中项目的代码:

public class TestItem : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;
    private void RaisePropertyChanged(string propertyName)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }

    private int m_ID;
    private string m_Name;
    private int m_OppositeID;

    public int ID
    {
        get { return m_ID; }
        set
        {
            m_ID = value;
            RaisePropertyChanged("ID");
        }
    }
    public string Name
    {
        get { return m_Name; }
        set
        {
            m_Name = value;
            RaisePropertyChanged("Name");
        }
    }
    public int OppositeID
    {
        get { return m_OppositeID; } …
Run Code Online (Sandbox Code Playgroud)

wpf datagrid combobox invalidoperationexception

6
推荐指数
1
解决办法
3062
查看次数

VB.net ApplicationFramework加上SplashScreen:InvalidOperationException

我最近更改了我的应用程序,使用自定义SplashScreen(它只是一个带有Timer的表单,主窗体并自行关闭)到应用程序框架.

这是我做的:

  • 创建了一个新的SplashScreenForm,显示了应用程序版本等.
  • 选择该表格在:我的项目 - >应用程序 - > SplashScreen
  • 将长时间运行的初始化代码从主窗体的构造函数移动到ApplicationEvents启动事件

这完全符合我的要求.SplashScreen首先显示,而不是启动事件触发并且它是否正常工作.SplashScreen关闭,显示实际的主窗体.

到现在为止还挺好.但我们的客户有时会在启动期间遇到这个令人讨厌的异常:

System.InvalidOperationException: Invoke oder BeginInvoke kann für ein Steuerelement erst aufgerufen werden, wenn das Fensterhandle erstellt wurde.
   bei System.Windows.Forms.Control.WaitForWaitHandle(WaitHandle waitHandle)
   bei System.Windows.Forms.Control.MarshaledInvoke(Control caller, Delegate method, Object[] args, Boolean synchronous)
   bei System.Windows.Forms.Control.Invoke(Delegate method, Object[] args)
   bei System.Windows.Forms.Control.Invoke(Delegate method)
   bei Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.HideSplashScreen()
   bei Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.MainFormLoadingDone(Object sender, EventArgs e)
   bei System.EventHandler.Invoke(Object sender, EventArgs e)
   bei System.Windows.Forms.Form.OnLoad(EventArgs e)
   bei System.Windows.Forms.Form.OnCreateControl()
   bei System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   bei System.Windows.Forms.Control.CreateControl()
   bei System.Windows.Forms.Control.WmShowWindow(Message& m)
   bei System.Windows.Forms.Control.WndProc(Message& m)
   bei System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   bei …
Run Code Online (Sandbox Code Playgroud)

vb.net invoke invalidoperationexception winforms

6
推荐指数
1
解决办法
3906
查看次数

如何逃避对setCurrentCellAddressCore的重入调用?

我有一个从cell_endedit调用的函数.它在dataGridView中移动dataGridViewRow:

private void moveRowTo(DataGridView table, int oldIndex, int newIndex)
{
    if (newIndex < oldIndex)
    {
        oldIndex += 1;
    }
    else if (newIndex == oldIndex)
    {
        return;
    }
    table.Rows.Insert(newIndex, 1);
    DataGridViewRow row = table.Rows[newIndex];
    DataGridViewCell cell0 = table.Rows[oldIndex].Cells[0];
    DataGridViewCell cell1 = table.Rows[oldIndex].Cells[1];
    row.Cells[0].Value = cell0.Value;
    row.Cells[1].Value = cell1.Value;
    table.Rows[oldIndex].Visible = false;
    table.Rows.RemoveAt(oldIndex);
    table.Rows[oldIndex].Selected = false;
    table.Rows[newIndex].Selected = true;
}
Run Code Online (Sandbox Code Playgroud)

在row table.Rows.Insert(newIndex,1)我收到以下错误:

System.Windows.Forms.dll中类型为"System.InvalidOperationException"的未处理异常

附加数据:操作无效,因为它导致对SetCurrentCellAddressCore函数的可重入调用.

当我在编辑当前单元格时单击另一个单元格时会发生这种情况.如何规避此类错误并正确插入行?

c# datagridview invalidoperationexception

6
推荐指数
1
解决办法
1万
查看次数

以管理员身份运行 PS,但收到错误 - 该操作需要提升

由于各种新的安全策略,我们需要能够作为分配的 uid 运行各种任务。为了帮助实现这一点,开发了一个通用菜单系统。脚本中的函数之一是:

$credential = user_credential
$cmd = "C:\windows\system32\mmc.exe" 
$args = "C:\Windows\System32\compmgmt.msc"
Start-Process -FilePath $cmd -ArgumentList $args  -Credential $credential
Run Code Online (Sandbox Code Playgroud)

收到错误:

Start-Process : This command cannot be run due to the error: The requested operation requires elevation.
t C:\webeng\webeng.ps1:131 char:5
     Start-Process -FilePath $cmd -ArgumentList $args  -Credential $credential
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   + CategoryInfo          : InvalidOperation: (:) [Start-Process], InvalidOperationException
   + FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand
Run Code Online (Sandbox Code Playgroud)

该错误似乎表明 PS 脚本需要提升权限,但我已经以管理员身份运行。

我在这里可能会错过什么?

powershell credentials invalidoperationexception

6
推荐指数
1
解决办法
2万
查看次数

.Net Framework 数据提供程序错误 60

我从实时站点收到以下错误:

System.Web.HttpUnhandledException:抛出了“System.Web.HttpUnhandledException”类型的异常。---> System.InvalidOperationException: 内部 .Net Framework 数据提供程序错误 60。在 System.Transactions.TransactionStatePSPEOperation.PSPEInitialize(InternalTransaction tx, IPromotableSinglePhaseNotification promotableSinglePhaseNotification) 的 System.Data.SqlClient.SqlDelegatedTransaction.Initialize()。 .EnlistPromotableSinglePhase(InternalTransaction tx, IPromotableSinglePhaseNotification promotableSinglePhaseNotification, Transaction atomicTransaction) at System.Transactions.Transaction.EnlistPromotableSinglePhase(IPromotableSinglePhaseNotification promotableSinglePhaseNotification) at System.Internal.DataClient

在本地我无法重现它。我不会每天都遇到这样的错误,但我需要理解并修复它。从日志中我看到它发生的那段代码是:

           var transactionOptions = new System.Transactions.TransactionOptions();
           transactionOptions.IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted;

           using (var transactionScope = new System.Transactions.TransactionScope(System.Transactions.TransactionScopeOption.Required, transactionOptions))
            {
                this.DataContext = new BMDataContext();// DataContext;
                if (patientAdmissionID != -1)
                {
                    PatientAdmission admission = queryAdmission(this.DataContext, patientAdmissionID);

                    transactionScope.Complete();
                    return admission;
                }
                transactionScope.Complete();
                return null;
            }
Run Code Online (Sandbox Code Playgroud)

该方法调用 queryAdmission 使用 linq to sql 从数据库返回数据:

private static Func<BMDataContext, long, PatientAdmission> queryAdmission = System.Data.Linq.CompiledQuery.Compile( …
Run Code Online (Sandbox Code Playgroud)

c# asp.net transactionscope errorprovider invalidoperationexception

6
推荐指数
0
解决办法
1098
查看次数

数据网格视图CellValueChanged事件抛出InvalidOperationException

InvalidOperationException在我的更新改变单元格的值,并直接点击菜单条项开放新的Winform.

   private void dgv_category_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            DataTable dt = new DataTable();
            dt = u.operationOnDataBase(sqlquery_selectCategory, 3);
            if (dt.Rows.Count > 0)
            {
                MessageBox.Show("Category Already Exist...");

            }
            else
            {
                u.operationOnDataBase(sqlquery_UpdateCategory, 1);
                u.SyncMaster("update", "CategoryDetails", 0, Convert.ToInt32(dgv_category[1, e.RowIndex].Value.ToString()));//---------Sync
            }

            try
            {
                dgv_category.DataSource = null; //here Throwing exception

                u.operationOnDataBase(sqlquery, 3);
                dgv_category.DataSource = u.dt;


            }
            catch (InvalidOperationException)
            {
                // exception
            }
        }
Run Code Online (Sandbox Code Playgroud)

异常 - 操作无效,因为它导致对SetCurrentCellAddressCore函数的可重入调用.

在System.Windows.Forms.Forms.DataGridView.set_DataSource的System.Windows.Forms.DataGridView.set_CurrentCell(DataGridViewCell值)处的System.Windows.Forms.DataGridView.SetCurrentCellAddressCore(Int32 columnIndex,Int32 rowIndex,Boolean setAnchorCellAddress,Boolean validateCurrentCell,Boolean throughMouseClick) (对象值)

.net c# datagridview invalidoperationexception winforms

6
推荐指数
1
解决办法
633
查看次数