This project has moved. For the latest updates, please go here.

GetResolutions() and GetPixelTypes() dosen't work in .net 4.0, 4.5 or 4.5.1

Mar 13, 2014 at 7:15 PM
Edited Mar 13, 2014 at 7:19 PM
Hello, I'm working with these library in a project that target .net 4.5.1 (x86) and all god except... when try to invoke these method GetResolutions() or GetPixelTypes() the app stopped immediately.

private void cbxScanner_SelectedIndexChanged(object sender, EventArgs e)
    {
        try
        {
            twain.CloseDataSource();
            twain.SourceIndex = cbxScanner.SelectedIndex;
            twain.OpenDataSource();

        }
        catch (TwainException ex)
        {
            LogFactory.CreateLog().LogError(ex.Message);
            MessageBox.Show(ErrorMessages.ScannerCannotByActivate, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
        }

        DisplayColorFormats();
        DisplayResolutions();
    }
private void DisplayColorFormats()
    {
        cbxColorFormat.Items.Clear();

        try
        {
            Twain32.Enumeration _pixelTypes = twain.GetPixelTypes(); //ERROR HERE!! :(

            for (int index = 0; index < _pixelTypes.Count; index++)
            {
                if (_pixelTypes[index].ToString() == "RGB")
                {
                    cbxColorFormat.Items.Add("Color");
                }

                if (_pixelTypes[index].ToString() == "Gray")
                {
                    cbxColorFormat.Items.Add("Escala de grises");
                }

                if (_pixelTypes[index].ToString() == "BW")
                {
                    cbxColorFormat.Items.Add("Blanco y negro");
                }
            }
        }
        catch (TwainException ex)
        {
            LogFactory.CreateLog().LogError(ex.Message);
            MessageBox.Show(ErrorMessages.PixelsNotAviableError, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
    }
private void DisplayResolutions()
    {
        cbxResolution.Items.Clear();

        try
        {
            Twain32.Enumeration resolutions = twain.GetResolutions(); //ERROR HERE!! :(

            if (resolutions.Count > 0)
            {
                for (int index = 0; index < resolutions.Count; index++)
                {
                    if (float.Parse(resolutions[index].ToString()) > 300)
                    {
                        cbxResolution.Items.Add(resolutions[index].ToString());
                    }                        
                }
            }
        }
        catch (TwainException ex)
        {
            LogFactory.CreateLog().LogError(ex.Message);
            MessageBox.Show(ErrorMessages.ResolutionsNotAviableError, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
    }

I'm using Visual Studio 2013 and Visual Studio 2013 Update 1... there is a problem with .net 4.0 or later version?
Coordinator
Mar 16, 2014 at 5:11 PM
Hello, emiliogg84.
I tested the project in .net 2.0 and .net 4.0 and not found any problems. I suspect that the problem is caused by an invalid sequence of method calls. See exception message and Saraff.Twain.Sample2.
Marked as answer by SARAFF on 6/23/2014 at 12:37 PM