Quantcast
Viewing all 8156 articles
Browse latest View live

Which one is the best source code in Microsoft Developer Network Samples?


Best approach for version tolerant serialization when new field allows null but has another default value.

I had asked a similar question:

Thread Title Determining OptionalFieldAttribute.VersionAdded for field being deserialized 

But it was inadvertently posted to the wrong forum (not a WCF question) and other than one reply I seemed to be having a conversation with myself.

I would like to implement a robust serialization mechanism without having to do too much work and the BinaryFormatter seems to work well - except when the default value of a new variable is not null or zero.

Take for example the case of adding a bool variable to an existing class class:

[OptionalField(VersionAdded = 2)]
private bool doGood = true;

When deserializing, if the version serialized was was of an earlier rev it will be de-serialized with a value of 'false' and to correct this in a method attributed with the Deserialized attribute it would be necessary to know this - hence the title of my original question.

I have given up on discovering an easy way to determine the version of the saved class and am now asking - what is the recommended way to serialize a field such as this - with the least amount of hassle & maintenance.

This must be a situation encountered by many developers so I assume that there are some recommendations or guidelines for how to do this.

I proposed saving a dictionary with the full type name mapped to a version number but if was possible to force the BinaryFormatter to overwrite a static class variable that had already been initialized then that would appear to me as simpler and easier to maintain.

An Extensive Examination of Data Structures Using C# 2.0

Scanning Component/sdk in .Net

Hello,

I want to develop a .Net application to scan some documents using VB.Net or C#.Net.

I searched for any component or any SDK provided by Microsoft which I can use to develop this application but no luck till yet. On Internet I found many third party components/sdk which are claiming to be .Net complaint but I am looking for component/sdk for scanning which is either provided by Microsoft or inbuilt in .Net Framework or VisualStudio.

Database.LoadDataSet() method throwing error while retriving data from IBM DB2 database

Database.LoadDataSet() method is throwing error during retriving data from empty table of IBM DB2 database. It is giving error code "SQL0100W".

“Error Message: 0NO_DATA [02000] [IBM] [DB2 / NT] SQL0100W FETCH, whether there is a line to be UPDATE or DELETE, or of the query result is an empty table . SQLSTATE = 02000”


How do I access the class name and method of an exception



How do I access the class name and method of an exception within my program? Pretty basic stufff I know, but can't seem to do so.

       ALSO, CAN SOMEONE PLEASE FIX THIS WINDOW I CANNOT PASTE INTO IT AND IT WON"T START A NEW LINE WHEN I PRESS RETURN. I AM USING IN VISUAL STUDIO 2013 AND ASSUME THE PROBLEM ARISES THERE SOMEHOW.

System.Reflection.Emit::DynamicMethod: Is there an SDK tool available to have IL code generated from existing assembly?

I want to create a dynamic method with code that's a bit more than trivial.

So I want to create a hard coded version of the method body and have a compiled version of it examined by some tool that's returning OpCos and parameters to me so I can insert them usingILGenerator::Emit().

Is there such tool available? I couldn't find one yet.


Still people out there alive using the keyboard?

Working with SQL Server/Visual Studio/Office/Windows and their poor keyboard support they seem extinct...

Microsoft.Diagnostics.Tracing.EventSource: Multiple sources/one event log

I'm trying to implement better event log usage in my software and the goal is to do the following:

Multiple Sources all writing to one or more channels of a single event log.  Meaning, one event log with the usual channels but the entries identified with different sources.

For example for "MyCompany-MyProduct":

MyCompany/MyProduct/Admin

MyCompany/MyProduct/Analytic

etc.

I can use the EventSource class to do this for one source but there doesn't appear to be a great way to have multiple sources write to the same log and the channels associated with the log.

