Upgrading GP Addin Mods to use EF6

After adding the configuration sections to Dynamics.exe.config

<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>

and adding the connnection strings section, the following error  occurs…

Top-level Exception
Type: System.InvalidOperationException
Message: The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer' registered in the application config file for the ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.
Source: EntityFramework
Stack Trace: at System.Data.Entity.Infrastructure.DependencyResolution.ProviderServicesFactory.GetInstance(String providerTypeName, String providerInvariantName)
at System.Data.Entity.Internal.AppConfig.<;.ctor>b__2(ProviderElement e)
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at System.Data.Entity.Internal.AppConfig.<;.ctor>b__1()
at System.Lazy`1.CreateValue()
at System.Lazy`1.LazyInitValue()
at System.Lazy`1.get_Value()
at System.Data.Entity.Internal.AppConfig.get_DbProviderServices()
at System.Data.Entity.Infrastructure.DependencyResolution.AppConfigDependencyResolver.RegisterDbProviderServices()
at System.Data.Entity.Infrastructure.DependencyResolution.AppConfigDependencyResolver.GetServiceFactory(Type type, String name)
at System.Data.Entity.Infrastructure.DependencyResolution.AppConfigDependencyResolver.<;>c__DisplayClass1.<GetService>b__0(Tuple`2 t)
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at System.Data.Entity.Infrastructure.DependencyResolution.AppConfigDependencyResolver.GetService(Type type, Object key)
at System.Data.Entity.Infrastructure.DependencyResolution.ResolverChain.<;>c__DisplayClass3.<GetService>b__0(IDbDependencyResolver r)
at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
at System.Data.Entity.Infrastructure.DependencyResolution.ResolverChain.GetService(Type type, Object key)
at System.Data.Entity.Infrastructure.DependencyResolution.CompositeResolver`2.GetService(Type type, Object key)
at System.Data.Entity.Infrastructure.DependencyResolution.DbDependencyResolverExtensions.GetService[T](IDbDependencyResolver resolver, Object key)
at System.Data.Entity.Core.EntityClient.EntityConnection.ChangeConnectionString(String newConnectionString)
at System.Data.Entity.Core.EntityClient.EntityConnection..ctor(String connectionString)
at canford.SalesOrderProcessingEntities.GetSqlConnection(String ConnectionString)

Seems that as I have all the data access defined in its own class lib, there is no code causing a reference to force the correct EntityFramework.SqlServer.dll to be pushed to the build output.

So this hack did the job for now and I’ve posted this here to come back to another time.

Stack overflow post: EntityFramework.SqlServer.dll not is getting added

private void FixEfProviderServicesProblem()
{
// The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer'
// for the 'System.Data.SqlClient' ADO.NET provider could not be loaded.
// Make sure the provider assembly is available to the running application.
// See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.
var instance = System.Data.Entity.SqlServer.SqlProviderServices.Instance;
}

UWP Serial Port Missing Bytes, Bytes Written Windows IoT

Whilst writing a PCX format, 1 bit per pixel (1bpp) byte array to a serial port FTDI USB serial adapter using WinRT/UWP, on a Laptop (using for developing before deploying to RPi2), it kept failing to work correctly. The serial port was going to the RS232 input of a Zebra Thermal printer, the PCX representing a bitmap to print. The code below was used to push the byte array through to the serial port, after failing to find any answers on line and eliminating other possibilities, a logic analyser on the serial port uncovered the issue. The bye array was not complete.  

public async Task Print(byte[] bytesTosend)
{
using (DataWriter dataWriteObject = new DataWriter(serialPort.OutputStream))
{
await WriteBytesAsync(dataWriteObject, bytesTosend);
if (dataWriteObject != null)
{
dataWriteObject.DetachStream();
}
}
}

public async Task WriteBytesAsync(DataWriter dataWriteObject, byte[] bytesTosend)
{
Task<UInt32> storeAsyncTask;
int offset = 0;
do
{
int buffersize = bytesTosend.Length;
//if (buffersize > 1000) { buffersize = 1000; }
byte[] sendBuffer = new byte[buffersize];
System.Buffer.BlockCopy(bytesTosend, offset, sendBuffer, 0, buffersize);
dataWriteObject.WriteBytes(sendBuffer);
storeAsyncTask = dataWriteObject.StoreAsync().AsTask();
UInt32 bytesWritten = await storeAsyncTask;
offset += buffersize;
} while (offset < bytesTosend.Length);
}

Running the code in debug and looking at the length of the byte array, compared to the bytes sent, the problem is clear to see. The image is 200x200 pixels, so at 1bpp this is 200/8 bytes wide * 200 rows = 5000 bytes.

Indeed the byte array is 5000 bytes to send, but wait look at how many bytes have actually been sent, 4096 bytes! Somewhere four bytes have gone missing, thus the printer is awaiting the complete image and does not print.

 Byte writing code showing the debug values

There seems to be no way to flush the buffer or any other methods on the DataWriter that could be used to force these extra bytes out, anyway the missing bytes might not necessarily from the end of the array. There is a FlushAsync method, however that returns a “not implemented” exception – gotta love coding on this platform…

So perhaps by gut says this is actually some kind of serial buffer overflow problem. Some support to this theory is that writing low numbers of bytes to the serial port works just fine.

 

Fixing serial port write on UWP application missing bytes

MakerFaire is in three weeks time so a solution is needed quick, not time to raise with Microsoft. As smaller writes works, and my suspicion is a buffer overflow, the solution is to uncomment the commented out line in the code above. This will break any byte array larger than one thousand bytes into chunks and send them one chunk at a time.

Running the code worked, printing the image perfectly every time.

This seems to be how it is in the world of Windows IoT and UWP at the moment, if feels like the first couple of years of the first versions of .NET all over again!

Visual Studio 2015 Licence Error (0x00000002): Unable to save downloaded online licence

I just experienced this error in Visual studio with a sole button to “close visual studio”.

image

It happened on opening projects. I ended up having to log out of my MSDN account on that same error window and back in again before it would allow me forward.

Clicking the “Check for an updated license” only worked after that logout and in process.

Seems others have seen this too Visual Studio 2015 fails to check license (unable to save downloaded online license)

I wonder if it is a transient connectivity issue with license webservices or a deeper issue of some kind.

What's Your Setup?

To the skaters out there you’ll recognise the familiar phrase “What’s Your Setup?”.

Your "Setup" is all of the pieces and parts that go into your skateboard. It's pretty rare to find two skaters with the same setup, and hearing about what other skaters use, and why, is a great way to learn about new options, and pick fights. [ref]

For developers using Visual Studio it is a similar story. I am a generalist developer, very lucky to have work types split over developing and supporting; embedded microcontroller programming, ERP Add-in development, Windows Forms, WPF, ASP.NET web applications and more. I also work 50-50, VB.NET-C#.

Visual Studio has embraced a pluggable architecture (MEF), allowing the base product to be changed with plug-in extensions. I thought it might be interesting to look at how I have set my Visual Studio up. I work over many machines between work and home and over virtual machines. My setup is consistent, helped by the user awareness that Visual Studio has these days. Some of these extensions I’ve picked up from co-workers, or going to developer talks, others from stumbling on them.

Colour Theme

Visual Studio with dark look

[More]

Currently running the “dark” colour theme, I resisted for a couple of years, convinced that I preferred the original light version but I’m a total convert now. Some of the windows clearly have not yet been updated to properly flow with the theme but I live with that. Dark theme makes the syntax highlighting punch out much more (for me) and is less tiring on the eyes (I think).

At work I use Team Foundation Server for source control and Application Lifecycle Management (ALM) , and Git extensions for source control on home projects.

Auto Shelve

TFS Auto Shelve for Visual Studio 2015

This every x mins shelves my current workspace into a shelf set, the solves the auditors worry over hardware failing and thus us loosing too many days or hours work since the last check in. It is amazing how often a quick update or change leads to a project being open and worked on for a couple of weeks, you never know when that SSD might go pop…

It also makes it easy for others in the team to pick my work in progress up, say after a huddle, with no effort from me.

Spell Checker

Visual Studio Spell Checker

I can’t spell, look at the comments and variable names in my circa 2003-7 code and you see why I need this feature. The spell checker is awesome in this add in, after remembering to switch it to EN-GB from EN-US. Just look at all the lovely settings, it is very code aware.

Spell Checker options windowsSpell Checker options windows

RegEx Tester

Regex Tester

RegEx comes into development a lot, I personally love creating regular expressions, this tool lets them be tested using the same regex engine as the code, in a dockable window right inside the IDE!

Regex Tester window

Productivity Power Tools

Productivity Power Tools 2015

This extension has biggest impact on my experience. Yes, when you first start using it, it adds lots of extra visual noise into the development environment, but once you get used to it, your productivity will increase and you’ll miss it if its not installed. I work with the tabs on the left, they are colour coded by project and sorted by project. The names on the tabs are much easier to see for the files and it just makes sense with a wide screen monitor and lots of files open to have them there.

Productivity Power Tools 2015 optionsProductivity Power Tools 2015 options

Productivity Power Tools 2015 optionsProductivity Power Tools 2015 options

Coloured tabs and left hand tabs well

Application Insights

Application Insights Tools for Visual Studio

Important for quickly diagnose any problems in your live application.

The following are other standard extensions that are important but next tier down in my frequency of use, i.e. I can work without them most of the time.

Power shell tools for Visual Studio 2015Web essentials 2015Visual  Studio installer projectsimageTypescript for Microsoft Visual Studio

For hardware projects

For work with Raspberry Pi, Arduino hardware and other maker activities I have these two

Arduino IDE

Windows IoT core TemplatesGIT

Templates

I also have templates installed for developing Microsoft Dynamics Plugins, see: Visual Studio 2015 Dynamics GP Addin Project Templates Install

Dynamics GP Project Templates for VS2015

General use

I’m loving the visual studio experience, being able to hover and see the out of view start of code blocks,

Code lenses

The new code lens type features and light bulb suggestions are great, although i have a gripe that it is far too slow compared to the old rename variable.

The built in diagnostics are really handy for looking at object disposal and performance tracing.

image

Extensions give so much more, as does delving into settings to see what is there.

I will add to this post as I think of other things I do with Visual Studio…