Creating console MonoMac application - monomac

I need to create a console MonoMac application.
Open Xamarin Studio and create C# console application project (not MonoMac specific).
Add reference to MonoMac assembly.
Edit Main method in Program.cs:
using System;
using MonoMac.Foundation;
namespace ConsoleTest
{
class MainClass
{
public static void Main(string[] args)
{
Console.WriteLine(new NSString("Hello World!"));
}
}
}
The project builds ok. But when I run it the console opens with error:
Missing method .ctor in assembly /.../ConsoleTest.exe, type MonoMac.Foundation.NSString
So the console project runs on Mac, but MonoMac assembly cannot be used. How to fix it?

Solved.
MonoMac should be compiled from sources:
Clone https://github.com/mono/monomac (including submodules).
Open terminal and run "make" in the root folder.
Find MonoMac.dll in src folder and copy it to your project directory.
Reference it directly (don't use the version bundled with Xamarin Studio).
One thing I also tried is to run NSApplication.Init() when starting the app. It seems a working solution too.

Related

Add service from another dll of another solution

We use ServiceStack 5.9.2 and have a ready, running application build with Visual Studio. Is it possible to add additional services to this application which were build in another Visual Studio solution? It provides a DLL which could be copied to the Exe of the host application. The application would have to detect the services in the copied dll on startup.
Just read
https://docs.servicestack.net/modularizing-services#modularizing-services-in-multiple-assemblies
but I'am not sure if that is possible/ allowed.
The AppHost supports wiring up Services from multiple .dll's so you can register services in an external .dll by adding the assembly to your AppHost's base constructor:
public class AppHost : AppHostBase
{
public AppHost()
: base("App",typeof(MyServices).Assembly,typeof(ServiceInExtDll).Assembly){}
public override void Configure(Container container) {}
}

Error System.BadImageFormatException service fabric

Problem
I am building service fabric application. When I create a Project and run it its working fine. but when I inject a service in the Api controller it gives me this error I tried to resolved it but not succeeded yet.
Error
System.BadImageFormatException
Could not load file or assembly 'dotnet-aspnet-codegenerator-design' or one of its dependencies. An attempt was made to load a program with an incorrect format.
Image
I add the service
protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners()
{
return new ServiceInstanceListener[]
{
new ServiceInstanceListener(serviceContext =>
new KestrelCommunicationListener(serviceContext, "ServiceEndpoint", (url, listener) =>
{
ServiceEventSource.Current.ServiceMessage(serviceContext, $"Starting Kestrel on {url}");
return new WebHostBuilder()
.UseKestrel()
.ConfigureServices(
services => services
.AddSingleton<StatelessServiceContext>(serviceContext)
.AddScoped(typeof(ISendMessage), typeof(SendMessage))
)
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
.UseServiceFabricIntegration(listener, ServiceFabricIntegrationOptions.None)
.UseUrls(url)
.Build();
}))
};
}
It is likely that your service or any of their dependencies is targeting a x86 platform.
To fix that, you have to force your service running on x64 and/or replace any x86 dependencies for x64.
If your are running dotnet-core, make sure the x64 tools are installed as well.
You might also try removing the reference to Microsoft.VisualStudio.Web.CodeGeneration.Design from your project as mentioned here
These SO questions might give you more information:
service fabric system badimageformatexception
badimageformatexception when migrating from aspnet core 1.1 to
2.0
This was an issue we faced sometime ago, It comes when you try to add asp.net core controller. For some reason visual studio adds the reference to "Microsoft.VisualStudio.Web.CodeGeneration.Design".
My sugegstion would be to remove the reference and also not add controller using the Project->Add->Controller.
Just add a basic code file and copy the content from an earlier controller.
Add more binaries for the package, and do AnyCPU for the platform target.
<PackageId>Microsoft.VisualStudio.Web.CodeGeneration.Design</PackageId>
<RuntimeIdentifier Condition=" '$(TargetFramework)' != 'netcoreapp2.0' ">win7-x86</RuntimeIdentifier>
<RuntimeIdentifier Condition=" '$(TargetFramework)' != 'netcoreapp2.0' ">win7-x64</RuntimeIdentifier>
To fix it, simply follow the steps below:
open project properties window.
select Build tab
Change it to ‘Any CPU’
Save your changes.
Compile your project and run
From source here
Edit 1:
Service febric targets x64 bit then Click the Platform dropdown and choose New, then create an x64 platform configuration.

Xamarin.ios using DLL library

I have xamarin binding project (represents kind of bridge to native iOS static library) which works fine if added to a solution.
What I'm trying to do is to use /bin/libary.dll instead of binding project.
I created new xamarin.ios simple view project, added reference to library.dll.
Project compiles fine using API from that library but when run i'm getting fatal error:
so there is no even entry point to application
sorry probably for posting obvioues answer, but I need to get it working fast.

How does dalvikvm understand the starting point of android application

I can successfully run a simple java program in dalvikvm by converting the java class into dex file. But when I try to run android application by converting its class files into dex, it says static main(String args[]) not found.
Android application does not contain static main() method.
So where does dalvikvm start executing an android application or how does it find the static main() method in android application???
Android determines your app's entry point based on the AndroidManifest.xml shipped with your app. Specifically, Android determines which intent was sent to the app (to cause it to launch), and will instantiate the appropriate Activity and call its onCreate method. This creation process is overseen by a wrapper process called app_process, which calls into dalvik directly and sets up the app execution environment.
Dalvik itself behaves like a normal Java JVM in most regards; therefore, running a jar or dex with Dalvik will still expect a main method, as with normal Java.

Problem loading Assemblies in MonoTouch Project

I am building a Monotouch (trial) 4.0.3. project. It compiles with the warning:
Warning: Library 'loader.dll' missing in app bundle, cannot extract content
All of the other dlls are successfully bundled during build, and this one was working before. After compiling with the warning, it crashes on load at runtime (on the simulator) with a segmentation fault when it fails to load the assembly.
I have searched for this warning and I haven't been able to find any references to it.
Does anyone know why the assembly is not being added to the app package?
It sounds like the linker is removing the loader.dll because it thinks nothing uses it. Try setting the project's linker setting to "link sdk only".
mhutch is correct, the linker is opportunistically pruning out the library. However, the default linker setting is not to link anything, so his solution will only work in the rare case that you're linking all assemblies (which you don't want to do with MonoTouch because references to the SDK should never be embedded).
The workaround is to just new up an instance of something in the library you want to use, from inside the calling assembly.
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using MyLibrary;
namespace MyApp
{
public class Application
{
static void Main(string [] args)
{
new MyLibrary.DontPruneMeBro();
UIApplication.Main(args, null, "AppDelegate");
}
}
}
As an aside, I don't know what iOS developers do, since this behavior would make run-time access to satellite libraries impossible.

Resources