[EventSource(Name="MyCompany-MyProduct")]
    public sealed class MyEventSource : EventSource
    {
        static public MyEventSource Log = new MyEventSource();

        [Event(1, Channel=EventChannel.Admin, Opcode=EventOpcode.Info, Message="Message: {0}", Keywords=EventKeywords.None)]
        [System.ComponentModel.Description("Admin Message")]
        public void WriteAdminMessage(string message)
        {

            WriteEvent(1, message);
        }
    }

I tried using the EventLog class in System.Diagnostics and I can almost write to that channel "MyCompany-MyProduct/Admin" but the event viewer than adds a log with that name to the top-level of the Application logs area and compromises the channel name registered from the EventSource manifest.

EventLog eventLog = new EventLog("MyCompany-MyProduct/Admin");
eventLog.Source = "MyOtherProduct";
eventLog.WriteEntry("Testing again...");

Worst case, I may have to write my own managed wrapper of the unmanaged event api but I'd rather not do that.

Any suggestions would be appreciated.


Using different version of assemblies (Microsoft.ReportViewer.WebForms)

Hi Guys, 

I need to use different versions of Microsoft.ReportViewer.WebForms(Version=9.0.0.0 and Version = 10.0.0.0) in a web application. Developed two user controls, one for each version of the report viewer. and loading it dynamically. But confused about the entries in the web.config. How do I define the handlers for both? ( using classic mode)

Thanks,

nasayoo


nasayoo

Trouble finding and referencing System.Configuration using .NET 4.5

As many out there, I am trying to use the ConfigurationManager class to read a ConectionString stored in a Web.Config file. The class is not recognized even though I have checked that System.Configuration is referenced by the project and I have added the using System.Configuration statement at the beginning of the code file. When I tried to add System.Configuration to the project, visual studio stated that the library is already referenced, although, it is not recognized in the using statement in the code file. How do I resolve this issue?

did windows form application works on windows touch ?

I am creating a windows form application using visual studio 2010 with framework 4.0 and this app maybe work on normal windows or windows touch ... is there a procedure should i take to make my app works on windows touch or this will automatically happened 

PrintDocument printer presets

Hello,

I've got serious problem. I can't change printer preset programmatically. I can't believe it.
Is there any way to do this? I've got two predefines presets and I need to select one of them (on-the-fly without user interaction). It depends on filename.

Thanks, avanember

Package vs. EncryptedPackageEnvelope

I'm trying to find a solution to have a filesystem-like structure in my application. I though the Package/ZipPackage would be a good solution, but it seems it's not possible to a have subfolder using the CreatePart/PackagePart method.

In fact I need the structured storage API which I thought is implemented in the Package class.

I have several plugins where each plugin should get a plugin-specific folder. From the main application I create the subfolder and only hand over the PackagePart to the plugin where the plugin is locked in the PackagePart. The plugin itself can only navigate inside the PackagePart add other folders and files, etc.

Somehow the PackagePart does not allow to create substructures. But the EncryptedPackageEnvelope does. Unfortunately I don't know how to allocate the EncryptedPackageEnvelope and I don't need the storage encrypted.

I found some blog where the StorageRoot was initially an available class, but Microsoft made it internal, and also internal in the EncryptedPackageEnvelope.

Is there something else I can use out of the box? Maybe one of the above solutions?

Thanks Martin


msedi

CUDA SafeHandle ObjectDisposedException when exiting application

I'm having trouble using the SafeHandle for my unmanaged P/Invokes using the CUDA library. My problem is following. I have created a CUDA P/Invoke library with two methods to create a CUDA context.

public static extern CUresult cuCtxCreate(out CUcontext pCtx, CUctx_flags Flags, CUdevice dev);
public static extern CUresult cuCtxDestroy(CUcontext ctx);

