Cannot get ServiceStack.OrmLite.Sqlite64 example working - sqlite

I am running under .NET 4.5 with VS 2012 Desktop Express. Through NuGet I grabbed ServiceStack and ServiceStack.OrmLite.Sqlite64. I then used the very simple example located http://code.google.com/p/servicestack/wiki/OrmLite to write the following.
class Program {
static void Main(string[] args) {
OrmLiteConfig.DialectProvider = new SqliteOrmLiteDialectProvider();
using (IDbConnection db = #"C:\test.s3db".OpenDbConnection()) {
db.CreateTable<Example>(true);
db.Insert(new Example { Id = 1, Text = "An example" });
var items = db.Select<Example>();
items.ForEach(x => Console.WriteLine(x.Id + "\t" + x.Text));
}
}
}
public class Example {
public int Id { get; set; }
public string Text { get; set; }
}
The code above compiles however I get a run time exception that seems to indicate that I am using a System.Data.Sqlite version that differs from what ServiceStack.OrmLite.SqliteNET was compiled against. The version provided to me by NuGet was 1.0.81.0 while the runtime exception appears to be looking for version 1.0.65.0.
I am new to using NuGet so I may have done something wrong, however I have been unable to determine what it is that I have done incorrectly. Assistance would be appreciated.

I noticed that the NuGet package ServiceStack.OrmLite.Sqlite64 was updated today. After installing the newest package the example worked as intended. It appears to have been an incorrect version of System.Data.Sqlite being supplied by the package that was causing my issue.

I've had this exact same experience with ServiceStack and SQLite, which occurred when the SQLite version listed as a dependency for ServiceStack.OrmLite.Sqlite* (via packages.config) was no longer available on NuGet (since the SQLite folks seem to remove old versions when they add new ones). I've submitted past pull requests to ServiceStack to keep this updated, but was also able to solve it locally with an assembly binding redirect:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Data.SQLite"
publicKeyToken="db937bc2d44ff139"
culture="neutral" />
<bindingRedirect oldVersion="1.0.82.0" newVersion="1.0.84.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
The above, in an App.config file, let my unit test assembly redirect ServiceStack's runtime binding request for SQLite 1.0.82 (which it was expecting) to 1.0.84 (which was the version available on NuGet), and thus it ran without error even though 1.0.84 was the only version available on my system.

Related

Could not load file or assembly 'Microsoft.IdentityModel.Clients.ActiveDirectory, Version=3.19.8.16603. does not match the assembly reference

There are two projects in solution.One is API and other is for OrganizationServiceCall.
I have installed one nuget package called Microsoft.CrmSdk.XrmTooling.CoreAssembly it has installed default package Microsoft.IdentityModel.Clients.ActiveDirectory, Version=3.19.8.1660 with it.
But I have installed Microsoft.IdentityModel.Clients.ActiveDirectory, Version=2.22 in other project.While Call API I got this error :
{"Could not load file or assembly 'Microsoft.IdentityModel.Clients.ActiveDirectory, Version=3.19.8.16603"}.
How can i done work while same Solution have different version of nuget pacakge conflicts?
Some work arounds that you can try
If second project api has no issue with latest version ,Also try Upgrading it to Microsoft.IdentityModel.Clients.ActiveDirectory version 3.19.8
Or Update all NuGet packages to the latest if its ok.
Or one may need to edit your csproj manually to add that specific version in thart particular project.
Use a single assembly version with Binding Redirect in config file
i) NuGet won't handle the references in the program. It just
manages packages. We may have to force our project to use the
loaded assembly with binding redirect.
ii) This specifies which version of assembly to use instead of old
version. It is not necessarily requires later version be specified
in newVersion, earlier version can be provided as well in
newVersion. If there are different versions, try make them uniform
across projects. Issue should be solved.
Here oneproject is referred to ActiveDirectory versions > 3.0, other
project needs less version that that. Adding a binding redirect to
the app.config can help fix problem in some cases. But before that
please make sure that particular dlls are present in the
configuration file.
Note that the runtime section is the one to be added.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
...
<runtime>
....
<dependentAssembly>
<assemblyIdentity
name="Microsoft.IdentityModel.Clients.ActiveDirectory" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="3.0.0.0-3.19.8.16603" newVersion="3.19.8.16603" />
</dependentAssembly>
.....
</runtime>
</configuration>
And try to explicitly set Specific Version for whatever DLL giving you version issues(Microsoft.IdentityModel.Clients.ActiveDirectory) to False from Visual Studio.
Other way, you can try is to auto-generate binding redirects.
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
References:
azure-sdk-for-media-services :issues(github)
How to resolve “Could not load file or assembly | by Chirag
Rupani | Medium
Troubleshooting NuGet Package Restore in Visual Studio | Microsoft
Docs

