RegAsm error RA0000 Could not load file or assembly on Network Drive - regasm

I experience a problem using a batch file to call Regasm on framework 4 on a network drive.
It works correctly when the dll is on a local drive.
The message is Could not load file or assembly filename.dll or one of its dependencies. Operation is not supported.
The problem is discussed
here ad "Darrens Developer Diary"
however editing the config as described does not help
I also tried the advice
here
which differs in the line
<loadFromRemoteSources="true"/>
with this I received a different error
"The system cannot execute the specified program"
The DLL used to use Framework 2, but I unregistered it using Framework 2 Regasm.
Here is the regasm.exe.config
<?xml version ="1.0"?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<requiredRuntime safemode="true" imageVersion="v4.0.30319" version="v4.0.30319"/>
<supportedRuntime version="v4.0" sku="client" />
</startup>
<runtime>
<loadfromremotesources enabled="true"> </loadfromremotesources>
</runtime>
</configuration>
Here is the command in my batch file
Z:
cd foldername
c:\WINDOWS\Microsoft.Net\Framework\v4.0.30319/regasm /verbose /codebase /tlb: .\SBD.CommBridge.tlb .\SBD.ComBridge.dll

The correct line in regasm.exe.config is
<loadFromRemoteSources enabled="true"/>
the case matters

Related

XDT Transform not working for applicationHost.xdt on Azure - Environment variables are ignored

It seems like environment variables are being ignored in my xdt transform for applicationHost.
I've created the following file applicationHost.xdt on azure in the \home\site folder. It does NOT perform the transform on applicationHost.config
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">>
<system.applicationHost>
<applicationPools>
<add name="%WEBSITE_SITE_NAME%" xdt:Locator="Match(name)">
<recycling disallowOverlappingRotation="true" xdt:Transform="Insert" />
</add>
<add name="%WEBSITE_IIS_SITE_NAME%" xdt:Locator="Match(name)">
<recycling disallowOverlappingRotation="true" xdt:Transform="Insert" />
</add>
</applicationPools>
</system.applicationHost>
</configuration>
If I adjust the %WEBSITE_SITE_NAME% to say "dev-mysitename.com" the transforms work properly.
Why are the Environment variables not working properly? I need this to work so my different environments will work properly.
You cannot use Environment Variables like this. Its just not possible.

Update Build number in App config xml file on build pipeline

I have a build pipeline in Azure DevOps, I need to update the build number in my apconfig exe file that will be $(Build.BuildNumber).
I just tried this way:
Adding a variable name = BuildNumber value = $(Build.BuildNumber).
And in my apconfig.exe file have a key same like <add key="BuildNumber" value="1812201901" />.
Why I have tried like this way: thinking like it will update in the config file if variable name match with the key.
But it is not working. can anyone please help? I have just started in CI/CD.
Update Build number in App config xml file on build pipeline
Just like the Shayki said, using the Replace Tokens extension should be the directly way to resolve this issue.
But since you need to request to get this extension, as workaround, you could also use power shell scripts to resolve this issue, you can check below my test powershell scripts:
$currentDirectory = [IO.Path]::GetDirectoryName($MyInvocation.MyCommand.Path)
$appConfigFile = [IO.Path]::Combine($currentDirectory, 'App.config')
$appConfig = New-Object XML
$appConfig.Load($appConfigFile)
foreach($BuildNumber in $appConfig.configuration.add)
{
'name: ' + $BuildNumber.name
'BuildNumber: ' + $BuildNumber.value
$BuildNumber.value = '123456789'
}
$appConfig.Save($appConfigFile)
As result, the app.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<add key="BuildNumber" value="123456789" />
</configuration>
Note: Set the powershell scripts at the same folder of the app.config file.
Hope this helps.
You can use the Replace Tokens extension and in the apconfig.exe file put this:
<add key="BuildNumber" value="__BuildNumber__" />
Configure the task to search variables with __ prefix and suffix:
Now the value will be replaced with the value of the BuildNumber variable you configured (equal to Build.BuildNumber).

The type initializer for 'DotNetOpenAuth.Logger' threw an exception

