I recently followed Xamarin's SQLite tutorial to install SQLite-net PCL. Everything works perfectly on the simulator in Debug mode but I'm getting crashes on startup in Release mode.
The exception is as follows:
exception:
System.MissingMethodException
message:
Default constructor not found for type MyApp.iOS.FileHelper
stack trace:
at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain
(int,string[],intptr,intptr) at UIKit.UIApplication.Main
(System.String[] args, System.IntPtr principal, System.IntPtr
delegate) [0x00005] in
/Users/builder/data/lanes/3969/7beaef43/source/xamarin-macios/src/UIKit/UIApplication.cs:79
at UIKit.UIApplication.Main (System.String[] args, System.String
principalClassName, System.String delegateClassName) [0x00038] in
/Users/builder/data/lanes/3969/7beaef43/source/xamarin-macios/src/UIKit/UIApplication.cs:63
at MyApp.iOS.Application.Main (System.String[] args) [0x00008] in
/Users/{FilePath}/iOS/Main.cs:13
What I've found
So this MyApp.iOS.FileHelper is Xamarin's code that fetches the documents directory. The implementation goes like this:
In the Forms application we just have a contract:
public interface IFileHelper
{
string GetLocalFilePath(string filename);
}
In the MyApp.iOS project we define a dependency:
[assembly: Dependency(typeof(FileHelper))]
namespace MyApp.iOS
{
public class FileHelper : IFileHelper
{
public FileHelper() { }
public string GetLocalFilePath(string filename)
{
string docFolder = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
string libFolder = Path.Combine(docFolder, "..", "Library", "Databases");
if (!Directory.Exists(libFolder))
{
Directory.CreateDirectory(libFolder);
}
return Path.Combine(libFolder, filename);
}
}
}
Here's how I am using it:
DependencyService.Get<IFileHelper>().GetLocalFilePath("MyAppDatabase.db3")
The application works as expected in Debug mode. So either the Dependency Service is behaving differently in Release or the Documents Directory is different in Release.
My Question
How can avoid this exception in release mode?
Dependency Info:
Xamarin Forms 2.3.3.193
Sqlite-net-pcl 1.2.1
update:
What I've tried:
Added a default constructor, yields no change
Tried different linker possibilities, yields no change
From Introduction to DependencyService
Note that every implementation must have a default (parameterless)
constructor in order for DependencyService to be able to instantiate
it. Parameterless constructors cannot be defined by the interface.
You need to add an empty constructor to your FileHelper class.
public FileHelper() {
}
Please note: I tried voting to close this question as a duplicate. It clearly
failed to be closed as such.
Based on comments point to this post from SushiHangover, this is what resolved my issue:
I needed to add decorate my FileHelper class in my iOS project with:
[Preserve(AllMembers = true)]
again, please go check out his original post here:
https://stackoverflow.com/a/41932246/1664443
Related
After updating Blazor from 0.5.1 (with working Flurl) to 0.6.0, calls via flurl throw an exception:
WASM: [Flurl.Http.FlurlHttpException] Call failed. Cannot invoke method
because it was wiped. See stack trace for details.
The project creates a HttpClientFactory which gets Blazor's HttpClient for being used by Flurl:
Create FlurlClient with Blazor's HttpClient (http) using HttpClientFactoryForBlazor:
IFlurlClient c = new FlurlClient() { Settings = new Flurl.Http.Configuration.ClientFlurlHttpSettings { HttpClientFactory = new HttpClientFactoryForBlazor(http) }};
Use the FlurlClient (c) for example by via Flurl's extensionmethod "IFlurlRequest.WithClient(c);"
private class HttpClientFactoryForBlazor : Flurl.Http.Configuration.IHttpClientFactory
{
private readonly HttpClient httpClient;
public HttpClientFactoryForBlazor(HttpClient httpClient)
{
this.httpClient = httpClient;
}
public virtual HttpClient CreateHttpClient(HttpMessageHandler handler)
{
return this.httpClient;
}
}
So, it seems like this approach does no longer work.
Does anybody know how to make Flurl with Blazor 0.6.0 work?
Call-Stack is:
WASM: [Flurl.Http.FlurlHttpException] Call failed. Cannot invoke method because it was wiped. See stack trace for details. GET http://srv01.servicegrid.eu:4455/API/Status?forceLoadDbs=False blazor.webassembly.js:1:32098
WASM: at Flurl.Http.FlurlRequest.HandleExceptionAsync (Flurl.Http.HttpCall call, System.Exception ex, System.Threading.CancellationToken token) <0x26945b8 + 0x001c2> in <c38761af4558433f81b1691eb86a1548>:0 blazor.webassembly.js:1:32098
WASM: at Flurl.Http.FlurlRequest.SendAsync (System.Net.Http.HttpMethod verb, System.Net.Http.HttpContent content, System.Threading.CancellationToken cancellationToken, System.Net.Http.HttpCompletionOption completionOption) <0x2665d30 + 0x005e6> in <c38761af4558433f81b1691eb86a1548>:0 blazor.webassembly.js:1:32098
WASM: at Flurl.Http.FlurlRequest.SendAsync (System.Net.Http.HttpMethod verb, System.Net.Http.HttpContent content, System.Threading.CancellationToken cancellationToken, System.Net.Http.HttpCompletionOption completionOption) <0x2665d30 + 0x0079a> in <c38761af4558433f81b1691eb86a1548>:0 blazor.webassembly.js:1:32098
WASM: at Flurl.Http.HttpResponseMessageExtensions.ReceiveJson[T] (System.Threading.Tasks.Task`1[TResult] response) <0x26a2180 + 0x000d6> in <c38761af4558433f81b1691eb86a1548>:0 blazor.webassembly.js:1:32098
WASM: at DotNetFabrik.FlurlExtensions.FlurlRequestExtensions.HandleWebApiExceptions[T] (System.Threading.Tasks.Task`1[TResult] task) <0x26a43f8 + 0x000e2> in <8c1e6df9d3f545cd831ff49915df2d85>:0 blazor.webassembly.js:1:32098
WASM: at DotNetFabrik.FlurlExtensions.FlurlRequestExtensions.HandleWebApiExceptions[T] (System.Threading.Tasks.Task`1[TResult] task) <0x26a43f8 + 0x00264> in <8c1e6df9d3f545cd831ff49915df2d85>:0 blazor.webassembly.js:1:32098
WASM: at BlazorCoreDMSTools.CommunicationService.CommunicationService.SetTokenAsync (System.String token, System.String database, System.String serverUri) <0x260dc60 + 0x00d9e> in <cb925648b50340888772566fbaeac465>:0
Just for some background, the Blazor team is in the process of significantly reducing the app's footprint, and resorting to some unusual measures to do so. In a nutshell, they've reduced it by about 20% by "wiping" HttpClientHandler.
wipe means "replace specified method bodies with a single throw
instruction". Doing this (instead of actually removing the method
entirely) means that the assembly retains a completely standard API
surface, and if you try to use one of the wiped methods, you get an
easy-to-understand exception stack trace that tells you which wiped
method you're trying to call.
This is what you've bumped up against: Blazor is still aware of HttpClientHandler for compilation purposes, but will throw a runtime exception if you (or in this case a compatible library) try to use it.
But HttpClient must wrap some implementation of HttpMessageHandler Blazor has its own: BrowserHttpMessageHandler. And Flurl provides an easy way to swap this in via its HttpClientFactory. But you don't need to pass in an HttpClient instance or implement CreateHttpClient. Instead, inherit from DefaultHttpClientFactory and just override CreateMessageHandler:
private class HttpClientFactoryForBlazor : DefaultHttpClientFactory
{
public override HttpMessageHandler CreateMessageHandler()
{
return new BrowserHttpMessageHandler();
}
}
I'd also recommend registering this once globally on app startup, rather than every time you create a FlurlClient:
FlurlHttp.Configure(settings =>
{
settings.HttpClientFactory = new HttpClientFactoryForBlazor();
});
It should also be noted that Blazor is still experimental and that BrowserHttpMessageHandler may be deprecated in a future release, so expect that this could be just a temporary work-around.
Currently in my 3.0 preview 5, BrowserHttpMessageHandler is not there anymore. Here is my current fix by simply not using any HttpMessageHandler. As far as I am aware, no problem happens to me yet, but I am not sure in all use cases:
class BlazorHttpClientFactory : DefaultHttpClientFactory
{
public override HttpClient CreateHttpClient(HttpMessageHandler handler)
{
return new HttpClient();
}
public override HttpMessageHandler CreateMessageHandler()
{
return null;
}
}
I'll start out with the questions first and follow up with context:
Is there a version of Unity.Interception available that is compatible with .NET Core?
Is there a .NET Core compatible alternative to Unity.Interception?
I am looking at using the Microsoft.Practices.Unity.InterceptionExtension.InterfaceInterceptor to short-circuit calls to certain interfaces (example code below), but it seems that the suggested NuGet package, Unity.Interception 4.0.1, is not compatible with .NET Core.
I have made an attempt to shoe-horn in the usage of Unity.Interception 4.0.1, as the code snippets used works fine in classic .NET; but as mentioned I am running into problems with .NET Core:
Install-Package : Package Unity.Interception 4.0.1 is not compatible with netcoreapp1.1 (.NETCoreApp,Version=v1.1). Package Unity.Interception 4.0.1 supports: net45 (.NETFramework,Version=v4.5
)
I tried to circumvent this by adding net451 to the PackageTargetFallback list:
<PackageTargetFallback>$(PackageTargetFallback);net451;dnxcore50;portable-net451+win8</PackageTargetFallback>
This allowed me to install the package, but it then complains something fierce about needing a reference to mscorlib:
Error CS0012
The type 'Type' is defined in an assembly that is not referenced. You must add a reference to assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
I'm not going to attempt to reference in the Classic .NET framework into a .NET Core application, so I'm pretty much at a dead end here.
Example code:
public class Interceptions
{
public static object CreateCustomInterceptedProxy(Type type)
{
var interceptor = new InterfaceInterceptor();
var proxy = interceptor.CreateProxy(type, null);
var interceptionBehavior = new CustomInterceptionBehavior();
proxy.AddInterceptionBehavior(interceptionBehavior);
return proxy;
}
}
public class CustomInterceptionBehavior : IInterceptionBehavior
{
public IMethodReturn Invoke(IMethodInvocation input, GetNextInterceptionBehaviorDelegate getNext)
{
object response = null; // replace with stuff that builds an actual object
return input.CreateMethodReturn(response, new object[] { });
}
public IEnumerable<Type> GetRequiredInterfaces()
{
return Type.EmptyTypes;
}
public bool WillExecute => true;
}
I know the question is for around a month ago, but I thought it might be useful for other developers as well (because It's been a nightmare for me).
I have forked out Unity project and ported that to .Net Core 2.0. You can find it under this repository:
https://github.com/Chavoshi/Unity.NetCore
And also these are the nuget packages:
https://www.nuget.org/packages/Unity.NetCore/
https://www.nuget.org/packages/Unity.Interception.NetCore/
P.S: The only part which I was not able to port is TransparentProxyInterception that uses .Net Remoting which is totally discontinued in .Net Core.
Unfortunately you have to use 3rd party libraries like:
Unity fork: https://www.nuget.org/packages/Unity.Interception.NetCore/
Dora Interception: https://www.nuget.org/packages/Dora.Interception/ it has a detailed usage documentation here.
It seems Castle.Core's DynamicProxy is what I needed:
using Castle.DynamicProxy;
public class CustomInterceptor : IInterceptor
{
public static object CreateCustomInterceptedProxy(Type type)
{
var proxyGenerator = new ProxyGenerator();
var interceptor = new Interceptor();
var proxy = proxyGenerator.CreateInterfaceProxyWithoutTarget(type, interceptor);
return proxy;
}
}
public class CustomInterceptor : IInterceptor
{
public void Intercept(IInvocation invocation)
{
object returnValue; // Do stuff to populate return value
invocation.ReturnValue = returnValue;
}
}
Here are the details of my Development Environment:
Visual Studio 2012 Ultimate with Update 4
Google Chrome Version 38.0.2125.111 m
Windows 7 Professional with 32-bit Operating System
Coded UITest Builder 11.0.60315.1
Our software team is creating an ASP.NET web application, and the customer has requested that we use Microsoft Visual Studio 2012 with Microsoft CodedUI to run automated tests.
I ran our ASP.NET application in Google Chrome Version 38.0.2125.111 m
I took steps to use the Microsoft CodedUI to record some Browser-user interaction steps on our ASP.NET application which ultimately led to generating some code.
The following is the generated code based on the recorded Brower-user interaction that I conducted on our ASP.NET Web Application
// ------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by coded UI test builder.
// Version: 11.0.0.0
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
// ------------------------------------------------------------------------------
namespace JigsawEMISTCodedUITestProject
{
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Drawing;
using System.Text.RegularExpressions;
using System.Windows.Input;
using Microsoft.VisualStudio.TestTools.UITest.Extension;
using Microsoft.VisualStudio.TestTools.UITesting;
using Microsoft.VisualStudio.TestTools.UITesting.WinControls;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Keyboard = Microsoft.VisualStudio.TestTools.UITesting.Keyboard;
using Mouse = Microsoft.VisualStudio.TestTools.UITesting.Mouse;
using MouseButtons = System.Windows.Forms.MouseButtons;
using Microsoft.VisualStudio.TestTools.UITesting.HtmlControls;
[GeneratedCode("Coded UITest Builder", "11.0.60315.1")]
public partial class UIMap
{
/// <summary>
/// RecordedMethod1
/// </summary>
public void RecordedMethod1()
{
#region Variable Declarations
WinClient uIChromeLegacyWindowClient = this.UIJigsawBetaEnviromentWindow.UIChromeLegacyWindowWindow.UIChromeLegacyWindowClient;
#endregion
// Click 'Chrome Legacy Window' client
Mouse.Click(uIChromeLegacyWindowClient, new Point(151, 25));
// Click 'Chrome Legacy Window' client
Mouse.Click(uIChromeLegacyWindowClient, new Point(150, 35));
// Click 'Chrome Legacy Window' client
Mouse.Click(uIChromeLegacyWindowClient, new Point(709, 90));
}
#region Properties
public UIJigsawBetaEnviromentWindow UIJigsawBetaEnviromentWindow
{
get
{
if ((this.mUIJigsawBetaEnviromentWindow == null))
{
this.mUIJigsawBetaEnviromentWindow = new UIJigsawBetaEnviromentWindow();
}
return this.mUIJigsawBetaEnviromentWindow;
}
}
#endregion
#region Fields
private UIJigsawBetaEnviromentWindow mUIJigsawBetaEnviromentWindow;
#endregion
}
[GeneratedCode("Coded UITest Builder", "11.0.60315.1")]
public class UIJigsawBetaEnviromentWindow : WinWindow
{
public UIJigsawBetaEnviromentWindow()
{
#region Search Criteria
this.SearchProperties[WinWindow.PropertyNames.Name] = "Jigsaw [Beta Enviroment] - Google Chrome";
// this.SearchProperties[WinWindow.PropertyNames.Name] = "Jigsaw";
this.SearchProperties[WinWindow.PropertyNames.ClassName] = "Chrome_WidgetWin_1";
// this.SearchProperties[WinWindow.PropertyNames.ClassName] = "Chrome";
this.WindowTitles.Add("Jigsaw [Beta Enviroment] - Google Chrome");
// this.WindowTitles.Add("Jigsaw");
#endregion
}
#region Properties
public UIChromeLegacyWindowWindow UIChromeLegacyWindowWindow
{
get
{
if ((this.mUIChromeLegacyWindowWindow == null))
{
this.mUIChromeLegacyWindowWindow = new UIChromeLegacyWindowWindow(this);
}
return this.mUIChromeLegacyWindowWindow;
}
}
#endregion
#region Fields
private UIChromeLegacyWindowWindow mUIChromeLegacyWindowWindow;
#endregion
}
[GeneratedCode("Coded UITest Builder", "11.0.60315.1")]
public class UIChromeLegacyWindowWindow : WinWindow
{
public UIChromeLegacyWindowWindow(UITestControl searchLimitContainer) :
base(searchLimitContainer)
{
#region Search Criteria
this.SearchProperties[WinWindow.PropertyNames.ControlId] = "144212160";
this.WindowTitles.Add("Jigsaw [Beta Enviroment] - Google Chrome");
// this.WindowTitles.Add("Jigsaw");
#endregion
}
#region Properties
public WinClient UIChromeLegacyWindowClient
{
get
{
if ((this.mUIChromeLegacyWindowClient == null))
{
this.mUIChromeLegacyWindowClient = new WinClient(this);
#region Search Criteria
this.mUIChromeLegacyWindowClient.SearchProperties[WinControl.PropertyNames.Name] = "Chrome Legacy Window";
// this.mUIChromeLegacyWindowClient.SearchProperties[WinControl.PropertyNames.Name] = "Chrome";
this.mUIChromeLegacyWindowClient.WindowTitles.Add("Jigsaw [Beta Enviroment] - Google Chrome");
// this.mUIChromeLegacyWindowClient.WindowTitles.Add("Jigsaw");
#endregion
}
return this.mUIChromeLegacyWindowClient;
}
}
#endregion
#region Fields
private WinClient mUIChromeLegacyWindowClient;
#endregion
}
}
Microsoft CodedUI is throwing Error because it fails to see 'Chrome Legacy Window'
I ran the code, but I get the following Error:
Microsoft.VisualStudio.TestTools.UITest.Extension.UITestControlNotFoundException was unhandled by user code
HResult=-268111872
Message=The playback failed to find the control with the given search properties. Additional Details:
TechnologyName: 'MSAA'
ControlType: 'Client'
Name: 'Chrome Legacy Window'
Source=Microsoft.VisualStudio.TestTools.UITesting
BasicMessage=The playback failed to find the control with the given search properties.
RootElement=""
StackTrace:
at Microsoft.VisualStudio.TestTools.UITesting.Playback.MapControlNotFoundException (COMException ex, IPlaybackContext context)
at Microsoft.VisualStudio.TestTools.UITesting.Playback.MapAndThrowComException (COMException innerException, IPlaybackContext context)
at Microsoft.VisualStudio.TestTools.UITesting.Playback.MapAndThrowException (SystemException exception, IPlaybackContext context)
at Microsoft.VisualStudio.TestTools.UITesting.Playback.MapAndThrowException (SystemException exception, String queryId)
at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.FindFirstDescendant (String queryId, Int32 maxDepth, Int32& timeLeft)
at Microsoft.VisualStudio.TestTools.UITesting.SearchHelper.GetElement(Boolean useCache, ISearchArgument searchArg)
at Microsoft.VisualStudio.TestTools.UITesting.SearchHelper.Search (ISearchArgument searchArg)
at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.FindInternal()
at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.FindPrivate()
at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.<Find>b__d()
at Microsoft.VisualStudio.TestTools.UITesting.CodedUITestMethodInvoker.InvokeMethod[T](Func`1 function, UITestControl control, Boolean firePlaybackErrorEvent, Boolean logAsAction)
at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.Find()
at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.GetPropertyPrivate (String propertyName)
at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.<>c__DisplayClass11.<GetProperty>b __10()
at Microsoft.VisualStudio.TestTools.UITesting.CodedUITestMethodInvoker.InvokeMethod[T](Func`1 function, UITestControl control, Boolean firePlaybackErrorEvent, Boolean logAsAction)
at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.GetProperty(String propertyName)
at Microsoft.VisualStudio.TestTools.UITesting.ALUtility.GetTechElementFromUITestControl (UITestControl uiTestControl)
at Microsoft.VisualStudio.TestTools.UITesting.ActionExecutorManager.GetActionExecutor (UITestControl uiControl)
at Microsoft.VisualStudio.TestTools.UITesting.Mouse.ClickImplementation (UITestControl control, MouseButtons button, ModifierKeys modifierKeys, Point relativeCoordinate)
at Microsoft.VisualStudio.TestTools.UITesting.Mouse.<>c__DisplayClass6.<Click>b__5()
at Microsoft.VisualStudio.TestTools.UITesting.CodedUITestMethodInvoker.InvokeMethod[T](Func`1 function, UITestControl control, Boolean firePlaybackErrorEvent, Boolean logAsAction)
at Microsoft.VisualStudio.TestTools.UITesting.Mouse.Click(UITestControl control, MouseButtons button, ModifierKeys modifierKeys, Point relativeCoordinate)
at Microsoft.VisualStudio.TestTools.UITesting.Mouse.Click(UITestControl control, Point relativeCoordinate)
at JigsawEMISTCodedUITestProject.UIMap.RecordedMethod1() in d:\EMIS\JigsawEMISTCodedUITestProject\JigsawEMISTCodedUITestProject\UIMap.cs:line 42
at JigsawEMISTCodedUITestProject.CodedUITest1.CodedUITestMethod1() in d:\EMIS\JigsawEMISTCodedUITestProject\JigsawEMISTCodedUITestProject\CodedUITest1.cs:line 30
InnerException: System.Runtime.InteropServices.COMException
HResult=-2147467259
Message=Error HRESULT E_FAIL has been returned from a call to a COM component.
Source=Microsoft.VisualStudio.TestTools.UITest.Playback
ErrorCode=-2147467259
StackTrace:
at Microsoft.VisualStudio.TestTools.UITest.Playback.Engine.IScreenElement.FindAllDescendants (String bstrQueryId, Object& pvarResKeys, Int32 cResKeys, Int32 nMaxDepth)
at Microsoft.VisualStudio.TestTools.UITest.Playback.ScreenElement.FindAllScreenElement(String queryId, Int32 depth, Boolean singleQueryId, Boolean throwException, Boolean resetSkipStep)
at Microsoft.VisualStudio.TestTools.UITest.Playback.ScreenElement.FindScreenElement(String queryId, Int32 depth, Boolean resetSkipStep)
at Microsoft.VisualStudio.TestTools.UITest.Playback.ScreenElement.FindScreenElement(String queryId, Int32 depth)
at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.FindFirstDescendant(String queryId, Int32 maxDepth, Int32& timeLeft)
InnerException:
Do I need to install some drivers for popular browsers ( i.e Google Chrome, Mozilla Firefox, IE, etc.) ?
I restarted my development computer a couple times, but still have same problem.
Please help me.
There's actually a Selenium framework that was ported to run with Coded UI by a developer at Microsoft, which you can find here, that will use the Selenium components to run the tests in Chrome or Firefox. IE is handled by the Coded UI itself, so if your BrowserWindow.BrowserType is "IE", then it'll just run the vanilla Coded UI that's shipped with your Visual Studio.
The Q&A section of that page is where you'll find the most support for questions about the tool itself, but if you have trouble getting started, this blog was very helpful.
http://www.asp.net/signalr/overview/signalr-20/getting-started-with-signalr-20/tutorial-signalr-20-self-host
In my case, my hubs are in a project referenced from the project code that spins up the self-hosted application.
On the line connection.Start().Wait(); I get an exception. The following is the sequence of exceptions thrown at that line:
The specified registry key does not exist System.IO.IOException
'MessageHub' Hub could not be resolved InvalidOperationException
The remote server returned an error: (500) Internal Server Error WebException
The signature of the message hub class in the referenced project is public class MessageHub : Hub.
Update: To test the theory, I moved the hub class from the referenced project into my test project and updated the namespace. It worked. So I think the theory here is sound... default hub resolution does not find hubs in referenced project or in separate namespace.
How can I convince MapHubs to find the test hub in the referenced project?
I think that I have found an answer to this.
After doing some digging around the source code it seems that SignalR uses the following method to designate an IAssemblyLocator to locate Hubs.
internal static RouteBase MapHubs(this RouteCollection routes, string name, string path, HubConfiguration configuration, Action<IAppBuilder> build)
{
var locator = new Lazy<IAssemblyLocator>(() => new BuildManagerAssemblyLocator());
configuration.Resolver.Register(typeof(IAssemblyLocator), () => locator.Value);
InitializeProtectedData(configuration);
return routes.MapOwinPath(name, path, map =>
{
build(map);
map.MapHubs(String.Empty, configuration);
});
}
public class BuildManagerAssemblyLocator : DefaultAssemblyLocator
{
public override IList<Assembly> GetAssemblies()
{
return BuildManager.GetReferencedAssemblies().Cast<Assembly>().ToList();
}
}
public class DefaultAssemblyLocator : IAssemblyLocator
{
public virtual IList<Assembly> GetAssemblies()
{
return AppDomain.CurrentDomain.GetAssemblies();
}
}
This got me to try to simply add my external assembly to current domain because although it was referenced it was not being loaded.
So before calling WebApp.Start I call the following line.
static void Main(string[] args)
{
string url = "http://localhost:8080";
// Add this line
AppDomain.CurrentDomain.Load(typeof(Core.Chat).Assembly.FullName);
using (WebApp.Start<Startup>(url))
{
Console.WriteLine("Server running on {0}", url);
Console.ReadLine();
}
}
Where Core.Chat is simply the Hub class I'm using.
And then the hubs defined in referenced assembly are loaded.
There might be a more straight forward way to go about this but I could not find anything in the documentation.
Hope this helps.
I have configured Ninject 2 in an ASP.NET 4.0 project (not MVC) however when I deploy the project to an IIS host it crashes with the following:
System.NullReferenceException: Object reference not set to an instance of an object.
[NullReferenceException: Object reference not set to an instance of an object.]
System.Web.PipelineModuleStepContainer.GetEventCount(RequestNotification notification, Boolean isPostEvent) +30
System.Web.PipelineStepManager.ResumeSteps(Exception error) +1481
System.Web.HttpApplication.BeginProcessRequestNotification(HttpContext context, AsyncCallback cb) +132
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +709
I have tested this again with a vanilla ASP.net Web Application and get the same crash with the following code:
protected override IKernel CreateKernel()
{
return Container;
}
private IKernel Container
{
get
{
IKernel kernel = new StandardKernel(new SiteModule());
var module = new OnePerRequestModule();
module.Init(this);
return kernel;
}
}
Has anyone else got Ninject working with ASP.net 4?
[UPDATE: 2010.11.03]
After doing some research it appears it may be something to do with the OnePerRequestModule() module, removing this however doesn't seem to resolve the problem I added it due at the suggestion of this question.
In Ninject 2, you use the Ninject.Web extension (see the complete set here) and dont do any explicit config as you have here around OnePerRequestModule etc.
You don't do any web.config stuff either IIRC (I'm using the MVC one and you don't there)