Quantcast
Channel: .NET Framework Class Libraries forum
Viewing all 8156 articles
Browse latest View live

operators and conditional with reflection or Reflection.Emit

$
0
0

good morning!
using operators and conditional with reflection or Reflection.Emit?

tanks


How do I avoid .bin attachments with SmtpClient.Send(MailMessage)?

$
0
0

I'm hitting the problem described here. However, I don't see any way with MailMessage to set the ordering of the content of the email.

How can I fix this?

        MailMessage mail = new MailMessage(new MailAddress(emailTempKeysFrom, "Windward Studios"), new MailAddress(to[0], pur.Account.Name));

        mail.Body = txt;
        AlternateView htmlView = AlternateView.CreateAlternateViewFromString(html, null, MediaTypeNames.Text.Html);
        int num = 0;
        foreach (MemoryStream mem in imagesTempKeys)
        {
            mem.Position = 0;
            LinkedResource res = new LinkedResource(mem);
            res.ContentId = "image" + num;
            res.TransferEncoding = TransferEncoding.Base64;

            htmlView.LinkedResources.Add(res);
            num++;
        }
        mail.AlternateViews.Add(htmlView);
        mailObj.Send(mail);

thanks - dave


What we did for the last 6 months - Made the world's coolest reporting & docgen system even more amazing


cant create an instance of excel.application

$
0
0

hallo, everyone,

we have a Desktop-App (vb.net), and need open Excel from program, and we just used 

xlsWorkbook = CType(System.Runtime.InteropServices.Marshal.BindToMoniker(filePath), Excel.Workbook)

xlsApp = CType(xlsWorkbook.Parent, Excel.Application)

and it works fine except by one user,

and we tried 

xlsApp = New Excel.Application     or 

xlsApp = CType(CreateObject("Excel.Application"), Excel.Application) 

and it cant work with his computer, by other users are ok.

i think its nothing to do with our code, just one com-component in his computer is missing, such like interop.excel.dll or sth else.

anyone know this? can anyone help?

thanks a lot!

using the SqlParameterCollection

$
0
0

Hi,

I got this:

To overcome this, you need to iterate through the source array and add each value to the SqlParameterCollection collection

string[] source = Convert.ToString(cboToCountry.EditValue).Split(new char[] { cboToCountry.Properties.SeparatorChar });

StringBuilder sb = new StringBuilder();

foreach (string s in source)

sql_command.Parameters.AddWithValue("param_country", s.Trim());

not sure how can I use the SqlParameterCollection.

Kindly help..

here is my code:

sql_connection = new MySqlConnection(serverClass.connectionstring("BlueFile", "BlueFile", "Server"));
sql_connection.Open();

sql_command = new MySqlCommand("sp_populate_memo_country_companies", sql_connection);
sql_command.CommandType = CommandType.StoredProcedure;
// sql_command.Parameters.AddWithValue("param_country", country_codes(Convert.ToString(cboToCountry.EditValue))).MySqlDbType = MySqlDbType.VarChar;

string[] source = Convert.ToString(cboToCountry.EditValue).Split(new char[] { cboToCountry.Properties.SeparatorChar });
StringBuilder sb = new StringBuilder();
foreach (string s in source)
{
sql_command.Parameters.AddWithValue("param_country", s.Trim()).MySqlDbType = MySqlDbType.VarChar;
}

Thanks,

Jassim

Enterprise library 5.0

$
0
0
Enterprise library log creation is not consistence. The log configuration set to rollInterval="Day", but   two log files are created instead of just one.

NLua: The type or namespace name KeraLua could not be found!

$
0
0

I have recently been looking into NLua for C# inb visual studio

however when I compile can run it I get the error "the type or namespace name KeraLua could not be found"

can someone tell me what this means

NLua seems to come with a demo project but I want to have only the API in my project, not the demo projects.

POS For .Net 1.12 /1.14 - Reverse Video Printing - CapReverse property

$
0
0

I believe the reverse video printing / capReverse property was added back in the release UPOS 1.6 and currently i am using Microsoft pos for .Net sdk version 1.12 and 1.14 and unable to find the the CapReverse property in the PrinterProperty class.  can any one tell how this feature can be implemented. ?  

https://msdn.microsoft.com/en-us/library/microsoft.pointofservice.posprinter_properties(v=winembedded.11).aspx

The link above describes the pos printer properties , but it does not include anything about the CapReverse

 

ss


Enterprise library 5.0

$
0
0

I have used the EL 5.0 to create the log. The log is created  but its writing log in two files instead of one.

