I am new to signal r and I am trying to create a basic chat application in c# visual studio 2012 but i am getting following error.
The following errors occurred while attempting to load the app.
- No assembly found containing an OwinStartupAttribute.
- The discovered startup type 'SignalRTutorials.Startup, SignalRTutorials, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
conflicts with the type 'Microsoft.VisualStudio.Web.PageInspector.Runtime.Startup, Microsoft.VisualStudio.Web.PageInspector.Runtime, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
Remove or rename one of the types, or reference the desired type directly.
To disable OWIN startup discovery, add the appSetting owin:AutomaticAppStartup with a value of "false" in your web.config.
To specify the OWIN startup Assembly, Class, or Method, add the appSetting owin:AppStartup with the fully qualified startup class or configuration method name in your web.config.
I have created 3 files:
1) first is Letschat.cs class as:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.AspNet.SignalR;
using Microsoft.AspNet.SignalR.Hubs;
namespace SignalRTutorials
{
[HubName("myChatHub")]
public class LetsChat:Hub
{
public void send(string message)
{
Clients.All.addMessage(message);
}
}
}
2) second file chat.aspx as
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Chat.aspx.cs" Inherits="SignalRTutorials.Chat" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="Scripts/jquery-1.6.4.min.js"></script>
<script src="Scripts/jquery-1.6.4-vsdoc.js"></script>
<script src="Scripts/jquery-1.6.4.min.js"></script>
<script src="Scripts/jquery.signalR-2.0.0.js"></script>
<script src="Scripts/jquery.signalR-2.0.0.min.js"></script>
</head>
<body>
<form id="form1" runat="server">
<script type="text/javascript">
$(function()
{
var IWannaChat=$.connection.myChatHub;
IWannaChat.client.addMessage=function(message){
$('#listMessages').append('<li>'+message+'</li>');
};
$("#SendMessage").click(function(){
IWannaChat.server.send($('#txtMessage').val());
});
$.connection.hub.start();
});
</script>
<div>
<input type="text" id="txtMessage" />
<input type="text" id="SendMessage" value="broadcast" />
<ul id="listMessages">
</ul>
</div>
</form>
</body>
</html>
3) class Named as Startup.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using System.Web;
using System.Web.Routing;
using Microsoft.AspNet.SignalR;
using Microsoft.Owin.Security;
using Owin;
namespace SignalRTutorials
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.MapSignalR();
}
}
}
I dont know where i am doing wrong any help in this regard will be appreciated.
Was facing the same problem.
Tried adding assembly level attribute, as suggested by #Praburaj
You can try the following.
using Microsoft.AspNet.SignalR;
using Microsoft.Owin.Security;
using Owin;
//add the attribute here
[assembly: OwinStartup(typeof(SignalRTutorials.Startup))]
namespace SignalRTutorials
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.MapSignalR();
}
}
}
I had the same problem but on Visual Studio 2013.
Removing the \bin and \obj folders on my project then rebuilding it fixed the problem.
You just need to add OWIN StartUp class [i.e. StartUp1.cs] into your project.
using System;
using System.Threading.Tasks;
using Microsoft.Owin;
using Owin;
[assembly: OwinStartup(typeof(UserInterfaceLayer.Hubs.Startup))]
namespace UserInterfaceLayer.Hubs
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.MapSignalR();
}
}
}
If you have built your project, and then renamed it, this issue might occur. Try delete all the files in the bin folder and then run your project. This worked for me.
Just add this line
[assembly: OwinStartup(typeof(SignalRTutorials.Hubs.Startup))] as described here
http://yazilimsozluk.com/no-assembly-found-containing-an-owinstartupattribute
Related
How can I bind the startup.cs file adding manually to the project?
I created it from Add > New Item > OWIN Startup class but is ignored by the app.
The Startup class
using System;
using System.Threading.Tasks;
using Microsoft.Owin;
using Owin;
[assembly: OwinStartup(typeof(WebApplication1.Startup))]
namespace WebTest
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=316888
}
}
}
Thanks
Update
I can do it thanks to this
OwinStartup not firing
[assembly: OwinStartup(typeof(**WebApplication1**.Startup))]
In the OwinStartup attribute you specify a class WebApplication1.Startup but the class shown says WebTest.Startup
I'm trying to do following project for learning purposes:
https://learn.microsoft.com/ru-ru/aspnet/web-forms/overview/getting-started/getting-started-with-aspnet-45-web-forms/create_the_data_access_layer
But I got stuck on the step "Updating the Global.asax file" - VS doesn't allow me to import WingtipToys.Models namespace to Global.asax.cs file.
Here's the project structure, Globa.asax.cs and 'using' error
Everything is done according to Microsoft's tutorial above.
Why can't I to import my models to global.asax.cs file?
My ProductDatabaseInitializer class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
namespace WingtipToys.Models
{
public class ProductDatabaseInitializer : DropCreateDatabaseIfModelChanges<ProductContext>
{
protected override void Seed(ProductContext context)
{
GetCategories().ForEach(c => context.Categories.Add(c));
GetProducts().ForEach(p => context.Products.Add(p));
}....
What did really help is a re-creation of all classes in Models directory (delete all old classes and create new ones with same code) - then I started to see my classes from Global.asax.cs file.
Maybe it could help someone.
I am facing a strange imtermittent issue with Azure AD authentication.
We are using CORS enabled web api in our project (origins are specified in web.config which are fetched by custom attribute, and this attribute is used for controllers).
Athorization part is done using adal.js
code is as follows:
startup.cs
using Microsoft.Owin;
using Owin;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
[assembly: OwinStartup(typeof(test.testapi.WebApi.Startup))]
namespace Test.testapi.WebApi
{
public partial class Startup
{
public void Configuration(IAppBuilder app)
{
ConfigureAuth(app);
}
}
}
Startup.auth.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Security.Claims;
using Microsoft.Owin.Security.ActiveDirectory;
using System.Configuration;
using Owin;
using System.Net;
namespace test.testapi.WebApi
{
public partial class Startup
{
public void ConfigureAuth(IAppBuilder app)
{
//Following line is not required if you are using HTTPS calls to APIs
//ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
app.UseWindowsAzureActiveDirectoryBearerAuthentication(
new WindowsAzureActiveDirectoryBearerAuthenticationOptions
{
Audience = ConfigurationManager.AppSettings["ida:Audience"],
Tenant = ConfigurationManager.AppSettings["ida:Tenant"],
});
}
}
}
When the control goes to startup.auth.cs it gives System.Net.Http.HttpRequestException
Error
Now thing is while i was working on my local dev environment i never got this issue(always authenticated fine ) but QA was facing this issue on QA server, so we started hosting web api from my machine, After which i also started getting this issue and that too quite frequently now.
what is this issue if anyone has faced this same issue.
I have a C# solution composed of three projects in Visual Sudio 2010. One is X.Domain (class library) the second, X.UnitTest and the third X.WebUI (MVC3). I was having problems with the using statement to reference the X.Domain namespace from withing the X.WebUI namespace. I thought it was a client profiling issue and verifired that all of the projects where using ".Net Framework 4" as the target framework. I checked to make sure the project dependencies for X.WebUI included the namesapce X.Domain. The exact errors I'm getting are:
The type or namespace name 'Domain' does not exist in the namespace'X' (are you missing an assembly reference). The error for the interface I'm trying to use from within X.Domain.Abstract: The type or namespace name 'IPersonRepository' could not be found (are you missing a using directive or an assembly reference)
In the X.Domain namespace/project, there are public methods, so I'm not sure why it's not exposed. I looked into these links here on stackoverflow, but they did not resolve the issue. Visual Studio 2010 suddenly can't see namespace?,
The type or namespace name could not be found ,
The type or namespace 'MyNamespace' does not exist etc
It's worth mentioning that someone posted that it could have something to do with a missed configured global.asax file, here
Type or namespace name does not exist
in that link, but I'm not sure about it. Could be the case, so I am posting my Global.asax file as well. I noticed the problem when I'm trying to create my 'PersonController' with ninject MVC3, I used Remo.gloo's blog to help me create the Global.asax file as posted here http://www.planetgeek.ch/2010/11/13/official-ninject-mvc-extension-gets-support-for-mvc3/ and am following along with some additional code on p.164 of the the Pro ASP.NET MVC3 Framework book to create the controller.
PersonController.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using KLTMCInsight.Domain.Abstract;
namespace KLTMCInsight.WebUI.Controllers
{
public class PersonController : Controller
{
private readonly IPersonRepository repository;
public PersonController(IPersonRepository personRepository)
{
repository = personRepository;
}
}
}
Global.asax
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using System.Reflection;
using Ninject;
using Ninject.Modules;
using Ninject.Web.Mvc;
namespace KLTMCInsight.WebUI
{
public class MvcApplication : NinjectHttpApplication
{
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
}
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
protected override IKernel CreateKernel()
{
var kernel = new StandardKernel();
kernel.Load(Assembly.GetExecutingAssembly());
return kernel;
}
protected override void OnApplicationStarted()
{
base.OnApplicationStarted();
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
}
}
}
If I missed something you need, I'll be more than glad to post it up. Again, Thank you for your help- Very appreciated.
Here is the solution:
I had used the 'Project Dependencies' box listed under the 'Project' file menu to select the dependencies of the X.WebUI project. Even though on in it I had checked the box for the X.WebUI project to depend on the X.Domain project... the reference was never created by VS2010. To solve the issue it was a simple fix by manually right-clicking the References folder under X.WebUI, and adding the reference to X.Domain through that window. Reference was added problem solved. Not sure why the reference was not made from the 'Project Dependencies' box in the first place, but if anyone comes across this same problem- this should remind you to check if the reference was actually made.
I have a WCF service in folder "Services":
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.Web.Services;
using System.ServiceModel.Activation;
using System.Web.Script.Services;
namespace Application.Services
{
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ScriptService]
public class ProductTypeService
{
[OperationContract]
[WebMethod]
public string LoadMainGridProductType(string test)
{
return "Success";
}
}
}
and on page I try to call this service method from javascript:
$(document).ready(function () {
var counter = "test";
Application.Services.ProductTypeService.LoadMainGridProductType(counter, ResultLoadMainGridProductType, ErrorLoadMainGridProductType);
});
on page I also make conect to this service and javascript files:
<asp:ScriptManager ID="ScriptManager" runat="server">
<Scripts>
<asp:ScriptReference Path="~/Scripts/ProductType.js" />
</Scripts>
<Services>
<asp:ServiceReference Path="~/Services/ProductTypeService.svc" />
</Services>
</asp:ScriptManager>
but code fails on
Application.Services.ProductTypeService.LoadMainGridProductType(counter, ResultLoadMainGridProductType, ErrorLoadMainGridProductType);
Error : Error of implementation of Microsoft Jscript: "Application" is not certain.
How fix this???
Firstly, check to see if the WCF service is working correctly by navigating directly to it, e.g. http://localhost:(port-number)/Services/ProductTypeService.svc
I suspect that this wont work and give you some errors.
Secondly, check to make sure that the jsdebug javascript file has been generated and is included in the scripts loaded with the application.
Another person asked a similar question earlier.
How get namespace on javascript in asp.net web?