Quantcast
Channel: Xamarin.Mac — Xamarin Community Forums
Viewing all 1429 articles
Browse latest View live

Getting domain Name in xamarin.mac

$
0
0

hi,

i am not able to fetch the domain name in xamarin as i would in windows. please help.
i tried the below options with no luck:

var domainname = new System.Text.StringBuilder(256);
Mono.Unix.Native.Syscall.getdomainname(domainname,
(ulong)domainname.Capacity);

string domainname=System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties().DomainName;


How to resolve 'Could not load file or assembly ...

$
0
0

Hi

This question seem to pop often in the forum without any relevant answer. (at least I didn't find any to solve my problem)

I had a working mac app with legacy target + framework 4.7 libraries.

Now I'm trying to switch to a Mac app with the 'modern' target. So I migrated all my libraries to 'netstandard 2.0'.

I tried to cleans, manual deletes of obj/ and recreated my project from zero and copy my code into it.

I always get this error:

Loaded assembly: /c#/ExpenseLogMac/ExpenseLogMac/bin/Debug/Expense Log.app/Contents/MonoBundle/Expense Log.exe
Loaded assembly: /c#/ExpenseLogMac/ExpenseLogMac/bin/Debug/Expense Log.app/Contents/MonoBundle/MultiOSFileLoader.dll
Loaded assembly: /c#/ExpenseLogMac/ExpenseLogMac/bin/Debug/Expense Log.app/Contents/MonoBundle/netstandard.dll [External]
Loaded assembly: /c#/ExpenseLogMac/ExpenseLogMac/bin/Debug/Expense Log.app/Contents/MonoBundle/ExpenseCore.dll
Loaded assembly: /c#/ExpenseLogMac/ExpenseLogMac/bin/Debug/Expense Log.app/Contents/MonoBundle/Xamarin.Mac.dll [External]

Unhandled Exception:
System.TypeLoadException: Could not load type of field 'ExpenseCore.Db:dbConnection' (1) due to: Could not load file or assembly 'SQLiteNetStandard, Version=1.5.1.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. assembly:SQLiteNetStandard, Version=1.5.1.0, Culture=neutral, PublicKeyToken=null type:<unknown type> member:<none>
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeLoadException: Could not load type of field 'ExpenseCore.Db:dbConnection' (1) due to: Could not load file or assembly 'SQLiteNetStandard, Version=1.5.1.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. assembly:SQLiteNetStandard, Version=1.5.1.0, Culture=neutral, PublicKeyToken=null type:<unknown type> member:<none>

If I compile a command line app, all is working fine. I'm not sure how I can resolve or understand this error.

Config: Visual Studio mac

Pkcs11Interop Xamarin.Mac crash

$
0
0

Hi.

I'm trying to create a Xamarin.Mac application using the Pkcs11Interop library. First I created the Cocoa app then created .NetStandart lib and imported the NuGet package Pkcs11Interop there.
But when I tried to use the library with the imported nuget package, I get an error:

Here is the code of the test library:
using System;
using Net.Pkcs11Interop.Common;
using Net.Pkcs11Interop.HighLevelAPI80;

namespace ReaderLib
{
    public class Initialize
    {
        public Initialize()
        {
            Pkcs11 pkcs11 = new Pkcs11("/usr/local/lib/libbeidpkcs11.dylib", AppType.MultiThreaded);
        }
    }
}

Code ViewController
using System;

using AppKit;
using Foundation;
using ReaderLib;

namespace IDReader
{
    public partial class ViewController : NSViewController
    {
        public ViewController(IntPtr handle) : base(handle)
        {
        }

        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            Initialize class1 = new Initialize();
        }

        public override NSObject RepresentedObject
        {
            get
            {
                return base.RepresentedObject;
            }
            set
            {
                base.RepresentedObject = value;
                // Update the view, if already loaded.
            }
        }
    }
}

Pkcs11Interop in Xamarin

$
0
0

Hello, this is my first try with Xamarin, I'm trying to ma use the "Pkcs11Interop" library with an example code (code at the end). But i can't figure how to make it work because it gives me these two errors "The name 'Settings' does not exist in the current context" and "The name 'Helpers' does not exist in the current context".

Thanks in advance for the help :)

/*
 *  Pkcs11Interop - Managed .NET wrapper for unmanaged PKCS#11 libraries
 *  Copyright (c) 2012-2015 JWC s.r.o. <http://www.jwc.sk>
 *  Author: Jaroslav Imrich <jimrich@jimrich.sk>
 *
 *  Licensing for open source projects:
 *  Pkcs11Interop is available under the terms of the GNU Affero General
 *  Public License version 3 as published by the Free Software Foundation.
 *  Please see <http://www.gnu.org/licenses/agpl-3.0.html> for more details.
 *
 *  Licensing for other types of projects:
 *  Pkcs11Interop is available under the terms of flexible commercial license.
 *  Please contact JWC s.r.o. at <info@pkcs11interop.net> for more details.
 */
