Issue/conflict with system.runtime.compilerservices.unsafe

Add-in Express™ Support Service
That's what is more important than anything else

Issue/conflict with system.runtime.compilerservices.unsafe
 
Subscribe
Ben Gijsen




Posts: 19
Joined: 2008-04-18
I've a problem which may be a little off-topic as it concerns co-operation between ADX and other software, but I think more developers run into similar problems.

So I created a very simple Word AddIn to test combination with the use of Azure Files. To addinmodule.vb I've just added:

 Private Sub AdxRibbonButton1_OnClick(sender As Object, control As IRibbonControl, pressed As Boolean) Handles AdxRibbonButton1.OnClick
        Dim ascShare As ShareClient, strShare As String

        Try
            strShare = "opsdata01"
            ascShare = New ShareClient("DefaultEndpointsProtocol=https;AccountName=... account ....;AccountKey=... key ....;EndpointSuffix=core.windows.net",strShare)

            If ascShare.Exists.Value Then
                MsgBox("Yes, share " + strShare + " is there")
            Else
                MsgBox("No, share " + strShare + " was not found")
            End If

        Catch excErr As Exception
            MsgBox("Error: " + excErr.Message)

        End Try

    End Sub


When I click the button an exception is raised (Source: System.Memory) with text
Could not load file or assembly 'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)


This only happens when I use Add-In Express (standard, latest version). If I create a basic Windows Forms application with the same body in a button's handler it works without any issue.

Any idea how to solve this?

I already tried redirecting the assembly's reference to 4.0.6.0, but that gives the same issue (only another number).
Installing NuGet System.Runtime.CompilerServices.Unsafe 3.5 solves it in my development enviroment but I get downgrade warnings and when I create a .msi, the deployed version again has the same issue.

Using: .Net Framework 4.7.2, VS 16.11, Add-In-Express adxnet-v905-b4661-vs-std, NuGet package Azure.Storage.Files.Shares 12.8
Posted 22 Oct, 2021 10:11:18 Top
Andrei Smolin


Add-in Express team


Posts: 17953
Joined: 2006-05-11
Hello Ben,

What .NET Framework version is ShareClient built for?

Regards from Poland (CEST),

Andrei Smolin
Add-in Express Team Leader
Posted 25 Oct, 2021 02:53:03 Top
Ben Gijsen




Posts: 19
Joined: 2008-04-18
Hi Andrei,

Thanks for your quick response. Currently I'm using .Net Framework 4.7.2 (I summed up all versions of VS, ADX, etc at the bottom of my post). I've installed other versions (Core and Net5), but can't select these for my ADX project.

In the mean time I already tried various suggested solutions:

  • Binding Redirect assembly versions , doesn't seem to do anything (at least not in my case; tried with option "Auto-generate " on and off for the project).
  • Using different versions by specifying CodeBase solved the problem when I run (debug) the application from VS, but when I created a .msi file (to which I added the app.config file and the alternative .dll as assembly) this installed correctly, but threw the error again.


