System.MissingMethodException with Miniprofiler.Windows - c#

Recently in my WinForm project, I installed MiniProfiler.Windows and write following decorator for my QueryHandlers(I'm using CQRS):
public class MiniProfilerQueryHandlerDecorator<TQuery,TResult>:IQueryHandler<TQuery,TResult> where TQuery : IQueryParameter<TResult>
{
private readonly IQueryHandler<TQuery, TResult> _decoratee;
public MiniProfilerQueryHandlerDecorator(IQueryHandler<TQuery, TResult> decoratee)
{
_decoratee = decoratee;
}
public TResult Handle(TQuery request)
{
TResult result;
using (StackExchange.Profiling.MiniProfiler.Current.Step("Call QueryHandler"))
{
result =_decoratee.Handle(request); //call some Linq to entity queries
}
var friendlyString = ConsoleProfiling.StopAndGetConsoleFriendlyOutputStringWithSqlTimings();
Debug.WriteLine(friendlyString);
return result;
}
}
I get following error at var friendlyString=ConsoleProfiling.StopAndGetConsoleFriendlyOutputStringWithSqlTimings()
line.
An unhandled exception of type 'System.MissingMethodException' occurred in IASCo.Application.Core.dll
Additional information: Method not found: 'Boolean StackExchange.Profiling.MiniProfiler.get_HasSqlTimings()'.
Does anyone know where is the problem?

MissingMethodException = an attempt is made to dynamically access a deleted or renamed method of an assembly that is not referenced by its strong name (msdn).
Or as this answer puts it:
This is a problem which can occur when there is an old version of a DLL still lingering somewhere around
I notice that the MiniProfiler.Windows library is using a very old (over 2 years) version of MiniProfiler. That version of the code did indeed have a MiniProfiler.HasSqlTimings property. However, the current version (3.0.11) no longer has this property.
I am guessing that you are using the code from the MiniProfiler.Windows library that you linked above, but instead of using the v2 MiniProfiler dll that they have saved in /packages, you are using a v3 MiniProfiler dll (maybe downloaded from nuget). This would explain the exception that you are getting.
If this is indeed the case, then you can solve this by either downloading the version 2.0.2 nuget (Install-Package MiniProfiler -Version 2.0.2) or by upgrading the code in ConsoleProfiling to be compatible with MiniProfiler v3.

Related

System.MissingMethodException after adding a project reference (without using the reference)

I have encountered a strange error that is unexplainable to me.
I have a .NET 6 class library project (A) that has the function:
public async Task ImportDeliveries()
{
try
{
var csvFileProcessor = new CsvFileProcessor();
await csvFileProcessor.ProcessAllAsync(_DeliveryImporter.ImportAsync).ConfigureAwait(true);
}
catch (Exception ex)
{
_TelemetryClient.TrackException(ex);
}
}
It works fine. However, as soon as I add the project reference of another .NET 6 class library (B) to the project, without changing anything else, the function
await csvFileProcessor.ProcessAllAsync(_DeliveryImporter.ImportAsync).ConfigureAwait(true);
fails and throws the following exception:
System.MissingMethodException: 'Method not found: 'System.Threading.Tasks.Task BlobStorageHelper.BlobStorageFolder.MoveAsync(Microsoft.Azure.Storage.Blob.CloudBlockBlob, BlobStorageHelper.BlobStorageFolder)'.'
Can this be caused because (B) contains certain nuget packages?
This behavior is very counterintuitive to me, and I'm not sure where to start looking.
This is probably caused by:
Your project, A, referencing a class library C, in which CsvFileProcessor and BlobStorageHelper.BlobStorageFolder are defined (the latter could also be in a transitive dependency, D).
Project B also references class library C (and/or D), but a different version.
Someone modified, added or removed System.Threading.Tasks.Task BlobStorageHelper.BlobStorageFolder.MoveAsync(Microsoft.Azure.Storage.Blob.CloudBlockBlob, BlobStorageHelper.BlobStorageFolder) in some version of C or D.
You're not properly implementing Semantic Versioning within C or D, so MSBuild is restoring a version of C or D that doesn't contain the required method.
Hence the error.
Takeaway: changing a signature or return type is breaking the ABI (application binary interface), requiring a major version update.
To fix this, you could revert the signature or return type change, and add an overload instead.

Cannot find the interop type that matches the embedded interop type

I have created a Visual Studios Extension using the AsyncPackage Class that looks something line this:
public sealed class Tools : AsyncPackage, IDisposable
{
internal const string PrjCATIDCSharpFileBrowseObject = "{8D58E6AF-ED4E-48B0-8C7B-C74EF0735451}";
private readonly List<IDisposable> _extenderProviders = new List<IDisposable>();
protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
{
await base.InitializeAsync(cancellationToken, progress);
_extenderProviders.Add(new BrowseProvider(this, PrjCATIDCSharpFileBrowseObject));
}
}
I am getting 4 Errors with the code CS1748 on BrowseProvider. What I do not understand is that the Errors it gives are for Types that BrowseProvider does not use. One of the errors is for IAsyncServiceProvider, but BrowseProvider uses IServiceProvider. AsyncPackage does inherit IServiceProvider, but I changed BrowseProvider to use IAsyncServiceProvider however this did not solve the problem. Creating a new BrowseProvider object anywhere in Tools shows this CS1748 error.
I have looked around and found that this error is caused by a reference DLL. I set Microsoft.VisualStudio.Shell.Framework to have its Embed Interop Type Property set to False, but the errors still persists.
All of my code shows no errors except when I try and create a BrowseProvider object from with in the Tools Package. I do not understand why creating a new object anywhere in the Tools Class shows errors for type that are no being used.
Please make sure that you reference the correct dll or the nuget package in your project. Usually you get this error, when there is no reference.

FluentAutomation and Selenium 2.33.0.0

I'm getting the following exception when I try to run a test with FluentAutomation
A first chance exception of type 'System.IO.FileLoadException'
occurred in FluentAutomation.Core.dll
Could not load file or assembly 'WebDriver, Version=2.25.1.0,
Culture=neutral, PublicKeyToken=1c2bd1631853048f' or one of its
dependencies. The located assembly's manifest definition does not
match the assembly reference. (Exception from HRESULT: 0x80131040)
Here's the stack trace
at FluentAutomation.SeleniumWebDriver.b__0(TinyIoCContainer
container)
at FluentAutomation.FluentTest.get_I()
I've got the latest version of selenium from nuget but seems like there's some kind of hardcoded required version from within the fluentautomation dll
FluentAutomation genuinely looks amazing so would be great to be able to use it in my project.
#stirno please help!
FluentAutomation and selenium 2.32.1.0 looks decidedly similar to my problem but I've downloaded the latest ChromeDriver from Nuget and I'm copying it into my bin directory as prescribed.
I've also tried downloading the latest from here and copying that in. No joy
I'm also using spec flow so here's my setup in case it helps...
[Binding]
public class WebScenario : FluentAutomation.FluentTest
{
private readonly IObjectContainer objectContainer;
public WebScenario(IObjectContainer objectContainer)
{
this.objectContainer = objectContainer;
FluentAutomation.Settings.ScreenshotPath = #"C:\Work\Temp";
FluentAutomation.Settings.ScreenshotOnFailedExpect = false;
FluentAutomation.Settings.ScreenshotOnFailedAction = false;
FluentAutomation.Settings.DefaultWaitTimeout = TimeSpan.FromSeconds(1);
FluentAutomation.Settings.DefaultWaitUntilTimeout = TimeSpan.FromSeconds(30);
FluentAutomation.Settings.MinimizeAllWindowsOnTestStart = true;
}
[BeforeScenario("Web")]
public void BeforeScenario()
{
FluentAutomation.SeleniumWebDriver.Bootstrap(FluentAutomation.SeleniumWebDriver.Browser.Firefox);
objectContainer.RegisterInstanceAs<INativeActionSyntaxProvider>(I);
}
}
The exception happens when I is accessed for the first time injecting it into the PageNavigator object
If you're interested you can download a really simple source example from github
So I got this working... I downloaded the FluentAutomation source from GitHub and built the latest dlls and dropped them in. Looks like this problem should be dealt with in the next release :D
Getting the latest source from the github repo and dropping in the built dlls worked for me

Unable to compile code output because of some reference assembly goofups

My issue goes like this:
There is a project called myframework. It has some extension methods defined in it as follows:
namespace myframework
{
public static class Helpers
{
public static bool ContainsAll(this string obj, string[])
{
return true;
}
}
}
It also has some other stuff like interfaces, etc, etc.
There is a second class I generate via System.CodeDom classes. The generated output is somewhat like this:
using myframework;
public class A: IMyFrameworkInterface
{
public void foo()
{
string s ="HELLO";
if(s.ContainsAll(some_arr))
return;
}
//More methods defined...
}
The compiler options I pass which is created prior to the actual compile call references the correct assemblies
var cp = new CompilerParameters();
cp.ReferencedAssemblies.Add("System.dll");
cp.ReferencedAssemblies.Add("myframework.dll");
The code compilation modules are written in a different project. The particular class responsible for this also nicely gives us access to a list of CompilerError object via which we can learn the result of compilation.
Issue1: When I tried this in an asp.net project the compiler threw error saying it could not find metadata file myframework.dll (despite it being referenced in the project).
Issue2: When I tried it with a windows forms project. It gave a different error. This time saying that string does not contain definition for ContainsAll()
How to solve these two specific problems?
Found out the answer to this after a bit digging up. I was using .net framework 3.5. The codedom compiler apis targets v2.0 of the framework by default. Hence, you have to manually specify the correct framework:
var cp = new CompilerParameters(
new Dictionary<string,string>() { {"CompilerVersion", "v3.5"} });
For the compilation to work within an asp.net environment you'd have to actually point the references to the correct location. Hence you'd have to do something like follows:
cp.ReferencedAssemblies.Add(
HttpContext.Current.Server.MapPath(
"bin\\myframework.dll"));
My references:
http://blogs.msdn.com/b/lukeh/archive/2007/07/11/c-3-0-and-codedom.aspx
.Net 3.5 CodeDom Compiler generating odd errors
And comments in the question's post. :)

"Specified cast is not valid" only on release build from MS build

I am getting a "Specified cast is not valid" valid when doing only a release build from MSBuild 4.0. I tested this out in using a release build from Visual Studio 2012 and didn't get this issue. I also tested this out using a debug build from MSBuild 4.0 and didn't get this issue.
Exception:
Code
public abstract class CachedSessionBase : ISessionObject
{
protected Dictionary<MethodBase, Object> _getAndSetCache = new Dictionary<MethodBase, object>();
protected TResult SetAndGet<TResult>(ObjectFactory factory, Func<TResult> func)
{
StackTrace stackTrace = new StackTrace();
var methodBase = stackTrace.GetFrame(1).GetMethod();
if (!_getAndSetCache.ContainsKey(methodBase))
{
_getAndSetCache[methodBase] = func.Invoke();
}
return (TResult)_getAndSetCache[methodBase];
}
The error is being thrown on this line
return (TResult)_getAndSetCache[methodBase];
It is likely that the call stack is different than what you are expecting it to be. Your method may be getting inlined, then GetFrame(1) is retrieving the caller's caller. When the value is retrieved from the dictionary, it is of a different type because it is for a different method.
You could try adding the attribute [MethodImpl(MethodImplOptions.NoInlining] to SetAndGet to prevent the inlining optimization for the method.
I had the same problem when running nuget pack which invoked
MSBuild auto-detection: using msbuild version '15.0'...
but the problem was solved by running dotnet pack which invoked
Microsoft (R) Build Engine version 15.3.409.57025 for .NET Core

Categories

Resources