using System.IO;
using Net.Pkcs11Interop.Common;
using Net.Pkcs11Interop.HighLevelAPI;
using NUnit.Framework;
namespace Net.Pkcs11Interop.Tests.HighLevelAPI
{
    [TestFixture()]
    public class _20_SignAndVerifyTest
    {
        [Test()]
        public void _01_SignAndVerifySinglePartTest()
        {
            using (Pkcs11 pkcs11 = new Pkcs11(Settings.Pkcs11LibraryPath, false))
            {
                // Find first slot with token present
                Slot slot = Helpers.GetUsableSlot(pkcs11);

                // Open RW session
                using (Session session = slot.OpenSession(false))
                {
                    // Login as normal user
                    session.Login(CKU.CKU_USER, Settings.NormalUserPin);

                    // Generate key pair
                    ObjectHandle publicKey = null;
                    ObjectHandle privateKey = null;
                    Helpers.GenerateKeyPair(session, out publicKey, out privateKey);

                    // Specify signing mechanism
                    Mechanism mechanism = new Mechanism(CKM.CKM_SHA1_RSA_PKCS);

                    byte[] sourceData = ConvertUtils.Utf8StringToBytes("Hello world");
                    // Sign data
                    byte[] signature = session.Sign(mechanism, privateKey, sourceData);
                    // Do something interesting with signature
                    // Verify signature
                    bool isValid = false;
                    session.Verify(mechanism, publicKey, sourceData, signature, out isValid);
                    // Do something interesting with verification result
                    Assert.IsTrue(isValid);
                    session.DestroyObject(privateKey);
                    session.DestroyObject(publicKey);
                    session.Logout();
                }
            }
        }
    }
}

Linker command failed with exit code 1 (use -v for more details)

$
0
0

Hi

I add .NetStandart lib project in my default Xamarin.Mac solutuion. Then i add Pkcs11Interop nuget package to .NetStandart lib.
the discussion about:
https://github.com/Pkcs11Interop/Pkcs11Interop/issues/65

When i start to build project i geves an error messages:

Log:

    MMP : warning MM2006: Native library 'libdl' was referenced but could not be found.
        /Library/Frameworks/Mono.framework/Commands/pkg-config --cflags mono-2
        -D_THREAD_SAFE -I/Library/Frameworks/Xamarin.Mac.framework/Versions/4.0.0.216/lib/pkgconfig/../../include/mono-2.0

        /Library/Frameworks/Mono.framework/Commands/pkg-config --variable=libdir mono-2
        /Library/Frameworks/Xamarin.Mac.framework/Versions/4.0.0.216/lib/pkgconfig/../../lib

        /Library/Frameworks/Mono.framework/Commands/pkg-config --modversion mono-2
        5.4.0
    xcrun -sdk macosx clang -g -mmacosx-version-min=10.12 -arch x86_64 -fobjc-runtime=macosx -Wno-unguarded-availability-new -ObjC -framework CoreFoundation -framework Security -framework CoreServices -framework AppKit -framework CoreVideo -framework Foundation -framework Carbon -framework OpenGL -framework CloudKit -framework QuartzCore -u xamarin_timezone_get_data -u xamarin_get_block_descriptor -u C_Initialize -u C_Finalize -u C_GetInfo -u C_GetFunctionList -u C_GetSlotList -u C_GetSlotInfo -u C_GetTokenInfo -u C_GetMechanismList -u C_GetMechanismInfo -u C_InitToken -u C_InitPIN -u C_SetPIN -u C_OpenSession -u C_CloseSession -u C_CloseAllSessions -u C_GetSessionInfo -u C_GetOperationState -u C_SetOperationState -u C_Login -u C_Logout -u C_CreateObject -u C_CopyObject -u C_DestroyObject -u C_GetObjectSize -u C_GetAttributeValue -u C_SetAttributeValue -u C_FindObjectsInit -u C_FindObjects -u C_FindObjectsFinal -u C_EncryptInit -u C_Encrypt -u C_EncryptUpdate -u C_EncryptFinal -u C_DecryptInit -u C_Decrypt -u C_DecryptUpdate -u C_DecryptFinal -u C_DigestInit -u C_Digest -u C_DigestUpdate -u C_DigestKey -u C_DigestFinal -u C_SignInit -u C_Sign -u C_SignUpdate -u C_SignFinal -u C_SignRecoverInit -u C_SignRecover -u C_VerifyInit -u C_Verify -u C_VerifyUpdate -u C_VerifyFinal -u C_VerifyRecoverInit -u C_VerifyRecover -u C_DigestEncryptUpdate -u C_DecryptDigestUpdate -u C_SignEncryptUpdate -u C_DecryptVerifyUpdate -u C_GenerateKey -u C_GenerateKeyPair -u C_WrapKey -u C_UnwrapKey -u C_DeriveKey -u C_SeedRandom -u C_GenerateRandom -u C_GetFunctionStatus -u C_CancelFunction -u C_WaitForSlotEvent -u mono_pmip -u xamarin_dyn_objc_msgSend -u xamarin_dyn_objc_msgSendSuper -u xamarin_dyn_objc_msgSend_stret -u _xamarin_dyn_objc_msgSendSuper_stret /Library/Frameworks/Xamarin.Mac.framework/Versions/4.0.0.216/lib/libxammac-debug.a -o /Users/fezz/Documents/Projects/IDReader/IDReader/bin/Debug/IDReader.app/Contents/MacOS/IDReader -D_THREAD_SAFE -I/Library/Frameworks/Xamarin.Mac.framework/Versions/4.0.0.216/lib/pkgconfig/../../include/mono-2.0   /Library/Frameworks/Xamarin.Mac.framework/Versions/4.0.0.216/lib/pkgconfig/../../lib/libmonosgen-2.0.a -liconv -x objective-c++ -I/Library/Frameworks/Xamarin.Mac.framework/Versions/4.0.0.216/include -fno-caret-diagnostics -fno-diagnostics-fixit-info -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk /Users/fezz/Documents/Projects/IDReader/IDReader/obj/x86/Debug/mmp-cache/main.m
