question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature: Offer CoreCLR-compatible portable library

See original GitHub issue

As discussed in #874:

I’m willing to take a look at converting libgit2sharp to a portable library that can run on CoreCLR. My exploration is in the portable branch of my fork.

I’d like an active issue to track this exploration where I can share ideas for making this work with the project owners, and verify owners’ willingness to ultimately accept a PR when the work is done.

Work ongoing in PR #1318

Issue Proposal/Resolution
Maintain net40 compatibility Maintain the net40 targeted class library. Move source code to a Shared Project and add a Portable library project to add support for net45 genre portable library
Serializable exceptions Put #if blocks around desktop-only serializable support
ICustomMarshaler CoreCLR does not support this attribute. Replace all uses with thunking method wrappers. Keep tax and extra code very low by leveraging code gen during build, the way the PInvoke project does.
ReliabilityContract Put #if blocks around these
X509Certificate Offered via a corefx nuget package
SecureString Offered via corefx NuGet package
BufferedStream Cheap portable imitation
CriticalFinalizerObject Put #if around base class declaration
Environment.OSVersion #if Desktop keep, #else use CoreCLR RuntimeInformation
Trace Put #ifblocks around these

Code generation design

The p/invoke signature that is hand-written changes from this:

[DllImport(libgit2)]
internal static extern unsafe int git_blob_create_fromchunks(
    ref GitOid oid,
    git_repository* repositoryPtr,
    [MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictFilePathMarshaler))] FilePath hintpath,
    source_callback fileCallback,
    IntPtr data);

To this:

[DllImport(libgit2)]
internal static extern unsafe int git_blob_create_fromchunks(
    ref GitOid oid,
    git_repository* repositoryPtr,
    [CustomMarshaler(typeof(StrictFilePathMarshaler))] byte* hintpath,
    source_callback fileCallback,
    IntPtr data);

Notice the change from using the MarshalAs attribute to using CustomMarshaler. This attribute causes another overload of this method to be automatically generated during the build (and available to Intellisense):

internal static unsafe int git_blob_create_fromchunks(ref GitOid oid, git_repository* repositoryPtr, string hintpath, source_callback fileCallback, IntPtr data)
{
    ICustomMarshaler marshaler = new StrictFilePathMarshaler();
    IntPtr p_hintpath = marshaler.MarshalManagedToNative(hintpath);
    try
    {
        return git_blob_create_fromchunks(ref oid, repositoryPtr, (byte*)p_hintpath, fileCallback, data);
    }
    finally
    {
        marshaler.CleanUpNativeData(p_hintpath);
    }
}

Notice this generated overload uses string as the marshaled parameter type, keeping the ease of use that we had before. It then emulates what the desktop marshaler would have done (at least, as far as I understand it).

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:10
  • Comments:32 (26 by maintainers)

github_iconTop GitHub Comments

2reactions
shiftkeycommented, Aug 22, 2016

@Jaykul it’s in flight, but it’s been a tough review to slog through so it’s kind of stalled: https://github.com/libgit2/libgit2sharp/pull/1318

2reactions
pawchencommented, Jun 27, 2016

@AArnott Thanks but that button would show ‘Unsubscribe’ if you already watched the repository, so I just don’t trust it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Portable Library
Buy books online and find book series such as Portable Library on PenguinRandomHouse.com.
Read more >
Introduction to Portable Class Libraries (PCL) - Xamarin
This article introduces Portable Class Library (PCL) projects and walks through creating and consuming PCL projects in Visual Studio for Mac ...
Read more >
Cross-Platform Development with Portable Class Libraries
Portable Class Libraries (PCLs) allow you to write code that can be targeted at a combination of .NET frameworks. You select the frameworks...
Read more >
Finding and tagging titles not offered by your library
If one of your libraries purchases the title, you'll be notified and have the option to borrow or place the title on hold...
Read more >
Little Free Library: Take a Book. Share a Book.
Little Free Library is a nonprofit organization with a mission to build community, inspire readers, and expand book access for all through a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found