Here is name of first file name: Policy.txt

Second file name: 28afdf13-db29-453c-8a85-2684e9895353Policy.txt

Business want just one log file  daily from midnight.

Here is log configuration.

<add name="Policy Flat File" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" fileName="C:\LOGS\Policy.txt" header="" footer="" formatter="MAO-Privacy-Policy" rollFileExistsBehavior="Increment" rollInterval="Midnight" timeStampPattern="yyyy-MM-dd" rollSizeKB="10000" maxArchivedFiles="30" />

Please help to fix this issue.



Enterprise library 5.0

$
0
0
The log is created  but its writing log in two files instead of one.

Is there Native support in .NET for XACML?

$
0
0
I have been unable to find any knowledge with regards to XACML support within the .Net framework. It appears that Microsoft does not have any current plans to incorporate XACML into the native framework, not even in the WIF or FIM / MIM. Does anyone know if Microsoft will incorporate this into their framework in the future?

Reading RAW RGBA Data into a bitmap

$
0
0
I am converting a piece of image manipulation from Python to C#
and basically I am getting nothing but garbage out

I have a byte array of Raw RGBA data and I am trying to copy it into a bitmap.
The code I have is as follows:

        public Bitmap RawToBitmap(byte[] rawdata)
        {

            for (int i = 0; i < rawdata.Length - 1; i+=4)
            {
                byte R = rawdata[i];
                byte G = rawdata[i + 1];
                byte B = rawdata[i + 2];
                byte A = rawdata[i + 3];

                rawdata[i] = A;
                rawdata[i + 1] = R;
                rawdata[i + 2] = G;
                rawdata[i + 3] = B;
            }

            int width = 128;
            int height = 128;

            // Set the stride... 
            int stride = width;

            // Ensure it is padded to a multiple of 4
            if (stride%4 != 0)
            {
                stride = width + (4 - width % 4);
            }

            IntPtr myPointer = System.Runtime.InteropServices.Marshal.AllocHGlobal(rawdata.Length);
            System.Runtime.InteropServices.Marshal.Copy(rawdata, 0, myPointer, rawdata.Length);

            Bitmap output = new Bitmap(width, height, stride, System.Drawing.Imaging.PixelFormat.Format32bppArgb, myPointer);
            Bitmap realOutput = (Bitmap)output.Clone();
           
            System.Runtime.InteropServices.Marshal.FreeHGlobal(myPointer);

            return realOutput;

        }

The only difference between this code and the original python is that the PNG library for python supports RGBA where as I can seem to find an equivelent in dot net so I am doing a byte swap.

I have tried both with and without the byte swap.
I have tried various PixelFormats but I never get anything but a munged image.

Any help at all would be appreciated.

.net application working in sharepoint

$
0
0
 The specific question I have is that I have an application that was developed using Microsoft.net and MVC3 framework on Windows 2008 R2 & SQL 2008 R2.  I assume it will work on any version of sharepoint since the application is .Net.  Can anyone confirm this for me?  Thanks.

Microsoft Speech

$
0
0
Is there a number limit that the Microsoft TTS_MS_en-US_Helen_11.0 audio can read out? In my App, I entered $100000 (One Hundred Thousand dollars), the TTS read it back correctly, but when i tried entering anything greater the $100000 (One Hundred Thousand dollars) It read back each digit of the number and not the number as whole.

Eg :- $100000 was read back as One Hundred Thousand dollars. But $100001 is read back as dollar one zero zero zero zero one.

Could someone suggest how to address this issue? 

How to get html source code after javascript execution?

$
0
0

Hello,

I am developing ASP.NET application and I want to load html from another site which uses AJAX for loading data from the server and insert it to HTML after. How to get final HTML source code after javascript execution?

Thank you for your time!

Reflection APIs are completely butchered at this point

$
0
0

I can't help but feel like this is a bug:

void Main()
{
	typeof(Test).GetProperty("TestString").GetCustomAttributes().Dump(); //dumps 1 item
	typeof(Test).GetProperty("TestString").GetCustomAttributes(inherit:true).Dump(); // dumps 0 items
	typeof(Test).GetProperty("TestString").GetCustomAttributes(inherit:false).Dump(); // dumps 0 items
}

// Define other methods and classes here

class TestBase
{
	[TestAttribute]
	public virtual string TestString {get;set; }
}

class Test : TestBase
{
	public override string TestString {get;set; }
}

[AttributeUsage(AttributeTargets.Property, Inherited = true)]
class TestAttribute : Attribute
{}

