问题:

为什么我收到错误:

模板只能用于字段访问,属性访问,单维数组索引或单参数自定义索引器表达式

在这段代码:

@model IEnumerable<ArtSchoolProject.Models.Trainer>

@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_PageLayout.cshtml";
}

<h2>Index</h2>

<p>
@Html.ActionLink("Create New", "Create")
</p>
<ul class="trainers">


@foreach (var item in Model) {
<li>
  <div>
      <div class="left">
          <a href="@Url.Action("Details", "Details", new { id = item.ID })">
              <img src="~/Images/Trainer/@item.Picture" />
          </a>
      </div>
      <div class="right">
          @Html.ActionLink(item.Name,"Details",new {id=item.ID})
          <br />
          @Html.DisplayFor(modelItem=>@string. item.Description.ToString().Substring(0,100))
      </div>
  </div>
  </li>
  }

  </ul>

在线:

@Html.DisplayFor(modelItem=>item.Description.ToString().Substring(0,100))

更新:

问题解决了。 我添加到我的代码中:

  @{
string parameterValue = item.Description.ToString().Substring(0, 100); 
          }
          @Html.DisplayFor(modelItem=>parameterValue)

我的新代码:

@foreach (var item in Model) {
<li>
  <div>
      <div class="left">
          <a href="@Url.Action("Details", "Details", new { id = item.ID })">
              <img src="~/Images/Trainer/@item.Picture" />
          </a>
      </div>
      <div class="right">
          @Html.ActionLink(item.Name,"Details",new {id=item.ID})
          <br />
          @{
string parameterValue = item.Description.ToString().Substring(0, 100); 
          }
          @Html.DisplayFor(modelItem=>parameterValue)
      </div>
  </div>
 </li>
}

这只是一种可能性。 只是出于好奇,还有另一种解决错误的方法吗?

Why am I receiving the error:Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressionsat this code:at line:Update:Problem solved.I added to my code :My new code:This is only one possibility.Just for curiosity is there another solution for solving the error?

问题:

我通过在C#中编写代码来构建C ++ dll。

我说错了

检测到LoaderLock消息:尝试在OS Loader锁内进行托管执行。 不要尝试在DllMain或图像初始化函数中运行托管代码,因为这样做可能导致应用程序挂起。

我尝试搜索该错误的确切含义,但我写的文章毫无意义,主要是说这只是一个警告,我应该在Visual Studio中将其关闭。 其他解决方案似乎是由于iTunes引起的,或者是在使用DirectX编程时发生了此问题。 我的问题与两个都不相关。

谁能解释,这实际上意味着什么?

I am building on C++ dll, by writing code in C#.I get an error, sayingLoaderLock was detected Message: Attempting managed execution inside OS Loader lock.Do not attempt to run managed code inside a DllMain or image initialization function since doing so can cause the application to hang.I tried seraching what this error exactly means, but I am drawing pointless articles, mostly saying that it’s just a warning, and I should switch that off in Visual Studio.The other solutions seem to be due to ITunes, or this problem occurring when programming with DirectX.My problem is connected to neither.Can anybody explain, what this actually means?

问题:

当在WebApi GET操作中找不到某些内容时,我将返回NotFound IHttpActionResult 与此响应一起,我要发送自定义消息和/或异常消息(如果有)。 当前的ApiControllerNotFound()方法没有提供重载来传递消息。

有什么办法吗? 还是我必须编写自己的自定义IHttpActionResult ?

I am returning a NotFound IHttpActionResult , when something is not found in my WebApi GET action.Along with this response, I want to send a custom message and/or the exception message (if any).The current ApiController ‘s NotFound() method does not provide an overload to pass a message.Is there any way of doing this?or I will have to write my own custom IHttpActionResult ?

问题:

我正在尝试部署ClickOnce应用程序,但在客户端上安装失败。 这是错误日志:

PLATFORM VERSION INFO
Windows             : 6.1.7601.65536 (Win32NT)
Common Language Runtime     : 4.0.30319.1
System.Deployment.dll       : 4.0.30319.1 (RTMRel.030319-0100)
clr.dll             : 4.0.30319.1 (RTMRel.030319-0100)
dfdll.dll           : 4.0.30319.1 (RTMRel.030319-0100)
dfshim.dll          : 4.0.31106.0 (Main.031106-0000)