Process exited with code 1, command:
    Undefined symbols for architecture x86_64

Steps to reproduce:

  1. Create Cocoa App
  2. Add .NetStandart library in solution
  3. Add nuget package Pkcs11Interop to the .NetStandart library
  4. Try to use this test code in library:

    using (Pkcs11 pkcs = new Pkcs11("libPath", AppType.MultiThread))
    {

    }

  5. Copy lib Pkcs11Interop.NetStandart.dll and Pkcs11Interop.NetStandart.xml files (took them from the nuget package) in /LibName/bin/Debug/netstandart2.0.

Or you can simply add nuget Package in Xamarin.Mac project

Casting a Task> to an NSMutableArray

$
0
0

I'm new to Mac coding and am creating a MacOS Cocoa App and PCL model project, using SQLite-net-pcl. I've implemented KVC but am now facing the challenge of getting an NSMutableArray for binding to the Xcode TableView object.

Is there a specific method in Xamarin for converting a C# List<> to an NSMutableArray? Or am I looking at this the wrong way?

My design:

  • PCL project with table model class(es)
  • Cocoa App project with Table View Controller and KVC mapping (including NSMutableArray and NSArray in a ViewModel class)
  • SQLite-net-pcl package to query database and return List

<

table class>

Open and Close Window Programmatically Xamarin.Mac

$
0
0

Hi.

I think this is a simple question, but I have not found the answer to it.
How can I open other windows of my application from the ViewController code?
How can I close the current window from the ViewController code?

any help plz to install VS on Mac ?!

$
0
0

about 4 days now trying to solve it :(
plz I need it urgent

every time I got that message:

**Initial task interrupted by exception
Message: Access to the path "/Users/Nemo/.config/xbuild" is denied.
Exception type: System.UnauthorizedAccessException

at Xamarin.Web.Installer.TasksManager.DetectComponents () [0x00097] in /Users/builder/data/lanes/5758/e32e17ec/source/installer/Xamarin.Web.Installer/TasksManager.cs:297**


Invalid IL Code

$
0
0

Hi All,
What would cause me to get exceptions like this?

Invalid IL code in (wrapper dynamic-method) object:lambda_method (System.Runtime.CompilerServices.Closure,MC.Clio.TemporaryDocumentStorage): method body is empty.

I'm getting an error when trying to run a blank android app on Visual Studio Xamarin on Mac.

$
0
0

The error and the warning I get are :
Failed to get the java SDK version.Found java version 9.0.4
"javac"exited with code 2 .(MSB6006)

I hava Java 8 SDK installed

How do I add an app icon to the home screen on install?

$
0
0

I created a macOs app, but when i install my generated .pkg file I can not choose to have the application icon appear on the desktop. And my application also does not fit in the Application folder
How can I do this?

Any CPU ?

$
0
0

In Visual Studio for Mac I can choose these Platform targets:

What in meant by "Any CPU" ? (Do I get an app compiled for x86, x64 or Itanium ?)

Best
Eigil

Xamarin.Mac signal handling

$
0
0

Hi,

I'd like to manage Signals, so the application does not just crash and leave users in the dark. I've been looking at PLCrashReporter which seems to do what I'd want, with one issue. As pointed here, that prevents NullReferenceExceptions from being correctly handled (and other for what I've tested).