Unable to trigger a Snapshot Debugger snapshot from code

This is in a Visual Studio Solution with an Asp.Net MVC app targeting .NET Framework 4.6 as the UI project, and several other C# class library projects.
We Application Insights Nuget packages, including the Snapshot Collector package, to all the projects in the solution we wish to trace. All Nuget packages use the latest version.
To trigger a snapshot from code, I throw an exception like so:
try
{
throw new Exception("This is an AI test exception");
}
catch (Exception ex)
{
var ai = new TelemetryClient();
var props = new Dictionary<string, string> { { "Property1", "A test property value" } };
ai.TrackException(ex, props);
}
The MVC Project's ApplicationInsights.config is configured as follows
<TelemetryProcessors>
<Add Type="Microsoft.ApplicationInsights.SnapshotCollector.SnapshotCollectorTelemetryProcessor, Microsoft.ApplicationInsights.SnapshotCollector">
<IsEnabledInDeveloperMode>false</IsEnabledInDeveloperMode>
<HandleUntrackedExceptions>true</HandleUntrackedExceptions>
<ThresholdForSnapshotting>1</ThresholdForSnapshotting>
<ProblemCounterResetInterval>2.00:00:00</ProblemCounterResetInterval> <!--2 days-->
</Add>
</TelemetryProcessors>
I published the app to Azure and invoked the exception several times by browsing the App.
This setup results in the exception being recorded to Application Insights, but without the snapshot. Snapshots work fine for unhandled exceptions.
Shouldn't it take a snapshot after the exception occurs a second time?
Please try the following steps:
1) change your IsEnabledInDeveloperMode to true in ApplicationInsights.config file.
true means that it will enable Snapshot Debugging.
<IsEnabledInDeveloperMode>true</IsEnabledInDeveloperMode>
2) add this before your code to check if there is an error loading the assembly.
var _ = typeof(SnapshotCollectorTelemetryProcessor);
3) add bindredirect in your web.config file:
<dependentAssembly>
<assemblyIdentity name="Microsoft.ApplicationInsights" publicKeyToken="xxxxx" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-2.15.0.44797" newVersion="2.15.0.44797"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.ApplicationInsights.SnapshotCollector" publicKeyToken="xxxx" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.3.7.0" newVersion="1.3.7.0" />
</dependentAssembly>
Usually, the activities will be in the %temp% folder.
If these do not work,
a) disable any vs installed extensions under Extensions-->Manage Extensions
b) reset vs settings under Tools-->Import and Export Settings--> Reset all settings
c) delete .vs hidden folder, bin and obj folder.

Microsoft.SqlServer.Types with Service Fabric