My aim is to call Google Admin SDK Directory updates from PowerShell. I started out with a working .NET app and converted it into a class library (which I tested - it works). I load that in the module manifest with
RequiredAssemblies = #('My.GoogleAdminSDK.Directory.dll')
My Get-GoogleSDKUser function New-Objects my class and calls GetUser on it. And I get:
Exception calling "GetUser" with "1" argument(s): "The type initializer for
'DotNetOpenAuth.Logger' threw an exception."
At C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\My.googleadminsdkdirectory.admin\My.GoogleA
dminSDKDirectory.Admin.psm1:56 char:9
+ $service.GetUser($googleUserName)
+ ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : TypeInitializationException
I've tried adding a config file for log4net which has produced an empty log file but that didn't help.
Note: in order to get this far, I had to add
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Net.Http.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="log4net" publicKeyToken="669e0ddf0bb1aa2a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.2.12.0" newVersion="1.2.12.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
to powershell_ise.exe.config to prevent the error:
"Could not load file or assembly 'System.Net.Http.Primitives,
Version=1.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or
one of its dependencies. The system cannot find the file specified."
which is far from ideal.
EDIT
The InnerException for the PowerShell-calling-my-DLL version was:
Could not load file or assembly 'log4net, Version=1.2.10.0,
Culture=neutral, PublicKeyToken=1b44e1d426115821' or one of its
dependencies. The system cannot find the file specified.
It took a bit of digging to find the innerException. I had a bit of a ferret around and found suggestions to use Fuslogvw, so I tried that. I closed and re-opened PowerShell, started up Fusion Log Viewer (it's the first time I've used it) and found three entries for log4net. The descriptions are:
log4net
log4net, Version=1.2.12.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a
log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821
When I open them up, the first two have 'The operation was successful.' as the second line of text. The third has 'The operation failed. Bind result: hr = 0x80070002. The system cannot find the file specified.'
When I dig into that log, I find:
LOG: Assembly download was successful. Attempting setup of file: C:\windows\system32\windowspowershell\v1.0\Modules\JLP.GoogleAdminSDKDirectory.Admin\log4net.dll
LOG: Entering run-from-source setup phase.
LOG: Assembly Name is: log4net, Version=1.2.12.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a
WRN: Comparing the assembly name resulted in the mismatch: Build Number
ERR: The assembly reference did not match the assembly definition found.
I tried running it from Visual Studio again. There were also three entries in fuslogvw and the third had the same error. But there's nothing in the VS output to indicate a problem.
It turns out that the two versions of log4net with different PublicKeyTokens have caused problems for others. I've got it working by adding a verison of log4netwith PublicKeyToken=1b44e1d426115821 to the GAC and adding another bindingredirect to the config file because the versions didn't match.
You can find the log4net versions here. You'll see references to oldkey and newkey versions. The oldkey one has PublicKeyToken=1b44e1d426115821 so I simply ran
gacutil /i "C:\Users\Me\Downloads\log4net\log4net-1.2.12-bin-oldkey\log4net-1.2.12\b
in\net\4.0\release\log4net.dll"
to stick it in the GAC and added:
<dependentAssembly>
<assemblyIdentity name="log4net" publicKeyToken="1b44e1d426115821" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.2.12.0" newVersion="1.2.12.0" />
</dependentAssembly>
to the assemblyBindings in the config file.

Modify a .Net Applications .exe.config file Settings Value via Powershell

I have a .Net console application which has an App.Config / MyApplicationConsole.exe.config file. This one contains settings set via the properties manager of VS, basically looking something like this:
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="My.Applications.Namespace.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<applicationSettings>
<My.Applications.Namespace.Properties.Settings>
<setting name="SettingsKeyABC" serializeAs="String">
<value>SomeOtherValue</value>
</setting>
<setting name="SettingsKeyXYZ" serializeAs="String">
<value>True</value>
</setting>
</Siemens.Med.CTE.PMP.Applications.JobExecutor.Properties.Settings>
</applicationSettings>
<system.diagnostics>
<trace>
<listeners>
<add name="Gibraltar" type="Gibraltar.Agent.LogListener, Gibraltar.Agent" />
</listeners>
</trace>
</system.diagnostics>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
</startup>
</configuration>
Now what I want/need to do is modify the ("True") value for the "SettingsKeyXYZ" setting, preferably via powershell (as my colleague set up). Does anyone know how to do this? All I found were sample for Web.Configs which seem a tad different than the ones created by VS.
First, The xml text is not valid. Where's the closing tag of line 10 tag (My.Applications.Namespace.Properties.Settings). I changed line 10 to match the closing tag.
Load the file (as xml), you must put the 'My.Applications.Namespace.Properties.Settings' tag in quotes otherwise powershell will try to parse each value between the dots as a tag), update the value to False and then save the file.
[xml]$xml = Get-Content c:\App.Config
$xml.configuration.applicationSettings.'My.Applications.Namespace.Properties.Settings'.setting.value='False'
$xml.Save('c:\App.Config')

How can I force IIS 7 to flush output?

In IIS 6, using Perl, I was able to send a stream of output to the client rather than buffering the entire thing and dumping it out at all once. This allowed such things as progress bars and such to be used.
How can I accomplish the same thing in IIS 7?
Under IIS 7, once you have created the Perl Script script mapping, you can add an attribute that will fix this.
You modify the %windir%\system32\inetsrv\config\applicationHost.control file and find the script mapping by name (in my case, Perl-Script). Then add the responseBufferLimit attribute into the XML, for example:
<add name="Perl-Script" path="*.pl" blah blah blah responseBufferLimit="0" />
This causes IIS to run as it did in IIS 6, with buffering off.
You can customize the web application's web.config to set responseBufferLimit="0" instead of changing global settings. Example web.config:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="Perl CGI for .pl (custom)" path="*.pl" verb="GET,HEAD,POST" modules="CgiModule" scriptProcessor="C:\Perl64\bin\perl.exe "%s" %s" resourceType="File" requireAccess="Script" responseBufferLimit="0" />
</handlers>
</system.webServer>
<system.web>
<identity impersonate="false" />
</system.web>
</configuration>
Place this file in the web root directory. It will override server settings for *.pl.
The ONLY thing that worked for my in IIS 7.5 (Windows 7) was the following command, run from CMD:
appcmd.exe set config /section:handlers "/[name='PHP_via_FastCGI'].ResponseBufferLimit:0"
NOTE: You must replace PHP_via_FastCGI with the name of your PHP handler in "Handler Mappings".