(BTW: I used the "Create Setup project" from the Add-in Express menu.

Regards, Ben
Posted 25 Oct, 2021 04:05:08 Top
Andrei Smolin


Add-in Express team


Posts: 17953
Joined: 2006-05-11
Hello Ben,

Select ShareClient in References: what value do you have in the Runtime Version property?

Regards from Poland (CEST),

Andrei Smolin
Add-in Express Team Leader
Posted 25 Oct, 2021 07:32:59 Top
Ben Gijsen




Posts: 19
Joined: 2008-04-18
Hi Andrei,

The ShareClient is a class from the Azure.Storage.Files.Shares package which is installed in VS via NuGet, so I don't see any of the actual dlls. In the reference list it has a different icon from the rest (eg. ADX), and if I open the properties window, nothing shows up.

Regards Ben
Posted 25 Oct, 2021 08:03:07 Top
Andrei Smolin


Add-in Express team


Posts: 17953
Joined: 2006-05-11
Hello Ben,

You have a reference to a DLL responsible for this functionality. I suppose, the reference name is Azure.Storage.Files.Shares.

Say, the reference named AddinExpress.MSO.2005 provides your add-in with the functionality of Add-in Express. Click it and press F4 to open the Properties window where you'll see that the Runtime Version is v.2.0.50727.

Regards from Poland (CEST),

Andrei Smolin
Add-in Express Team Leader
Posted 25 Oct, 2021 09:03:17 Top
Ben Gijsen




Posts: 19
Joined: 2008-04-18
Hi Andrei,

Yes I have that reference but it works different. There's a different icon next to it in the list in the Solution Explorer and I get an empty list of Properties. For ADX I can get a list, which e.g. tells me its Version (9.5.4661.0), Runtime Version (v2.0.50727) and more.

On the Project Page, the reference to Azure.Storage.Files.Shares also is not in the upper pane labelled References (that's where I see ADX, the Office dlls and varius System dlls), but it's only visible in the lower pane labelled Imported namespaces where I have selected it, otherwise I (obviously) get the error "Type 'ShareClient' is not defined".

BTW: is there a way I can include a picture from disk (screenprint) in my response; the IMG button only allows a http:// url for adding.

Regards Ben
Posted 25 Oct, 2021 09:21:03 Top
Andrei Smolin


Add-in Express team


Posts: 17953
Joined: 2006-05-11
Hello Ben,

Could you send a sample project to the support email address? I'll install Azure SDK for .NET and test the project.

Regards from Poland (CEST),

Andrei Smolin
Add-in Express Team Leader
Posted 25 Oct, 2021 10:49:04 Top
Andrei Smolin


Add-in Express team


Posts: 17953
Joined: 2006-05-11
Hello Ben,

Thank you for the project. I reproduce the issue. Upon inspection, the System.Runtime.CompilerServices.Unsafe.dll file supplied is a .NET Core file while the project is based on .NET Framework. Maybe, they have a .NET Framework version of that file?

Just recently we posted an explanation why Add-in Express won't support .NET 5-6, etc.; see https://www.add-in-express.com/forum/read.php?FID=5&TID=16208.

Regards from Poland (CEST),

Andrei Smolin
Add-in Express Team Leader
Posted 26 Oct, 2021 08:44:24 Top
Ben Gijsen




Posts: 19
Joined: 2008-04-18
Hi Andrei,

Many thanks for your support so far. I've also read the post (very funny how this has been implemented; you must feel frustrated having to spend so much time on something you actually don't want to care about) .Now I also understand why the latest .Net Framework version I can select is 4.7.2 (which I did when starting the project).

I tried to find a .NET Framework version but did not find it, all references end up with the NuGet package. I did however find out that after installation and de-installation of the NuGet package 4.5.3 there were several .dll files (the pacake has for each version the subfolers lib and ref which in turn have subfolders net461, netcoreapp2.0, netstandard1.0 and netstandard2.0). Using gacutil I could add one (only from the lib collection, I've tried both the net461 and netstandard2.0 versions). When I tried to load one from the ref collection I got the error "An attempt was made to load a Program with an incorrect format"

The effect was that I could run the application in VS without any modifications to app.config. The compilerservices dll still doesn't show up in the application project references, but both (probably the one implicitly added and the one I registered) are present in the "Detected Dependencies" list of the Setup Project and there I can also examine their Properties. As the implicitly installed version (4.0.5.0) in its source refers to ...\ref\netstandard2.0... I've loaded the old one from ...\lib\netstandard2.0...

However when creating a .msi I obviously got a problem as both were targeted at the same output destination. So I created an extra folder for the old one and set its Register property to vsdraCOM.

On my target machine the add-in installed without any errors (also checked the ADX log files), but I still got the error message from my initial post (either with the Register property set to DoNotRegister or COM).
Interesting detail: if I exclude the newer version (4.0.5.1) I get the same error but for the excluded version.

It looks like the problem should be solved if the additional .dll could also be loaded, but of course I don't have gacutil on my target machine (and don't think the users have either).

Can this help you in finding a solution (I'm obviously not nearly as experienced with all these installing intricacies as you are)?
Posted 27 Oct, 2021 04:24:05 Top