Then to ensure the handle is closed when it's not needed anymore I createsd a CUcontext derived from a SafeHandle:

 /// <summary>
    /// Cuda Context Handle
    /// </summary>
    [SecurityPermission(SecurityAction.InheritanceDemand, UnmanagedCode = true)]
    [SecurityPermission(SecurityAction.Demand, UnmanagedCode = true)]
    public class CUcontext : SafeHandleZeroOrMinusOneIsInvalid
    {
        public CUcontext()
            : base(true)
        {
        }

        [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
        protected override bool ReleaseHandle()
        {
            try
            {
                if (!IsInvalid)
                {
                  CUDADriverAPI.cuCtxDestroy(this);
                }
            }
            catch
            {
                SetHandleAsInvalid();
            }

            return true;
        }
    }

Then I wrote a small tester to see if the CUDA context gets released when closing the application:

void Main()
{
    CUDADriverAPI.cuInit(0);

    // Get the device handle
    CUdevice aDeviceHandle = new CUdevice();
    CUDA.Assert(CUDADriverAPI.cuDeviceGet(ref aDeviceHandle, 0));

    CUcontext aContextHandle = null;

    // Create a context.
    CUDA.Assert(CUDADriverAPI.cuCtxCreate(
        out aContextHandle,
        CUctx_flags.CU_CTX_SCHED_AUTO | CUctx_flags.CU_CTX_MAP_HOST,
        aDeviceHandle
        ));
}    

The problem is that the ReleaseHandle of the SafeHandle gets called immediately after the last curly bracket which is OK. The problem is that the SafeHandle fires a ObjectDisposedException when calling cuCtxDestroy although the finalizer has not run before.

My question is what exactly happens on the last curly bracket. If some internal CUDA objects has been created which subsystem is responsible to clean it after the application has been closed. This behaviour must be similar to the FileStream mechanism or anything else that deals with SafeHandles. If haven't got the magic behind it.

One thing that came into my mind was that I use the same SafeHandle in the Create and Destroy method. In most of the examples a regular IntPtr was used. Maybe this is one of the problems since I don't know if the handle is marked as "destroyed" when I'm in the ReleaseHandle() method and I don't know if the marshaller will recognize this as object disposed.

Thank you Martin





Cross Reference Table in Pdf

 I am developing the assembly for pdf to add annotations. For that i need to clarify my doubts. How to add entries inside the cross reference table? how to get the object number from that entry?


Pdf Dll creation

Please any one give me a sample code which generates the pdf document?

Now i am creating the pdf dll. Please tell me how to startup the creation?

.Net Framework: WORA - Write once, run anywhere. Will it be?

I have read about .Net Core and other news relating it.

Will it be platform independent?

Will i be able to write once and run anywhere using .Net Framework like Java?

That would be very cool, i am very excited.

I am not talking about Mono, Xamarin!

I am talking about real .Net Framework!

MSDN documentation - http://msdn.microsoft.com/en-us/library/system.net.http.httprequestmessageextensions.getcorrelationid%28v=vs.118%29.aspx

Hi,

According to the MSDN documentation for HttpRequestMessageExtensions.GetCorrelationId Method, the intended behavior of the method is get a new guid for new http request. We have observed plenty of duplicate Identifiers generated from the GetCorrelationId method.

Please let me know if the documentation is poor to highlight the usage or is it a bug?

Thanks

Application.Exit(); throwing Collection was modified; enumeration operation may not execute

Hi,

I would like to ask why I am getting:

Collection was modified; enumeration operation may not execute

when using:

Application.Exit();

Kindly help.....

source code to generate one-time download URL?

My boss ask me work out a secure download link solution, I need your kind help.

2 Servers, A is front end web portal server, B is Windows Server 2008 R2 IIS server to store download file.     

User a use IE browser to login web server A portal , click a link to download a confidential EXE file in Server B C:\path_a\setup.exe

User b use IE browser to login web server A portal, click a link to download a confidential EXE file in Server B C:\path_b\setup.exe

The server will return one-time download link (or you may say dynamic generated link, one-time rewrite link) for that user, so if the hacker capture the download link directly, they cannot download the file as the download link is invalid.


Can you provide web page source code to me and tell me how to insert in IIS website? I have zero knowledge about IIS, detail description is highly appreciated, thanks a lot. 

Viewing all 8156 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>