Are property attributes even supposed to be inheritable? ReSharper doesn't seem to think so, giving you a warning that "Inherited = true" only applies to AttributeTargets.Class and AttributeTargets.Method, and either does GetCustomAttributes(bool inherit). Why would the parameterless version return the attribute?

Next up: why are all the GetRuntimeXXX() methods extensions on Type and not extensions on TypeInfo? I thought the whole point of the reflection API redesign was to make Type just a reference to a type, and TypeInfo to require a load and contain all the actual type shape and information. Doesn't this design fly in the face of this distinction? I don't understand why they aren't just plain methods on TypeInfo instead of extensions on Type.

Why does TypeInfo inherit from Type in .NET but not in .NET Core and UWP? This causes confusion because all the extensions mentioned above are now available on both Type and TypeInfo on .NET, and introduces more API differences between the platforms. Now you need to go to TypeInfo to get some stuff, while other stuff you can just grab from Type but it will still cause an assembly load, and stuff is just all over the place. This is further confused by the fact that the API docs for .NET Core show that the class declaration for TypeInfo DOES in fact inherit from Type. Whaaaa??

Why does GetRuntimeProperties() return non-public members but GetRuntimeProperty(name) doesn't? This completely violates the principle of least surprise. This would almost be forgivable if the difference was documented in the method docs but it isn't.

Is there actually a point to the GetRuntimeXXX? It seems to me that GetProperties and GetProperty are available everywhere. When should you pick one over the other now?

There are more things that I can't remember off the top of my head but this is honestly the most botched API refresh I've seen come out of Microsoft. The only other thing that comes close is the mess of inconsistencies between generic and non-generic collection interfaces/classes. Writing a portable library that heavily depends on reflection has been quite the exercise in patience these last couple months.

I really wish there was an opportunity to do a "clean break" where all the past mistakes of the framework could be cleaned up, especially the collection classes/interfaces situation because those are used all the time. But I'm guessing that's never going to happen...I was hoping .NET Core was going to be that clean break and clean everything up in a sensible way but it didn't :(




ObservableCollection Memory Leak?

$
0
0

I am populating an ObservableCollection<T> where T is a simple model. One of the properties in my model is a byte[]. The ObservableCollection<T> is refreshed often, using these steps:

  1. ObservableCollection<T>.Clear()
  2. Populate ObservableCollection<T>

Problem: The memory consumption grows everytime the observable collection is repopulated.

My questions are:

  1. Doesn't the garbage collector free up the model items in the observable collection after the Clear()?
  2. If not, what steps do I need to take to free up the list of items after they have been cleared from the observable collection?
  • The ObservableCollection<T> is bound to a WPF control
  • Type <T> has only .Net int's, string's and the one byte[]
  • Type <T> does not implement IDisposable

Thanks in advance for your help!

Chart.SaveImage does not save anything in the image

$
0
0

Hello, I'm working on a wcf service and trying to create a chart serverside and save it as image so that I can send the image url to external users. Here is the complete code:

 var chart = new System.Web.UI.DataVisualization.Charting.Chart();
            chart.EnableViewState = false;

            chart.Titles.Add(new System.Web.UI.DataVisualization.Charting.Title());
            chart.Titles[0].Text = "Cash Balance Comparison";
            chart.Titles[0].Alignment = System.Drawing.ContentAlignment.TopCenter;
            chart.Visible = true;
            chart.Legends.Add("Legend1");

            var series = chart.Series.Add("School 1");
            series.ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.RangeColumn;
            series.Points.AddXY("dept 1", 12345);
            series.Points.AddXY("dept 2", 345);
            series.Points.AddXY("dept 3", 345);
            series.Points.AddXY("dept 4", 5656);

            series = chart.Series.Add("School 2");
            series.ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.RangeColumn;
            series.Points.AddXY("dept 1", 54345);
            series.Points.AddXY("dept 2", 444);
            series.Points.AddXY("dept 3", 54345);
            series.Points.AddXY("dept 4", 9090);

            series = chart.Series.Add("School 3");
            series.ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.RangeColumn;
            series.Points.AddXY("dept 1", 239);
            series.Points.AddXY("dept 2", 2397);
            series.Points.AddXY("dept 3", 23237);
            series.Points.AddXY("dept 4", 2234487);

            chart.Legends[0].Docking = System.Web.UI.DataVisualization.Charting.Docking.Bottom;
            chart.Legends[0].TitleAlignment = System.Drawing.StringAlignment.Center;
            chart.Legends[0].Alignment = System.Drawing.StringAlignment.Center;

            chart.RenderType = System.Web.UI.DataVisualization.Charting.RenderType.ImageTag;

            string path = @"C:\temp\Charts\test.png";

            chart.ImageLocation = path;

            chart.SaveImage(path, System.Web.UI.DataVisualization.Charting.ChartImageFormat.Png);

            chart.Dispose();
            chart = null;
            return path;

