Embedding a file in an assembly

Why? I have some unit tests that need to run off of some pre-defined static XML data and while the tests run fine so long as the file and assembly are in the same location as soon as the assembly is moved elsewhere they start to fail, “file not found” exceptions.
So if the file is embedded in the assembly I don’t need to worry about where it is located anymore.

The assumption, in the following, is that the file is XML that has been serialised from an existing List and is being reloaded back into the same, and that the file is in the current assembly. “_states” is a global variable.

So here are the basic steps for this:

In your Solution Explorer view right-click on the file, in this case “state.xml”, and view it’s Properties, make sure that the “Build Action” is set to “Embedded Resource”, optionally set the “Copy to Output Directory” to “Do not copy”.

Once this has done then the file can be loaded and copied into the required object using:

GetFileFromAssembly

An important thing to remember is that the “Namespace” prefix to the file is the “Default namespace” as entered in the Application properties tab and not the namespace used in the referencing file.

You can reference the file, if it’s in a sub-folder by adding the folder just after the namespace, e.g.

GetFileFromAssemblyNamespace

 

 

Advertisements

Wrong version of C:\Windows\System32\ATL100.dll

Having problems with this DLL on Windows 7?

In my case this stopped notepad.exe from saving files smoothly, okay how many people use notepad still? The files did save but you had to click through a couple of Window’s dialogs saying that the file was running on the wrong version of Windows. Quite why the 64 bit of notepad was running this is beyond the level of investigation I put into this.

I tried to uninstall it using regsv32 but that also complained it was the wrong version. Right clicking on the file and examining the properties was of no help at all, so maybe it is corrupt? Looking at the ATL110.dll we see that that it has been signed by Microsoft, my version of ATL100.dll didn’t even offer up the tab! Should have taken a screen grab before I replaced it.

atl110 properties
Digital signatures of the atl110.dll

Trying to find similar issues, either via Google or Bing, offered up plenty of sites who would provide a copy – but without having any checksum to work with no way was I downloading them! Also no one seemed to provide any solution, maybe I can’t construct the correct query or I should have gone further into the results.

Next was to try and rollback the file, not an option as by the time I’d found the issue I’d helpfully cleared out, read reset, my system restore and windows backups so they were no use. Running the System File Checker (sfc.exe) showed that there were no problems with the Windows installation.

Okay so back to basics and try and figure it out, with vague recollection of my VC++ days (very vague and no fun) we find the DLL is part of the Active Template Library (the ATL in the file name) part of the C++ 2010 Redistributable package (the 100 in the file name).

To resolve the issue I downloaded the 64 and 32 bit 2010 packages using this link: https://support.microsoft.com/en-us/kb/2977003

First off I ran each installer in repair mode, no luck the error still persisted. The atl100.dll still wasn’t right. So I took the sledgehammer to it and deleted it. Then I ran each installer twice, first removing the package and then to re-install. I didn’t reboot in between removing and installing but it is probably advisable. Certainly once you have re-installed then a reboot would be good practice.

Sorted!

Windows 7: Drag and drop not working

Trying to drag a file, or folder, in Windows Explorer and nothing is happening?

The solution I found was to left-click on the item, keep the button depressed, and then press the “Esc”ape key. Low and behold you can now drag and drop the item.

Absolutely no idea what causes this to stop working.

Further information, but no root cause, here.

How to search a MS-SQL DB for text in a stored procedure (updated)

Looking for a column that’s directly referenced by a stored procedure (sproc) then try running this query:

SELECT SProcName = OBJECT_NAME(object_id), Definition
FROM sys.sql_modules WHERE definition LIKE '%SEARCH_CRITERIA%' 
ORDER BY SProcName;

This replaces the previous post.

Important
If using MS SQL Server Management Studio 17+ then you need to make sure that the following option is checked:

Tools>Options>Query Results>SQL Server>Results to Grid>Retain CR/LF on copy or save

Otherwise carriage returns are lost. After checking the option you need to restart SSMS, for it to take effect on any queries.

linked servers in MS SQL

EXEC sp_addlinkedserver @server='LKSRV_SYS', @srvproduct = 'SQLServer OLEDB Provider', @provider = 'SQLOLEDB', @datasrc ='SERVERNAMEHERE'
EXEC sp_addlinkedsrvlogin 'LKSRV_SYS', 'False', 'sa', 'sa', 'SA PASSWORD HERE'
GO

And if you get any errors running the above, because users are associated with the linked server then run this:
sp_dropserver 'LKSRV_SYS', 'droplogins'