So I've followed the instruction and wrapped my EnableCrashReporter with Mono.Runtime.RemoveSignalHandlers and Mono.Runtime.InstallSignalHandlers. Which restore the wanted behavior (NullReferenceException now being handled). But PLCrashReporter does not appear to catch anything, at all. It's not just the signal that mono handles, it's even those that do end in a crash regardless, even if I raise a SIGSEGV in manage code myself or trigger a SIGFPE in native code.

I have to be frank and admit that I'm far from experience when it come to signal handling, so I might be missing something. But looking at this quote:

Since Mono’s signal handlers are reinstalled and not restored, Mono will now chain to the signal handlers installed by EnableCrashReporting.

I'd have though that when registering it's own signal handler, Mono would keep the previously installed one (in this case PLCrashReporter one) and call it when it sees nothing to do with the signal. Which is also what this line seems to suggest:

[...], because Mono will chain to the previous handler if it detects that a SIGSEGV occurred in native code, and the existing signal handlers when Mono installed its signal handlers would be the default signal handlers for the platform.

Any idea?

How to Intercept MouseDown() on NSText

$
0
0

I'm running into a problem trying to intercept MouseDown() events for NSTextField. I've created a custom text field that extends NSTextField, and the first MouseDown() call gets intercepted correctly, but it seems that the NSTextField creates an NSText object that becomes the first responder. From that point on, the text field's MouseDown() is not called when it is clicked.

Is there any way to create a custom NSText object when an NSTextField gets clicked, or is there another method within NSTextField that I can override to detect mouse clicks?

Thanks!

2 different app icons and I can´t figure out how to change it

$
0
0

Hello everyone,

I have a problem with the icons on a mac monogame app.
If I do everything that´s listed in the guide(https://developer.xamarin.com/guides/mac/deployment,_testing,_and_metrics/app-icon/) my custom icon is shown while the app is loading which means that it jumps up and down in the dock.
As soon as the app has finished loading the icon changes to the monogame-icon (red M). I just can´t figure out how to change that.
What´s really strange is that the monogame-icon isn´t listed anywhere in the project. I tried to create a clean monogame project because I thought there´s something messed up in my project but it´s the same. Two icons and xcassets just changes the first one.
Am I missing something?

Thank you for your help,

Harry


Objective-c code to c# ( using system libraries)

Objective C binding

$
0
0

I created a project that need to bind one third party library with my Xamarin Mac application. I used objective sharpie for creating ApiDefinitions and StructsAndEnums. But when i add .a using native references to binding application it won't create the linking .cs file. Also when a build the binding application i got an error "No api definition file specified". Please help me to resolve this issue.

Getting System.InvalidCastException while loading View from a xib file

$
0
0

I have a xib file - LoaderView.xib and associated class LoaderView.cs which contains a view for showing loading text. When I try to load it in the main ViewController as -

public override void ViewDidAppear()
{
   base.ViewDidAppear();

   NSBundle.MainBundle.LoadNibNamed("LoaderView", this, out NSArray arr);
   var view = Runtime.GetNSObject<LoaderView>(arr.ValueAt(0));
   view.Frame = View.Frame;
   View.AddSubview(view);
}

I am getting the System.InvalidCastException in this line -

var view = Runtime.GetNSObject<LoaderView>(arr.ValueAt(0));

And the strange part is I do not get the exception every time. When it works, I am seeing the loading text overlapped with default view - associated with the ViewController.

Can someone point out what is the best way to show Loading, Error and Empty states. Should I have separate ViewControllers for them? Or Can I have separate xib files which I can load/unload from the main View Controller? How to load a view from a xib file?

Unsubscribing from NSWorkspace.Notifications events

$
0
0

I can subscribe to NSWorkspace.Notifications like so:

_processStartedToken = NSWorkspace.Notifications.ObserveDidLaunchApplication((sender, e) =>
{
if (_processName == e.Application.BundleIdentifier)
ProcessStarted?.Invoke(e.Application.ProcessIdentifier);
});

but how can I unsubscribe from it?

I tried:
NSNotificationCenter.DefaultCenter.RemoveObserver(_processStartedToken);

but it did not work.

Thanks!

how to initiate gui to user from root process in Xamarin.mac

$
0
0

if there a way to launch process with with gui from root process without asking for any credentials any help would be appreciated. please reply soon. thank you.

Viewing all 1429 articles
Browse latest View live