It saves an image with a chart title, but doesn't contain anything else. Can someone please let me know why its not working?

Any help will be highly appreciated.

Thanks.


MEF2 package compatibility issues in 4.6 PCL

$
0
0

I have a lot of PCL libraries targeting .NET Framework 4.5.1 and Windows Universal I'd like to upgrade to 4.6. Unfortunately, some of them rely on MEF2 (the package from NuGet: microsoft.composition), which targets 4.5 only. Yet, this lightweight version seems to be the most modern of the MEF releases. Is there any way I can use this package in these PCLs, or should I stick with 4.5 and wait for a hopefully upgrade of that package? According to this post (http://stackoverflow.com/questions/28801312/is-there-a-replacement-for-mef-in-net-core-or-asp-net-5), it seems that the MEF2 package is effectively usable even in .NET Core (yet, the proposed solution for using that package in .NET Core libraries does not seem to work).

You can easily reproduce the issue as follows: using VS2015 update 3, create a new PCL library project (.NET Framework: 4.6.2, Class Library (Portable), accepting all the default targets: .NET Framework 4.6, Windows Universal 10.0). Then try to install MEF2 via its NuGet package: install-package microsoft.composition. NuGet will fail installing the package, telling that package is not compatible with .NETStandard, Version=v1.3. The package rather supports portable-net45+win8+wp8+wpa81 (.NETPortable,Version=v0.0,Profile=Profile259).

playing AVI video files,

$
0
0
  The video motion plays, but no sound is heard while playing on Windows 10.  Is there a way to play the full file functionality??

How to use the WritePrinter / ReadPrinter method to read/write data from zebra printer GX420t using C#

$
0
0

i am trying to send a ZPL (Zebra Programming Language) command to my Zebra GX420t printer to check its status if it available, offline, ready or pause etc. i can send a command to write to printer but please tell me how i can read response from the printer ?

is there any way to send zpl through c# and then read the resposne.

i have alreay tried the link below but my ReadPrinter function is not returning any data in the "out" parameter and the method always return false:

https://msdn.microsoft.com/en-us/library/windows/desktop/dd162895(v=vs.85).aspx

http://stackoverflow.com/questions/25669403/how-to-send-a-raw-zpl-to-zebra-printer-using-c-sharp-via-usb?rq=1

http://stackoverflow.com/questions/2044676/net-code-to-send-zpl-to-zebra-printers

my code is as follows:

/////////To send data to printer i have used 

             string s = "^XA~HQES^XZ\n";
            var bytes = Encoding.ASCII.GetBytes(s);
            RawPrinterHelper.SendStringToPrinter("ZDesigner GX420t (Copy 1)", s);

////////////////////////////////////////////////////////////////////////////////////

//////This is my method to send request and then get response 

public static bool SendBytesToPrinter(string szPrinterName, IntPtr pBytes, Int32 dwCount)
        {
            Int32 dwError = 0, dwWritten = 0;
            IntPtr hPrinter = new IntPtr(0);
            DOCINFOA di = new DOCINFOA();
            bool bSuccess = false; // Assume failure unless you specifically succeed.

            di.pDocName = "MTOlive label";
            di.pDataType = "RAW";

            // Open the printer.
            if (OpenPrinter(szPrinterName.Normalize(), out hPrinter, IntPtr.Zero))
            {
                // Start a document.
                if (StartDocPrinter(hPrinter, 1, di))
                {
                    // Start a page.
                    if (StartPagePrinter(hPrinter))
                    {
                        // Write your bytes.
                        bSuccess = RawPrinterHelper.WritePrinter(hPrinter, pBytes, dwCount, out dwWritten);
                        StringBuilder sbData = new StringBuilder();
                        bool aSuccess = ReadPrinter(hPrinter, out sbData, dwWritten, out dwWritten);
                        EndPagePrinter(hPrinter);
                    }
                    EndDocPrinter(hPrinter);
                }
                ClosePrinter(hPrinter);
            }
            // If you did not succeed, GetLastError may give more information
            // about why not.
            if (bSuccess == false)
            {
                dwError = Marshal.GetLastWin32Error();
            }
            return bSuccess;
        }

/////////////////////////////////////

Viewing all 8156 articles
Browse latest View live