SOURCES
Deployment url          : http://MyProduct.com/download/workstation/MyProduct%20Front%20Desk.application
                    Server      : Microsoft-IIS/7.5
                    X-Powered-By    : ASP.NET
Deployment Provider url     : http://MyProduct.com/Download/Workstation/MyProduct%20Front%20Desk.application
                    Server      : Microsoft-IIS/7.5
                    X-Powered-By    : ASP.NET
Application url         : http://MyProduct.com/Download/Workstation/Application%20Files/MyProduct%20Front%20Desk_1_0_0_7/MyProduct%20Front%20Desk.exe.manifest
                    Server      : Microsoft-IIS/7.5
                    X-Powered-By    : ASP.NET

IDENTITIES
Deployment Identity     : MyProduct Front Desk.application, Version=1.0.0.7, Culture=neutral, PublicKeyToken=df343a0868ab2d74, processorArchitecture=msil
Application Identity        : MyProduct Front Desk.exe, Version=1.0.0.7, Culture=neutral, PublicKeyToken=df343a0868ab2d74, processorArchitecture=msil, type=win32

APPLICATION SUMMARY
* Installable application.

ERROR SUMMARY
Below is a summary of the errors, details of these errors are listed later in the log.
* Activation of http://MyProduct.com/download/workstation/MyProduct%20Front%20Desk.application resulted in exception. Following failure messages were detected:
    + Reference in the manifest does not match the identity of the downloaded assembly MyProductSiteServer.exe.

COMPONENT STORE TRANSACTION FAILURE SUMMARY
No transaction error was detected.

WARNINGS
There were no warnings during this operation.

OPERATION PROGRESS STATUS
* [03/17/11 11:51:04] : Activation of http://MyProduct.com/download/workstation/MyProduct%20Front%20Desk.application has started.
* [03/17/11 11:51:04] : Processing of deployment manifest has successfully completed.
* [03/17/11 11:51:04] : Installation of the application has started.
* [03/17/11 11:51:05] : Processing of application manifest has successfully completed.
* [03/17/11 11:51:06] : Found compatible runtime version 4.0.30319.
* [03/17/11 11:51:06] : Request of trust and detection of platform is complete.

ERROR DETAILS
Following errors were detected during this operation.
* [03/17/11 11:51:30] System.Deployment.Application.InvalidDeploymentException (RefDefValidation)
    - Reference in the manifest does not match the identity of the downloaded assembly MyProductSiteServer.exe.
    - Source: System.Deployment
    - Stack trace:
        at System.Deployment.Application.DownloadManager.ProcessDownloadedFile(Object sender, DownloadEventArgs e)
        at System.Deployment.Application.FileDownloader.DownloadModifiedEventHandler.Invoke(Object sender, DownloadEventArgs e)
        at System.Deployment.Application.SystemNetDownloader.DownloadSingleFile(DownloadQueueItem next)
        at System.Deployment.Application.SystemNetDownloader.DownloadAllFiles()
        at System.Deployment.Application.FileDownloader.Download(SubscriptionState subState)
        at System.Deployment.Application.DownloadManager.DownloadDependencies(SubscriptionState subState, AssemblyManifest deployManifest, AssemblyManifest appManifest, Uri sourceUriBase, String targetDirectory, String group, IDownloadNotification notification, DownloadOptions options)
        at System.Deployment.Application.ApplicationActivator.DownloadApplication(SubscriptionState subState, ActivationDescription actDesc, Int64 transactionId, TempDirectory& downloadTemp)
        at System.Deployment.Application.ApplicationActivator.InstallApplication(SubscriptionState& subState, ActivationDescription actDesc)
        at System.Deployment.Application.ApplicationActivator.PerformDeploymentActivation(Uri activationUri, Boolean isShortcut, String textualSubId, String deploymentProviderUrlFromExtension, BrowserSettings browserSettings, String& errorPageUrl)
        at System.Deployment.Application.ApplicationActivator.ActivateDeploymentWorker(Object state)