Problem is pretty simple. I moved a WebApps project to Service Fabric which had the Microsoft.SqlServer.Types nuget package installed. Now, when trying to access database I'm getting the following error because I'm using spatial types.
"Spatial types and functions are not available for this provider because the assembly 'Microsoft.SqlServer.Types' version 10 or higher could not be found. "
I've tried adding the following line of code to the class which the FabricRuntime creates an instance of, but that was of no use.
SqlServerTypes.Utilities.LoadNativeAssemblies(AppDomain.CurrentDomain.BaseDirectory);
Your help would be appreciated, please do let me know if you need more info from me.
You do need the line of code, but for asp.net application it should be slightly different:
For Asp.net websites, Default.aspx.cs:
public partial class _Default : System.Web.UI.Page
{
static bool _isSqlTypesLoaded = false;
public _Default()
{
if (!_isSqlTypesLoaded)
{
SqlServerTypes.Utilities.LoadNativeAssemblies(Server.MapPath("~"));
_isSqlTypesLoaded = true;
}
}
}
For web applications, in Global.asax.cs:
SqlServerTypes.Utilities.LoadNativeAssemblies(Server.MapPath("~/bin"));
Also you need to create the following binding redirect in web.config:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.SqlServer.Types" publicKeyToken="89845dcd8080cc91" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-14.0.0.0" newVersion="14.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
Here is the only discussion on the topic which helped me.
Update: Here is a blog post that provides a well described solution in 3 steps. Although, the third step didn't work for me and I had to create the binding as described above.

Could not load System.Web.Cors in Owin Startup.cs

I have a .Net 4.5.1 application using Web API 2 and running in my local Azure Emulator. I have some OWIN components installed and in my Startup.cs file within the Configuration(IAppBuilder app) function I have the following code block and the last line causes an exception:
HttpConfiguration httpConfiguration = new HttpConfiguration();
WebApiConfig.Register(httpConfiguration);
app.UseWebApi(httpConfiguration);
app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
This line is causing an exception "Could not load file or assembly 'System.Web.Cors, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies."
I'm having trouble figuring out why NuGet didnt' install this if it is a dependency. Additionally I'm not able to find a corresponding dll already installed to add a reference myself, nor the correct NuGet package to install to provide said dll.
Has anyone experienced a similar issue? If so, perhaps you could point me in the right direction.
This is surely coming cause of your DLL version is different OR DLL is missing on that environment.
Few steps you require to check:
Cors DLL should be there in your BIN directory [On Azure]
If it's there then Version of DLL deployed on server and your local both should be same. [You can check in properties]
If your version of Cors DLL higher on Azure server, compare to local one then you can
<dependentAssembly>
<assemblyIdentity name="System.Web.Cors" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-5.0.0.0" newVersion="5.0.0.1" />
</dependentAssembly>
Your new version could be your DLL version which are available into the BIN directory.
Have you tried Microsoft.Asp.Net.WebApi.Cors at nuget?
https://www.nuget.org/packages/Microsoft.AspNet.WebApi.Cors/5.2.2
It's not a dependency for the Cors package because it's for webapi and the only microsoft.owin.cors dependency is on the base microsoft.asp.net.cors (other than the owin packages).

Assembly Reference Catch-22

I'm trying to integrate MangoChat into an existing .Net project. Mango requires the use of Newtonsoft.Json version 3.5.0.0, however my current version of this assembly is 6.x.
Logically, I thought to uninstall the current version but it has so many dependencies that it tears apart the project. I can't install version 3.5.0.0 beside 6.x because I can't add a second assembly to the .bin folder with the same name.
How could I solve this issue?
If version 6.x is compatible with version 3.5.0.0, you can add a binding redirect to new version. You should add it to your configuration file:
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="[enter token here]" culture="neutral" />
<bindingRedirect oldVersion="3.5.0.0-6.X" newVersion="6.X"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Replace 6.X with your actual version.
Another option is to add assembly to different folder and use AssemblyResolve event on AppDomain to find it. You can use such code:
//Load assembly from alternative location
Assembly newtonsoftAssembly = Assembly.LoadFrom(#"C:\PathToYourAssembly.dll");
//Handle AssemblyResolve event
AppDomain.CurrentDomain.AssemblyResolve += (sender, args) =>
{
//Check if your assembly was requested
if (args.Name.Contains("Newtonsoft.Json"))
{
return newtonsoftAssembly;
}
return null;
};
You should run this code once, e.g. during application startup.

Resources