I'm trying to create a server and a asp.net client (2 projects in one solution..).
In the server in the class where the hub is defined i get an error ...
I use visual studio 2013.
this is the startup:
using System;
using System.Threading.Tasks;
using Microsoft.Owin;
using Owin;
[assembly: OwinStartup(typeof(TestServer.Startup))]
namespace TestServer
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
// Any connection or hub wire up and configuration should go here
app.MapSignalR();
}
}
}
the hub:
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNet.SignalR;
using Microsoft.AspNet.SignalR.Hubs;
namespace TestServer
{
[HubName("ServerHub")]
class ServerHub : Hub
{
public void Send(string message)
{
Clients.All.AddMessage(message);
}
}
}
it marks Clients.All.AddMessage(message) as an error : "One or more types required to compile a dynamic expression cannot be found. Are you missing a reference?" I can't understand what reference is missing.
You need to include the Microsoft.CSharp library.
It's easy to do, under the Add Reference dialog go to the Assemblies -> Framework tab. You'll see Microsoft.CSharp listed, add it.
Hope this helps!
Related
Below is the sample I found from online Tutorial to host the website suing OWIN, however when I try to run on my machine, I got this error
CS0246 The type or namespace name 'Func<,>' could not be found (are you missing a using directive or an assembly reference?)
I think for using 'Func<,>' I have using System, and for IDictionary, I have using System.Collections.Generic; so I don't understand why it still can't work.
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Owin;
using Owin;
using AppFunc = Func<IDictionary<string, object>, Task>;
public class Startup
{
public void Configuration(IAppBuilder app)
{
var middleware = new Func<AppFunc, AppFunc>(MyMiddleWare);
app.Use(middleware);
app.Use<OtherMiddleware>();
}
public AppFunc MyMiddleWare(AppFunc next)
{
AppFunc appFunc = async (IDictionary<string, object> environment) =>
{
var response = environment["owin.ResponseBody"] as Stream;
byte[] str = Encoding.UTF8.GetBytes("My First Middleware");
await response.WriteAsync(str, 0, str.Length);
await next.Invoke(environment);
};
return appFunc;
}
public class OtherMiddleware : OwinMiddleware
{
public OtherMiddleware(OwinMiddleware next) : base(next) { }
public override async Task Invoke(IOwinContext context)
{
byte[] str = Encoding.UTF8.GetBytes(" Other middleware");
context.Response.Body.Write(str, 0, str.Length);
await this.Next.Invoke(context);
}
}
}
You need to put the AppFunc in the class so it can use the using,
Or you can use full namespace for Func, IDictionary and Task
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Owin;
using Owin;
// Use this
using AppFunc = System.Func<System.Collections.Generic.IDictionary<string, object>, System.Threading.Tasks.Task>;
public class Startup
{
// Or this
using AppFunc = Func<IDictionary<string, object>, Task>;
...
}
For me it was low .NET Target Framework version 2.0 of application. Changed to 4.7 (it seems minimal is 3.5).
You need to make sure you added the reference System.Runtime.CompileServices to your project as you see in here: https://msdn.microsoft.com/en-us/library/bb549151(v=vs.110).aspx the delegate is part of mscorlib assembly.
The exception is:
System.MissingMethodException
Constructor on type 'MyApp.Droid.MyGridRenderer' not found
The custom renderer:
using System;
using Android.Content;
using Android.Graphics;
using Android.Text;
using Android.Util;
using MyApp;
using MyApp.Droid;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
[assembly: ExportRenderer(typeof(Grid), typeof(MyGridRenderer))]
namespace MyApp.Droid
{
public class MyGridRenderer : ViewRenderer<Grid, Android.Views.View>
{
protected MyGridRenderer(Context context) : base(context)
{
}
}
}
I have Visual Studio Community for Mac version 7.3.2
Just in case, this is the custom renderer for iOS, which is working ok without any constructors:
using System;
using CoreGraphics;
using CoreText;
using Foundation;
using MyApp;
using MyApp.iOS;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
[assembly: ExportRenderer(typeof(Grid), typeof(MyGridRenderer))]
namespace MyApp.iOS
{
public class MyGridRenderer : ViewRenderer<Grid, UIView>
{
}
}
The signature of the constructor for Android custom renderers changed in the latest version (2.5.0) of Xamarin forms to require the context to be passed.
You can see that here in the release notes.
This is not something that is required for iOS.
Try changing protected to public.
I am trying to Xamarin.uiTest to automate an application and I got this error in very initial stage.
System.InvalidOperationException : Sequence contains no elements
Code: AppInitializer.cs
using System;
using System.IO;
using System.Linq;
using Xamarin.UITest;
using Xamarin.UITest.Queries;
namespace MyXamarinApp1_Test1
{
public class AppInitializer
{
public static IApp StartApp(Platform platform)
{
if (platform == Platform.Android)
{
return ConfigureApp
.Android
//.InstalledApp("com.companyname.MyXamarinApp1")
.ApkFile("C:\\Users\\...\\Desktop\\com.companyname.MyXamarinApp1.apk")
.StartApp();
}
return ConfigureApp
.iOS.StartApp();
}
}
}
Code: Test.cs
using System;
using System.IO;
using System.Linq;
using NUnit.Framework;
using Xamarin.UITest;
using Xamarin.UITest.Queries;
namespace UITest1
{
[TestFixture(Platform.Android)]
[TestFixture(Platform.iOS)]
public class Tests
{
IApp app;
Platform platform;
public Tests(Platform platform)
{
this.platform = platform;
}
[SetUp]
public void BeforeEachTest()
{
app = AppInitializer.StartApp(platform);
}
[Test]
public void AppLaunches()
{
app.Screenshot("First screen.");
}
}
Any idea to resolve the issue is appreciated.
I am using the signed app, could it be an issue.
Xamarin version : 2.0.3
Nunit : 2.6.4
try downgrading or upgrading it to Xamarin 2.2.1 or less and try cleaning solution or delete debug folder and build and run the command in fresh command line window, it may fix.. not 100% sure
I've put all my Views in their own folders in Visual Studio and now the content is not rendering anymore. From where do I have to set the path for them to render?
Well, the convention is that Umbraco templates live in the ~/View folder. If they live anywhere else you loose the tooling support in the backoffice (and confuse any other Umbraco devs who pick up the project!).
However, provided the folder names match the names of the document types, you could create a controller for each of your document types (i.e. hijack the routing). I'm sure this would allow Umbraco to check in the subfolders.
I'm doing a multisite with single core Umbraco 7. Here's how I'm handling that at the moment:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Web.Mvc;
using Umbraco.Core;
using Umbraco.Web.Mvc;
using Umbraco.Core.Logging;
namespace MyApp.UmbracoExtensions.Shared.Events
{
public class RegisterCustomViewEngine : ApplicationEventHandler
{
protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
ViewEngines.Engines.Add(new CustomViewEngine());
base.ApplicationStarting(umbracoApplication, applicationContext);
}
}
public class CustomViewEngine : RazorViewEngine
{
private static string[] NewViewFormats = new[] {
"~/Views/SomeFolder/{0}.cshtml",
"~/Views/AnotherFolder/{0}.cshtml",
"~/Views/Wiki/{0}.cshtml"
};
public CustomViewEngine()
{
base.ViewLocationFormats = base.ViewLocationFormats.Union(NewViewFormats).ToArray();
}
}
}
I am attempting to figure out how to host MVC4 apps that were built under different solutions. There are many examples of doing this on SO and on the web using the RazorGenerator nuget package with Areas - it works very well. In my situation, I want to avoid using areas - every application my company develops will be in it's own MVC4 project (then collectively in the same solution).
I've integrated RazorGenerator into my apps, the code gen is working as expected. However, my host solution can not find the View in it's default locations. As an example, I have a Controller/View built in one app called MyAccount/Index.
Controller:
namespace Accounts.Controllers
{
public class MyAccountController : Controller
{
//
// GET: /MyAccount/
public ActionResult Index()
{
return View();
}
}
}
View (as generated from RazorGenerator):
namespace Accounts.Views.MyAccount
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Web;
using System.Web.Helpers;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using System.Web.Mvc.Html;
using System.Web.Routing;
using System.Web.Security;
using System.Web.UI;
using System.Web.WebPages;
[System.CodeDom.Compiler.GeneratedCodeAttribute("RazorGenerator", "1.5.4.0")]
[System.Web.WebPages.PageVirtualPathAttribute("~/Views/MyAccount/Index.cshtml")]
public partial class Index : System.Web.Mvc.WebViewPage<dynamic>
{
public Index()
{
}
public override void Execute()
{
#line 1 "..\..\Views\MyAccount\Index.cshtml"
ViewBag.Title = "Index";
#line default
#line hidden
WriteLiteral("\r\n\r\n<h2>Index</h2>\r\n\r\nMy AccountController Index view.");
}
}
}
I know that by default, the ViewEngines are going to try to find this view in the default locations (Views and Shared), so I added my own ViewEngine to the Engines collection:
MyViewEngine.cs:
public class MyViewEngine : RazorViewEngine
{
private static string[] _viewLocations
= new string[]
{
"~/Accounts/Views/{1}/{0}.cshtml"
};
public MyViewEngine()
{
base.ViewLocationFormats = ViewLocationFormats.Union(_viewLocations).ToArray();
}
}
However, the view still isn't found:
The view 'Index' or its master was not found or no view engine supports the searched locations.
The following locations were searched:
~/Views/MyAccount/Index.cshtml
~/Views/Shared/Index.cshtml
~/Views/MyAccount/Index.aspx
~/Views/MyAccount/Index.ascx
~/Views/Shared/Index.aspx
~/Views/Shared/Index.ascx
~/Views/MyAccount/Index.vbhtml
~/Views/Shared/Index.vbhtml
~/Accounts/Views/MyAccount/Index.cshtml
Maybe I am misunderstanding how the view is located -I had thought it would have been found in Accounts/Views/MyAccount/. Any ideas what I might be doing wrong?
Thanks!
Found my issue - it was due to not having the RazorGeneratorMvcStart warmup code in place. It is generated automatically into the App_Start folder when you add the nuget package, however I erroneously removed it.