COMPONENT STORE TRANSACTION DETAILS
No transaction information is available.

我需要部署的主要exe是MyProductFrontDesk.exe ,它依赖于MyProductSiteServer.exe – 这似乎是抛出错误的位置:“清单中的引用与下载的程序集MyProductSiteServer.exe的标识不匹配“。

哪个清单需要纠正? 如何?

I’m trying to deploy a ClickOnce application, but installation fails on the client.Here’s the error log:The main exe I need to deploy is MyProductFrontDesk.exe , which has a dependency on MyProductSiteServer.exe – and that appears to be where the error is being thrown: “Reference in the manifest does not match the identity of the downloaded assembly MyProductSiteServer.exe.”Which manifest needs to be corrected?And how?

问题:

我已经按照本教程进行了很好的工作,直到我修改了我的DbContext以获得额外的构造函数。 我现在遇到了解决方案的问题,不知道如何解决这个问题。 是否有一种简单的方法可以强制它抓住无参数构造函数,或者我接近这个错误?

带有两个构造函数的DbContext :

public class DashboardDbContext : DbContext
{
    public DashboardDbContext() : base("DefaultConnection") { }

    public DashboardDbContext(DbConnection dbConnection, bool owns)
        : base(dbConnection, owns) { }
}

SiteController构造函数:

private readonly IDashboardRepository _repo;

public SiteController(IDashboardRepository repo)
{
    _repo = repo;
}

库:

DashboardDbContext _context;

public DashboardRepository(DashboardDbContext context)
{
    _context = context;
}

UnityResolver代码:

public class UnityResolver : IDependencyResolver
{
    private readonly IUnityContainer _container;

    public UnityResolver(IUnityContainer container)
    {
        _container = container;
    }

    public object GetService(Type serviceType)
    {
        try
        {
            return _container.Resolve(serviceType);
        }
        catch (ResolutionFailedException)
        {
            return null;
        }
    }

    public IEnumerable<object> GetServices(Type serviceType)
    {
        try
        {
            return _container.ResolveAll(serviceType);
        }
        catch (ResolutionFailedException)
        {
            return new List<object>();
        }
    }

    public IDependencyScope BeginScope()
    {
        var child = _container.CreateChildContainer();
        return new UnityResolver(child);
    }

    public void Dispose()
    {
        _container.Dispose();
    }
}

WebApiConfig:

var container = new UnityContainer();
container.RegisterType<IDashboardRepository, DashboardRepository>(new HierarchicalLifetimeManager());
config.DependencyResolver = new UnityResolver(container);

WebApi调用出错:

System.InvalidOperationException:尝试创建“SiteController”类型的控制器时发生错误。 确保控制器具有无参数的公共构造函数。

at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType) 
at System.Web.Http.Controllers.HttpControllerDescriptor.CreateController(HttpRequestMessage request) 
at System.Web.Http.Dispatcher.HttpControllerDispatcher.SendAsyncCore(HttpRequestMessage request, CancellationToken cancellationToken) 
at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__0.MoveNext()

InnerException:System.ArgumentException:Type’Dashboard.Web.Controllers.SiteController’没有默认构造函数。

at System.Linq.Expressions.Expression.New(Type type) 
at System.Web.Http.Internal.TypeActivator.Create[TBase](Type instanceType) 
at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.GetInstanceOrActivator(HttpRequestMessage request, Type controllerType, Func`1& activator) 
at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType)

该教程非常棒,并且在我添加第二个构造函数之前一直很好用。

I have followed this tutorial which has worked great, until I modified my DbContext to have an additional constructor.I am now having issues with the resolution and not sure what to do to fix this.Is there an easy way to force it to grab the parameterless constructor or I am approaching this incorrectly?DbContext with two constructors:SiteController constructor:Repository:UnityResolver code:WebApiConfig:Error from WebApi Call:System.InvalidOperationException: An error occurred when trying to create a controller of type ‘SiteController’.Make sure that the controller has a parameterless public constructor.InnerException: System.ArgumentException: Type ‘Dashboard.Web.Controllers.SiteController’ does not have a default constructor.The tutorial was great and has been working well for me up until I added the second constructor.