[{"data":1,"prerenderedAt":992},["ShallowReactive",2],{"article-nullable-types-in-net-framework":3},{"article":4,"tags":90,"previous":105,"next":826},{"id":5,"title":6,"author":7,"body":8,"createdAt":79,"description":14,"extension":80,"img":81,"meta":82,"navigation":83,"path":84,"seo":85,"stem":86,"tags":87,"updatedAt":79,"__hash__":89},"articles\u002Farticles\u002Fnullable-types-in-net-framework.md","Nullable Types in .NET Framework","[object Object]",{"type":9,"value":10,"toc":75},"minimark",[11,15,18,34,40],[12,13,14],"p",{},"Within the .NET Framework data types such as Boolean can either be true or false. Right? Well, with the release of 2.0 Framework it has been possible to create nullable data types. A nullable type can represent all the values of the underlying type plus empty (or undefined). In the case of our Boolean it would be True\u002FFalse and Nothing.",[12,16,17],{},"It is only possible to create a nullable types Nullable(Of T) for value types since the default value for reference types is already nothing. The following types are valid as nullable: Boolean, Byte, Int16, Int32, Int64, Single, Double, Decimal, DateTime. The following examples show examples on how to create a nullable variable type:",[12,19,20,21,24,25,27,28,30,31,33],{},"Dim success as New Nullable(Of Boolean)()",[22,23],"br",{},"\nDim customerId as New Nullable(Of Integer)()",[22,26],{},"\nWith the release of .NET 3.5 it is also possible to use the short form versions:",[22,29],{},"\nDim success as Boolean?\nDim customerId as Integer?",[22,32],{},"\nIn C#",[12,35,36,37,39],{},"bool? success;",[22,38],{},"\nint? customerId;",[12,41,42,43,45,46,48,49,51,52,54,55,57,58,60,61,65,66,68,69,71,72,74],{},"To check of a nullable type as a value it is possible to use the HasValue or Value properties. Use the System.Nullable.GetValueOrDefault property return either the assigned value, or the default value for the underlying type.",[22,44],{},"\nIf customerId.HasValue Then\ndo something\nEnd If",[22,47],{},"\nIf assigning a nullable type to a non-nullable type you must cast operator is necessary. For example:",[22,50],{},"\nint newCustomerId = (int)customerId; \u002F\u002F in C#",[22,53],{},"\nNullable types can be useful when dealing with NULL values from a database query however they are not the same. That is to say that DBNULL value is not the same as Nothing. When returning data from the database the following code will be necessary:",[22,56],{},"\nint? customerId = null;",[22,59],{},"\nif (!DBNULL.Value.Equals(reader",[62,63,64],"span",{},"“CustomerId”",")){ \u002F\u002F this code converts the DBNULL to a c# null",[22,67],{},"\ncustomerId = (int)reader",[62,70,64],{},";",[22,73],{},"\n}",{"title":76,"searchDepth":77,"depth":77,"links":78},"",2,[],"2015-04-20T08:07:15.7000000-04:00","md","\u002Farticles\u002Fimages\u002Fstation.jpg",{},true,"\u002Farticles\u002Fnullable-types-in-net-framework",{"title":6,"description":14},"articles\u002Fnullable-types-in-net-framework",[88],"netcore","JNUKjLzLY5rs-w8jF4EkEer1CjSLRZAYa-LqJjqkYlU",[91],{"id":92,"title":93,"body":94,"description":98,"extension":80,"img":99,"meta":100,"name":88,"navigation":83,"path":101,"seo":102,"stem":103,"__hash__":104},"tags\u002Ftags\u002Fnetcore.md","Netcore",{"type":9,"value":95,"toc":96},[],{"title":76,"searchDepth":77,"depth":77,"links":97},[],".NET Core is a new version of .NET Framework, which is a free, open-source, general-purpose development platform maintained by Microsoft. It is a cross-platform framework that runs on Windows, macOS, and Linux operating systems.","https:\u002F\u002Fimages.unsplash.com\u002Fphoto-1598313183973-4effcded8d5e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=675&q=80",{},"\u002Ftags\u002Fnetcore",{"description":98},"tags\u002Fnetcore","D5BWCPpKVXJTUKU0TRuD3sWQ9rXtqETGkxzHAK__g5w",{"id":106,"title":107,"author":7,"body":108,"createdAt":818,"description":819,"extension":80,"img":815,"meta":820,"navigation":83,"path":821,"seo":822,"stem":823,"tags":824,"updatedAt":818,"__hash__":825},"articles\u002Farticles\u002Fgenericcollection-usage-in-the-net-framework.md","Generic(Collection) Usage in the .NET Framework",{"type":9,"value":109,"toc":816},[110,116,119,217,312,448,451,591,660,664,667,680,683,781,789,797,800,803,806],[12,111,112,113,115],{},"Generics provide a way for developers to define subroutines, functions, fields, properties as well as classes, structures, interfaces and even delegates in such a way that the parameters are not of any particular type.  In a sense the constructs are defined in a generic approach.",[22,114],{},"\nThe .NET Framework contains the following namespaces:System.Collections, System.Collections.Generic.    The latter mimics very much the features of the former. ",[12,117,118],{},"System.Collections namespace (nongeneric)",[120,121,125,126,125],"table",{"border":122,"cellSpacing":123,"cellPadding":123,"style":124},0,"0","width: 515px;","  \n",[127,128,125,129,125,146,125,157,125,168,125,179,125,189,125,199,125,209,125],"tbody",{},[130,131,125,132,125,138,125,142,125],"tr",{},[133,134,137],"td",{"width":135,"vAlign":136},152,"top","ICollection",[133,139,141],{"width":140,"vAlign":136},224,"(size, enumeration, thread safety)",[133,143,145],{"width":144,"vAlign":136},137,"derives from IEnumerable",[130,147,125,148,125,151,125,154,125],{},[133,149,150],{"width":135,"vAlign":136},"IComparer",[133,152,153],{"width":140,"vAlign":136},"Allows two objects to be compared",[133,155,156],{"width":144,"vAlign":136}," ",[130,158,125,159,125,162,125,165,125],{},[133,160,161],{"width":135,"vAlign":136},"IDictionary",[133,163,164],{"width":140,"vAlign":136},"Collection object to represent its contents using name\u002Fvalue pairs",[133,166,167],{"width":144,"vAlign":136},"derives from ICollection, IEnumerable",[130,169,125,170,125,173,125,176,125],{},[133,171,172],{"width":135,"vAlign":136},"IDictionaryEnumerator",[133,174,175],{"width":140,"vAlign":136},"Enumerates the contents of a type supporting IDictionary",[133,177,178],{"width":144,"vAlign":136},"derives from IEnumerator",[130,180,125,181,125,184,125,187,125],{},[133,182,183],{"width":135,"vAlign":136},"IEnumerable",[133,185,186],{"width":140,"vAlign":136},"Returns IEnumerator interface for a collection",[133,188,156],{"width":144,"vAlign":136},[130,190,125,191,125,194,125,197,125],{},[133,192,193],{"width":135,"vAlign":136},"IEnumerator",[133,195,196],{"width":140,"vAlign":136},"Enables for each style iteration of items in collection",[133,198,156],{"width":144,"vAlign":136},[130,200,125,201,125,204,125,207,125],{},[133,202,203],{"width":135,"vAlign":136},"IList",[133,205,206],{"width":140,"vAlign":136},"Provides add, remove and index items in a list of objects",[133,208,167],{"width":144,"vAlign":136},[130,210,125,211,125,213,125,215,125],{},[133,212,156],{"width":135,"vAlign":136},[133,214,156],{"width":140,"vAlign":136},[133,216,156],{"width":144,"vAlign":136},[218,219,125,221,125],"div",{"id":220},"codeSnippetWrapper",[218,222,125,225,125,125,238,125,125,246,125,125,269,125,125,282,125,125,294,125,125,306,125],{"id":223,"style":224},"codeSnippet","padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;",[226,227,229,233,234,237],"pre",{"style":228},"margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;",[62,230,232],{"style":231},"color: #0000ff;","Public"," ",[62,235,236],{"style":231},"Interface"," ICollection",[226,239,241,242,245],{"style":240},"margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;","  ",[62,243,244],{"style":231},"Inherits"," IEnumerable",[226,247,241,248,251,252,255,256,259,260,262,263,233,265,268],{"style":228},[62,249,250],{"style":231},"Sub"," CopyTo(",[62,253,254],{"style":231},"ByVal"," array ",[62,257,258],{"style":231},"As"," Array, ",[62,261,254],{"style":231}," index ",[62,264,258],{"style":231},[62,266,267],{"style":231},"Integer",")",[226,270,241,271,233,274,277,278,233,280],{"style":240},[62,272,273],{"style":231},"ReadOnly",[62,275,276],{"style":231},"Property"," Count() ",[62,279,258],{"style":231},[62,281,267],{"style":231},[226,283,241,284,233,286,288,289,233,291],{"style":228},[62,285,273],{"style":231},[62,287,276],{"style":231}," IsSynchronized() ",[62,290,258],{"style":231},[62,292,293],{"style":231},"Boolean",[226,295,241,296,233,298,300,301,233,303],{"style":240},[62,297,273],{"style":231},[62,299,276],{"style":231}," SyncRoot() ",[62,302,258],{"style":231},[62,304,305],{"style":231},"Object",[226,307,308,311],{"style":228},[62,309,310],{"style":231},"End"," Interface",[218,313,125,314,125],{"id":220},[218,315,125,316,125,125,323,125,125,328,125,125,348,125,125,353,125,125,370,125,125,378,125,125,389,125,125,400,125,125,411,125,125,426,125,125,435,125,125,444,125],{"id":223,"style":224},[226,317,318,233,320,322],{"style":228},[62,319,232],{"style":231},[62,321,236],{"style":231}," IDictionary",[226,324,241,325,327],{"style":240},[62,326,244],{"style":231}," ICollection, IEnumerable",[226,329,241,330,332,333,335,336,233,338,340,341,343,344,233,346,268],{"style":228},[62,331,250],{"style":231}," Add(",[62,334,254],{"style":231}," key ",[62,337,258],{"style":231},[62,339,305],{"style":231},", ",[62,342,254],{"style":231}," value ",[62,345,258],{"style":231},[62,347,305],{"style":231},[226,349,241,350,352],{"style":240},[62,351,250],{"style":231}," Clear()",[226,354,241,355,358,359,335,361,233,363,365,366,233,368],{"style":228},[62,356,357],{"style":231},"Function"," Contains(",[62,360,254],{"style":231},[62,362,258],{"style":231},[62,364,305],{"style":231},") ",[62,367,258],{"style":231},[62,369,293],{"style":231},[226,371,241,372,374,375,377],{"style":240},[62,373,357],{"style":231}," GetEnumerator() ",[62,376,258],{"style":231}," IDictionaryEnumerator",[226,379,241,380,382,383,335,385,233,387,268],{"style":228},[62,381,250],{"style":231}," Remove(",[62,384,254],{"style":231},[62,386,258],{"style":231},[62,388,305],{"style":231},[226,390,241,391,233,393,395,396,233,398],{"style":240},[62,392,273],{"style":231},[62,394,276],{"style":231}," IsFixedSize() ",[62,397,258],{"style":231},[62,399,293],{"style":231},[226,401,241,402,233,404,406,407,233,409],{"style":228},[62,403,273],{"style":231},[62,405,276],{"style":231}," IsReadOnly() ",[62,408,258],{"style":231},[62,410,293],{"style":231},[226,412,241,413,415,416,335,418,233,420,365,422,233,424],{"style":240},[62,414,276],{"style":231}," Item(",[62,417,254],{"style":231},[62,419,258],{"style":231},[62,421,305],{"style":231},[62,423,258],{"style":231},[62,425,305],{"style":231},[226,427,241,428,233,430,432,433,237],{"style":228},[62,429,273],{"style":231},[62,431,276],{"style":231}," Keys() ",[62,434,258],{"style":231},[226,436,241,437,233,439,441,442,237],{"style":240},[62,438,273],{"style":231},[62,440,276],{"style":231}," Values() ",[62,443,258],{"style":231},[226,445,446,311],{"style":228},[62,447,310],{"style":231},[12,449,450],{},"IList provides the ability to insert, remove and index items",[218,452,125,453,125],{"id":220},[218,454,125,455,125,125,462,125,125,466,125,125,480,125,125,484,125,125,498,125,125,513,125,125,530,125,125,540,125,125,551,125,125,561,125,125,571,125,125,585,125],{"id":223,"style":224},[226,456,457,233,459,461],{"style":228},[62,458,232],{"style":231},[62,460,236],{"style":231}," IList",[226,463,241,464,327],{"style":240},[62,465,244],{"style":231},[226,467,241,468,332,470,343,472,233,474,365,476,233,478],{"style":228},[62,469,357],{"style":231},[62,471,254],{"style":231},[62,473,258],{"style":231},[62,475,305],{"style":231},[62,477,258],{"style":231},[62,479,267],{"style":231},[226,481,241,482,352],{"style":240},[62,483,250],{"style":231},[226,485,241,486,358,488,343,490,233,492,365,494,233,496],{"style":228},[62,487,357],{"style":231},[62,489,254],{"style":231},[62,491,258],{"style":231},[62,493,305],{"style":231},[62,495,258],{"style":231},[62,497,293],{"style":231},[226,499,241,500,502,503,343,505,233,507,365,509,233,511],{"style":240},[62,501,357],{"style":231}," IndexOf(",[62,504,254],{"style":231},[62,506,258],{"style":231},[62,508,305],{"style":231},[62,510,258],{"style":231},[62,512,267],{"style":231},[226,514,241,515,517,518,262,520,233,522,340,524,343,526,233,528,268],{"style":228},[62,516,250],{"style":231}," Insert(",[62,519,254],{"style":231},[62,521,258],{"style":231},[62,523,267],{"style":231},[62,525,254],{"style":231},[62,527,258],{"style":231},[62,529,305],{"style":231},[226,531,241,532,382,534,343,536,233,538,268],{"style":240},[62,533,250],{"style":231},[62,535,254],{"style":231},[62,537,258],{"style":231},[62,539,305],{"style":231},[226,541,241,542,544,545,262,547,233,549,268],{"style":228},[62,543,250],{"style":231}," RemoveAt(",[62,546,254],{"style":231},[62,548,258],{"style":231},[62,550,267],{"style":231},[226,552,241,553,233,555,395,557,233,559],{"style":240},[62,554,273],{"style":231},[62,556,276],{"style":231},[62,558,258],{"style":231},[62,560,293],{"style":231},[226,562,241,563,233,565,406,567,233,569],{"style":228},[62,564,273],{"style":231},[62,566,276],{"style":231},[62,568,258],{"style":231},[62,570,293],{"style":231},[226,572,241,573,415,575,262,577,233,579,365,581,233,583],{"style":240},[62,574,276],{"style":231},[62,576,254],{"style":231},[62,578,258],{"style":231},[62,580,267],{"style":231},[62,582,258],{"style":231},[62,584,305],{"style":231},[226,586,587,233,589],{"style":228},[62,588,310],{"style":231},[62,590,236],{"style":231},[120,592,125,594,125],{"border":122,"cellSpacing":123,"cellPadding":123,"style":593},"width: 711px;",[127,595,125,596,125,610,125,621,125,632,125,642,125,652,125],{},[130,597,125,598,125,602,125,606,125],{},[133,599,601],{"width":600,"vAlign":136},133,"ArrayList",[133,603,605],{"width":604,"vAlign":136},414,"dynamically sized \nDim personList as New ArrayList() \npersonList.AddRange(New Person(){New Person(“dave”), New Person(“tom”)}",[133,607,609],{"width":608,"vAlign":136},162,"IList \nICollection \nIEnumerable \nICloneable",[130,611,125,612,125,615,125,618,125],{},[133,613,614],{"width":600,"vAlign":136},"Hashtable",[133,616,617],{"width":604,"vAlign":136},"collection whereby each item is represented by a numerical key",[133,619,620],{"width":608,"vAlign":136},"IDictionary \nICollection \nIEnumerable \nICloneable",[130,622,125,623,125,626,125,629,125],{},[133,624,625],{"width":600,"vAlign":136},"Queue",[133,627,628],{"width":604,"vAlign":136},"first in – first out queue with members Dequeue() (removes object at the top of queue), Enqueue() (adds object to end of queue), Peek() (returns object at the beginning of queue without removing it)",[133,630,631],{"width":608,"vAlign":136},"ICollection \nICloneable \nIEnumerable",[130,633,125,634,125,637,125,640,125],{},[133,635,636],{"width":600,"vAlign":136},"SortedList",[133,638,639],{"width":604,"vAlign":136},"similar to dictionary however items can be accessed by ordinal position",[133,641,620],{"width":608,"vAlign":136},[130,643,125,644,125,647,125,650,125],{},[133,645,646],{"width":600,"vAlign":136},"Stack",[133,648,649],{"width":604,"vAlign":136},"last in – first out queue using push, pop and peek",[133,651,631],{"width":608,"vAlign":136},[130,653,125,654,125,656,125,658,125],{},[133,655,156],{"width":600,"vAlign":136},[133,657,156],{"width":604,"vAlign":136},[133,659,156],{"width":608,"vAlign":136},[661,662,663],"strong",{},"System.Collections.Generic",[12,665,666],{},"Boxing\u002FUnboxing is a term that is used when a value type variable is stored in a reference type structure.  This occurs with all nongeneric types as they operate of the System.Objects type.",[12,668,669,670,672,673,675,676,679],{},"For example:\nDim ar as New ArrayList()\nar.Add(123) ‘boxing occurs\nDim i as Integer = CType(ar(0), Integer) ‘unboxing occurs",[22,671],{},"\n\u003Cp$1$2$3$4$5$6> ",[22,674],{},"\nUsing a generic collection:\n",[661,677,678],{},"Dim ar as New List(Of Integer)","\nar.Add(10) ‘no boxing\nDim i as Integer = ar(0) ‘no unboxing",[12,681,682],{},"The following is a list of interfaces within the System.Collections.Generic namespace: ICollections(Of T), IComparer(Of T), IDictionary(Of K, V), IEnumerable(Of T), IEnumerator(Of T), and IList(Of T).  There respective classes are as follows:",[120,684,125,686,125],{"border":122,"cellSpacing":123,"cellPadding":123,"style":685},"width: 657px;",[127,687,125,688,125,701,125,711,125,721,125,731,125,741,125,751,125,761,125,771,125],{},[130,689,125,690,125,694,125,698,125],{},[133,691,693],{"width":692,"vAlign":136},198,"Collection(Of T)",[133,695,697],{"width":696,"vAlign":136},274,"generic collection",[133,699,156],{"width":700,"vAlign":136},183,[130,702,125,703,125,706,125,709,125],{},[133,704,705],{"width":692,"vAlign":136},"Comparer(Of T)",[133,707,708],{"width":696,"vAlign":136},"compares two generic objects",[133,710,156],{"width":700,"vAlign":136},[130,712,125,713,125,716,125,719,125],{},[133,714,715],{"width":692,"vAlign":136},"Dictionary(Of K, V)",[133,717,718],{"width":696,"vAlign":136},"name\u002Fvalue pairs",[133,720,156],{"width":700,"vAlign":136},[130,722,125,723,125,726,125,729,125],{},[133,724,725],{"width":692,"vAlign":136},"List(Of T)",[133,727,728],{"width":696,"vAlign":136},"dynamically resizable",[133,730,156],{"width":700,"vAlign":136},[130,732,125,733,125,736,125,739,125],{},[133,734,735],{"width":692,"vAlign":136},"Queue(Of T)",[133,737,738],{"width":696,"vAlign":136},"FIFO collection",[133,740,156],{"width":700,"vAlign":136},[130,742,125,743,125,746,125,749,125],{},[133,744,745],{"width":692,"vAlign":136},"SortedDictionary(Of K, V)",[133,747,748],{"width":696,"vAlign":136},"sorted set of name\u002Fvalue pairs",[133,750,156],{"width":700,"vAlign":136},[130,752,125,753,125,756,125,759,125],{},[133,754,755],{"width":692,"vAlign":136},"Stack(Of T)",[133,757,758],{"width":696,"vAlign":136},"LIFO collection",[133,760,156],{"width":700,"vAlign":136},[130,762,125,763,125,766,125,769,125],{},[133,764,765],{"width":692,"vAlign":136},"LinkedList(Of T)",[133,767,768],{"width":696,"vAlign":136},"doubly linked list",[133,770,156],{"width":700,"vAlign":136},[130,772,125,773,125,776,125,779,125],{},[133,774,775],{"width":692,"vAlign":136},"ReadOnlyCollection(Of T)",[133,777,778],{"width":696,"vAlign":136},"readonly set of items",[133,780,156],{"width":700,"vAlign":136},[12,782,783,784,672,786,788],{},"Public Function Test(Of T)(ByRef o1 as T, ByRef o2 as T) as T\n  ‘do something\nEnd Function",[22,785],{},[22,787],{},"\nIt is possible to establish constraints with respect to the type of T.  The following is a complete list of the types of constraints:\nOf T as Structure > the type parameter must be a value type (ie. structure)\nOf T as Class > the type parameter must be a reference type (i.e. classes)\nOf T as New > the type parameter must have a default constructor\nOf T as NameOf BaseClass > the type parameter must be derived from the class specified by NameOfBaseClass\nOf T as NameOfInterface > the type parameter must implement the interface specified by NameOfInterface",[12,790,791,792,672,794,796],{},"’new items must have a default constructor\nPublic Class TestClass(Of T as New)\n  ‘stuff here\nEnd Class",[22,793],{},[22,795],{},"\nThe term generic can apply to Interfaces as well. In any case the interface will define the contract that the implementing class must adhere to.  When implementing a generic interface the supporting type specifies the placeholder type:",[12,798,799],{},"Public Interface IMyInterface(Of T)\n  Function Add(ByVal x as T, ByVal y as T) as T\nEnd Interface",[12,801,802],{},"Public Class MyClass\n  Implements IMyInterface(Of Integer)",[12,804,805],{},"Public Function Add(ByVal x as Integer, ByVal y as Integer) as Integer\n  Return x + y\nEnd Function",[12,807,808,809,811],{},"By all means utilize the generic collection namespace over the system.collection nongeneric namespace.  In addition to improved performance(avoiding boxing\u002Funboxing) your code will avoid type-safety issues of earlier releases of .NET.",[22,810],{},[812,813],"img",{"style":814,"src":815,"alt":76},"display: none;","\u002Farticles\u002Fimages\u002Ffeet.jpg",{"title":76,"searchDepth":77,"depth":77,"links":817},[],"2015-04-20T08:07:15.7900000-04:00",null,{},"\u002Farticles\u002Fgenericcollection-usage-in-the-net-framework",{"title":107,"description":819},"articles\u002Fgenericcollection-usage-in-the-net-framework",[88],"HVNZe5xrJpyaU0pq3szPwlINvtqAJ9ix-JzG7RGvBtg",{"id":827,"title":828,"author":7,"body":829,"createdAt":984,"description":819,"extension":80,"img":981,"meta":985,"navigation":83,"path":986,"seo":987,"stem":988,"tags":989,"updatedAt":984,"__hash__":991},"articles\u002Farticles\u002Fstrong-names-and-signing-assemblies-net.md","Strong Names and Signing Assemblies .NET",{"type":9,"value":830,"toc":982},[831,834,841,850,937,944,947,962,965,968,979],[12,832,833],{},"Digital signatures are used to verify the integrity of data being passed from the originator (the signer) to a recipient (the verifier). The signatures are generated and verified using public key cryptography.",[12,835,836,837,840],{},"The ",[661,838,839],{},"signer"," of a message has a pair of cryptographic keys: a public key, which everyone in the world knows, and a private key, which is kept secret by the signer.",[12,842,836,843,846,847,849],{},[661,844,845],{},"verifier"," knows only the public key, which is used to verify that the signer knew the private key and the message.",[22,848],{},"\nStrong Named Assemblies",[851,852,853,857,860,863,866,869,872,875,878,881,884,898,901,904,907,919,922,925,928,931,934],"ul",{},[854,855,856],"li",{},"Strong names offer a powerful mechanism for giving .NET Framework assemblies unique identities.",[854,858,859],{},"The strong name for an assembly consists of five parts:",[854,861,862],{},"a public key (RSA cryptographic public key that helps verify the assembly's authenticity)",[854,864,865],{},"a simple name (text string—usually the name of the file (without the extension) that contains the assembly)",[854,867,868],{},"a version (four-part version number, in the form of Major.Minor.Build.Revision (i.e.  1.0.0.1)",[854,870,871],{},"an optional culture (Target audience for the assembly, such as \"neutral\" (default audience), \"en-us\" (English – United States) or \"fr\" (France) etc.)",[854,873,874],{},"and an optional processor architecture (Defines the assembly's format, such as MSIL (intermediate language) or x86 (binary for Intel x86 processors)",[854,876,877],{},"An assembly is strong-named during the build process using the private key which corresponds to the public key in the strong name.  The strong name can be verified using the public key.",[854,879,880],{},"The .NET Framework verifies the strong name signature.  If it cannot be verified the Framework will not load the assembly.",[854,882,883],{},"The above has one exception.  Strong named assemblies that are used in the GAC (Global Assembly Cache) are not verified each time the .NET Framework loads them.  The assemblies in the GAC are verified only at the time they are installed in the GAC as the GAC already is locked down and assemblies can only be installed by an individual who has admin permissions.  Once an assembly was installed in the GAC, it's considered to be safe and being verified earlier (during gacutil.exe phase)",[854,885,886,887,892,893,897],{},"Why use strong names…Strong names prevent others from spoofing your code.  i.e. a malicious user cannot modify your code and successfully re-sign it.  ",[888,889,891],"a",{"href":890},"http:\u002F\u002Fwww.codeproject.com\u002Fdotnet\u002FStrongNameExplained.asp","Strong names"," are required to store shared assemblies in the global assembly cache (GAC). This is because the GAC allows multiple versions of the same assembly to reside on your system simultaneously, so that each application can find and use its own version of your assembly. This helps avoid ",[888,894,896],{"href":895},"http:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FDLL_hell","DLL Hell",", where applications that may be compiled to different versions of your assembly could potentially break because they are all forced to use the same version of your assembly.",[854,899,900],{},"Strong name signatures do not contain any reliable information about the publisher.  In order to trust keys from other organizations ensure you have a secure channel to get their public key.  Remember that through the public key the strong named assembly can be verified that it was signed with the corresponding private key.  Hence strong names are secure only when the strong name private key is kept secure.",[854,902,903],{},"Strong-name signing is a good idea for most applications, especially those that are deployed over a network or any medium not fully controlled by the deployer.",[854,905,906],{},"All assemblies referenced by a strong-named assembly must also be strong-named. If you reference an assembly written by a third party that is not strong-name signed, you cannot strong-name sign your assembly.",[854,908,909,910,912,913,915,916,918],{},"Strong-name signing makes servicing more complicated. Under current versioning policy, an assembly will always attempt to load the exact version of the assembly it was built against. If, for example, your application was built against version 1.0.0.0 of a strong-named assembly and you fix a bug in the assembly, bumping the version number to 1.0.0.1, the existing application will not find the updated assembly.",[22,911],{},"\nThere are a few ways to deal with this situation. You can rebuild the application against the new assembly. Obviously, this is an annoying process for just picking up a bug fix and it may not be an option in some situations. Still, it works fine when your code is not widely deployed or the assembly being serviced is not widely shared across applications.",[22,914],{},"\nAnother option is if the assembly is installed in the GAC, you can use publisher policy to redirect loads for version 1.0.0.0 to version 1.0.0.1. However, publisher policy is complicated.",[22,917],{},"\nYet another option is to fix the bug and not change the assembly version number, so existing applications can still find the assembly. This is the approach the .NET Framework uses for bug fixes, although it’s not appropriate for new features or anything that breaks compatibility. If you are adding new features, you should bump the assembly version up and have applications rebuild to opt in to the new features.",[854,920,921],{},"Assemblies loaded in the GAC perform better as they are loaded from central system space and the verification process has already been completed.  The strong name ensures correct component versioning helping to prevent components with the same name from conflicting with each other.",[854,923,924],{},"To install assemblies in the GAC they must be strong named(signed).",[854,926,927],{},"Delay signing allows you to generate a partial signature during development with access only to the public key. ",[854,929,930],{},"The private key can be stored securely out of the hands of the developers and used to apply the final strong name signature just before shipping your code. ",[854,932,933],{},"Use the public key to delay sign your assemblies during development.",[854,935,936],{},"Because the assemblies are not fully signed yet, you’ll also have to configure your development machines to skip strong name signature verification for your key—otherwise, the .NET Framework will not allow you to load the delay-signed assemblies.  You must configure the .NET Framework to skip verification for the delay-signed assemblies using your public key. To do this, you use the sn.exe tool again. i.e. sn –Vr {assemblyName} ",[12,938,939,940,943],{},"Another options…to configure your development machine to ",[661,941,942],{},"skip all verification"," for delay signed assemblies signed with a particular key.  Using sn –T {assemblyName} will give you the public key token.  Then execute the following to skip strong name verification for any assembly using that public key token sn – Vr *,{public token}  Any assembly delay signed with that public key will now skip strong name signature verification and run on your development machine.  It should never be done on production computers because it opens up those machines to assembly spoofing attacks. ",[12,945,946],{},"Another technique to acquire the public key token is to use the public key file alone.\ni.e. sn – tp {publickeyfile}",[851,948,949],{},[854,950,951,952,957,958,961],{},"When you are ready to ship your code, use the (well guarded) private key to apply the final strong name signature to your delay-signed assemblies.  sn –R {assemblyName} {your key file}  Now your assembly has a full signature.  It is possible to use command line “",[888,953,956],{"href":954,"target":955},"http:\u002F\u002Fwww.microsoft.com\u002Fresources\u002Fdocumentation\u002Fwindows\u002Fxp\u002Fall\u002Fproddocs\u002Fen-us\u002Ffor.mspx?mfr=true","_blank","For","” command to iterate over each dll saving a lot of typing\ni.e. for {%variable|%%variable} in (set) do command ",[62,959,960],{}," CommandLineOptions","\nfor %f in (*.dll) do sn –R %f MyKeyFile.snk",[12,963,964],{},"if you use this within a batch file replace %f with %ff",[12,966,967],{},"Additional Notes:",[851,969,970,973,976],{},[854,971,972],{},"Create a strong name key (often your organization will already have one established)\ni.e. sn –k MyKeyFile.snk  This creates a strong name key pair (both public and private keys in the same file)",[854,974,975],{},"Developers typically only need the public key portion.  sn –p MyKeyFile.snk MyKeyFilePublic.snk  This extracts the public key and creates a new file MyKeyFilePublic.snk.  At this point, MyKeyFile.snk should be put in a save location and available to Administrators only",[854,977,978],{},"To access the public key value and token sn – tp MyKeyFIlePublic.snk.  At this point, store the output in a text file somewhere.  We will use both the public key value and token.",[812,980],{"style":814,"src":981,"alt":76},"\u002Farticles\u002Fimages\u002Fstrong.jpg",{"title":76,"searchDepth":77,"depth":77,"links":983},[],"2015-04-20T08:07:15.6200000-04:00",{},"\u002Farticles\u002Fstrong-names-and-signing-assemblies-net",{"title":828,"description":819},"articles\u002Fstrong-names-and-signing-assemblies-net",[990],"visualstudio","ObgnfB7dmw3KHuTDCYm1Z1HRlE1trT6XiP7-DYrKozk",1781574765744]