Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NetTopologySuite.IO.ShapeFile with Xamarin.Mac - ArgumentNullException #34

Open
TomQv opened this issue May 15, 2020 · 7 comments
Open

Comments

@TomQv
Copy link

TomQv commented May 15, 2020

Im trying to read shp-files in a Xamarin.Mac project with NetTopologySuite.IO.Shapefile 2.0.0.
Project is targeting Xamarin.Mac Full NET 4.8.

Calling _reader = new ShapefileDataReader(file, _geometryFactory, System.Text.Encoding.Default); results in ArgumentNullException, see stacktrace below.

With a plain .NET Core 3.0 project, everything is fine.

Any ideas?

System.ThrowHelper.ThrowArgumentNullException(System.ExceptionArgument argument) in /Library/Frameworks/Xamarin.Mac.framework/Versions/Current/src/Xamarin.Mac/external/corefx/src/System.Memory/src/System/ThrowHelper.cs:27
System.Collections.Generic.Dictionary<System.Text.Encoding,byte>.FindEntry(System.Text.Encoding key) in /Library/Frameworks/Xamarin.Mac.framework/Versions/Current/src/Xamarin.Mac/external/corefx/src/Common/src/CoreLib/System/Collections/Generic/Dictionary.cs:380
System.Collections.Generic.Dictionary<System.Text.Encoding,byte>.ContainsKey(System.Text.Encoding key) in /Library/Frameworks/Xamarin.Mac.framework/Versions/Current/src/Xamarin.Mac/external/corefx/src/Common/src/CoreLib/System/Collections/Generic/Dictionary.cs:286
NetTopologySuite.IO.DbaseEncodingUtility.AddLdidEncodingPair(byte ldid, System.Text.Encoding encodingToAdd) in 
NetTopologySuite.IO.DbaseEncodingUtility.RegisterEncodings(object[][] ldidCodePagePairs) in 
NetTopologySuite.IO.DbaseEncodingUtility..cctor() in 
NetTopologySuite.IO.DbaseFileHeader.GetEncoding(NetTopologySuite.IO.Streams.ByteStreamProvider provider) in 
NetTopologySuite.IO.DbaseFileHeader.DetectEncoding(byte ldid, NetTopologySuite.IO.Streams.ByteStreamProvider cpgFile) in 
NetTopologySuite.IO.DbaseFileHeader.ReadHeader(System.IO.BinaryReader reader, NetTopologySuite.IO.Streams.ByteStreamProvider cpgStreamProvider) in 
NetTopologySuite.IO.DbaseFileReader.GetHeader() in 
NetTopologySuite.IO.ShapefileDataReader..ctor(string filename, NetTopologySuite.Geometries.GeometryFactory geometryFactory, System.Text.ASCIIEncoding encoding) in 
QvShape.Reader..ctor(string file) in /Users/tomflemming/QuoVadis/Qvx1/CodeFromExternal/NetTopologySuite/QvShape/Reader.cs:26
QvShape.Reader.Test() in /Users/tomflemming/QuoVadis/Qvx1/CodeFromExternal/NetTopologySuite/QvShape/Reader.cs:83
QvxAppShared.QvxApp..ctor(Eto.Mac.Platform platform, string[] args) in /Users/tomflemming/QuoVadis/Qvx1/QvxShared/App/QvxApp.cs:49
QvxAppShared.Mac.Program.Main(string[] args) in /Users/tomflemming/QuoVadis/Qvx1/QvxMac/Program.cs:16

@cmarqueztecnosylva
Copy link

Hi TomQv,
i have a similar problem, but when i write a shapefile. Do you found any solution for your problem?
I also use
NetTopologySuite.Features 2.0
NetTopologySuite.IO.Shapefile 2.0
on xamarin.

Thanks in advance

@TomQv
Copy link
Author

TomQv commented Jun 5, 2020

Hi, no, unfortunate not yet. I mean, I downloaded the source, commented out DetectEncoding() because I don't have text in that specific project so its working with me. But of course this is just a workaround if you don't have text in db.

@cmarqueztecnosylva
Copy link

Perfect, i haven text also, so, do you download the project from here https://github.com/NetTopologySuite/NetTopologySuite???

because i go to do the same.

A lot of thanks for your pretty fast response TomQv.

@TomQv
Copy link
Author

TomQv commented Jun 5, 2020

I only downloaded https://github.com/NetTopologySuite/NetTopologySuite.IO.ShapeFile
Because I only need Shp. You must add a reference to NetTopologySuite.Features.

These are my changes only in file DbaseEncodingUtility:

internal static readonly Encoding Latin1 = Encoding.UTF8;                                 // TOM  GetEncodingForCodePageName("iso-8859-1");
public static Encoding DefaultEncoding { get; set; } = Encoding.UTF8;                     //  TOM   GetEncodingForCodePageIdentifier(1252);
public static Encoding GetEncodingForCodePageIdentifier(int codePage) => DefaultEncoding; // TOM  CodePagesEncodingProvider.Instance.GetEncoding(codePage);
public static Encoding GetEncodingForCodePageName(string name) => DefaultEncoding;        // TOM   CodePagesEncodingProvider.Instance.GetEncoding(name) ?? Encoding.GetEncoding(name);

@cmarqueztecnosylva
Copy link

Thanks a lot Tom,

i done the same, but my bug was another, in the method GetLdidFromEncoding; i added a try catch and is done:

    private static byte GetLdidFromEncoding(Encoding encoding)
    {
        byte ldid;
        try
        {
            if (!DbaseEncodingUtility.EncodingToLdid.TryGetValue(encoding, out ldid))
                ldid = 0x03;
        }
        catch
        {
            ldid = 0x03;
        }
        return ldid;
    }

Thanks.

@TomQv
Copy link
Author

TomQv commented Jun 5, 2020

👍

@KubaSzostak
Copy link
Member

Hi @TomQv, do you need more support on this issue? If so, provide further details, please.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants